blob: dde8a974c9847345598c97467cad13cbb8047aa2 [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
John McCall83024632010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor840bd6c2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCallaab3e412010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000024#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000025#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000026#include "clang/AST/ExprCXX.h"
27#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000028#include "clang/AST/Stmt.h"
29#include "clang/AST/StmtCXX.h"
30#include "clang/AST/StmtObjC.h"
John McCall8b0666c2010-08-20 18:27:03 +000031#include "clang/Sema/Ownership.h"
32#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000033#include "clang/Lex/Preprocessor.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000034#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000035#include "llvm/Support/ErrorHandling.h"
Douglas Gregor451d1b12010-12-02 00:05:49 +000036#include "TypeLocBuilder.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000040using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000041
Douglas Gregord6ff3322009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump11289f42009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump11289f42009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
101
102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
106
107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
111
Douglas Gregord6ff3322009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000114
Mike Stump11289f42009-09-09 15:08:12 +0000115public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000116 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000117 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000118
Douglas Gregord6ff3322009-08-04 16:50:30 +0000119 /// \brief Retrieves a reference to the derived class.
120 Derived &getDerived() { return static_cast<Derived&>(*this); }
121
122 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000123 const Derived &getDerived() const {
124 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000125 }
126
John McCalldadc5752010-08-24 06:29:42 +0000127 static inline ExprResult Owned(Expr *E) { return E; }
128 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000129
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 /// \brief Retrieves a reference to the semantic analysis object used for
131 /// this tree transform.
132 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000133
Douglas Gregord6ff3322009-08-04 16:50:30 +0000134 /// \brief Whether the transformation should always rebuild AST nodes, even
135 /// if none of the children have changed.
136 ///
137 /// Subclasses may override this function to specify when the transformation
138 /// should rebuild all AST nodes.
139 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000140
Douglas Gregord6ff3322009-08-04 16:50:30 +0000141 /// \brief Returns the location of the entity being transformed, if that
142 /// information was not available elsewhere in the AST.
143 ///
Mike Stump11289f42009-09-09 15:08:12 +0000144 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000145 /// provide an alternative implementation that provides better location
146 /// information.
147 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000148
Douglas Gregord6ff3322009-08-04 16:50:30 +0000149 /// \brief Returns the name of the entity being transformed, if that
150 /// information was not available elsewhere in the AST.
151 ///
152 /// By default, returns an empty name. Subclasses can provide an alternative
153 /// implementation with a more precise name.
154 DeclarationName getBaseEntity() { return DeclarationName(); }
155
Douglas Gregora16548e2009-08-11 05:31:07 +0000156 /// \brief Sets the "base" location and entity when that
157 /// information is known based on another transformation.
158 ///
159 /// By default, the source location and entity are ignored. Subclasses can
160 /// override this function to provide a customized implementation.
161 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000162
Douglas Gregora16548e2009-08-11 05:31:07 +0000163 /// \brief RAII object that temporarily sets the base location and entity
164 /// used for reporting diagnostics in types.
165 class TemporaryBase {
166 TreeTransform &Self;
167 SourceLocation OldLocation;
168 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000169
Douglas Gregora16548e2009-08-11 05:31:07 +0000170 public:
171 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000172 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000173 OldLocation = Self.getDerived().getBaseLocation();
174 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregora518d5b2011-01-25 17:51:48 +0000175
176 if (Location.isValid())
177 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000178 }
Mike Stump11289f42009-09-09 15:08:12 +0000179
Douglas Gregora16548e2009-08-11 05:31:07 +0000180 ~TemporaryBase() {
181 Self.getDerived().setBase(OldLocation, OldEntity);
182 }
183 };
Mike Stump11289f42009-09-09 15:08:12 +0000184
185 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000186 /// transformed.
187 ///
188 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000189 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000190 /// not change. For example, template instantiation need not traverse
191 /// non-dependent types.
192 bool AlreadyTransformed(QualType T) {
193 return T.isNull();
194 }
195
Douglas Gregord196a582009-12-14 19:27:10 +0000196 /// \brief Determine whether the given call argument should be dropped, e.g.,
197 /// because it is a default argument.
198 ///
199 /// Subclasses can provide an alternative implementation of this routine to
200 /// determine which kinds of call arguments get dropped. By default,
201 /// CXXDefaultArgument nodes are dropped (prior to transformation).
202 bool DropCallArgument(Expr *E) {
203 return E->isDefaultArgument();
204 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000205
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000206 /// \brief Determine whether we should expand a pack expansion with the
207 /// given set of parameter packs into separate arguments by repeatedly
208 /// transforming the pattern.
209 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000210 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000211 /// Subclasses can override this routine to provide different behavior.
212 ///
213 /// \param EllipsisLoc The location of the ellipsis that identifies the
214 /// pack expansion.
215 ///
216 /// \param PatternRange The source range that covers the entire pattern of
217 /// the pack expansion.
218 ///
219 /// \param Unexpanded The set of unexpanded parameter packs within the
220 /// pattern.
221 ///
222 /// \param NumUnexpanded The number of unexpanded parameter packs in
223 /// \p Unexpanded.
224 ///
225 /// \param ShouldExpand Will be set to \c true if the transformer should
226 /// expand the corresponding pack expansions into separate arguments. When
227 /// set, \c NumExpansions must also be set.
228 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000229 /// \param RetainExpansion Whether the caller should add an unexpanded
230 /// pack expansion after all of the expanded arguments. This is used
231 /// when extending explicitly-specified template argument packs per
232 /// C++0x [temp.arg.explicit]p9.
233 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000234 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000235 /// the expanded form of the corresponding pack expansion. This is both an
236 /// input and an output parameter, which can be set by the caller if the
237 /// number of expansions is known a priori (e.g., due to a prior substitution)
238 /// and will be set by the callee when the number of expansions is known.
239 /// The callee must set this value when \c ShouldExpand is \c true; it may
240 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000241 ///
242 /// \returns true if an error occurred (e.g., because the parameter packs
243 /// are to be instantiated with arguments of different lengths), false
244 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
245 /// must be set.
246 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
247 SourceRange PatternRange,
David Blaikieb9c168a2011-09-22 02:34:54 +0000248 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000249 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000250 bool &RetainExpansion,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000251 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000252 ShouldExpand = false;
253 return false;
254 }
255
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000256 /// \brief "Forget" about the partially-substituted pack template argument,
257 /// when performing an instantiation that must preserve the parameter pack
258 /// use.
259 ///
260 /// This routine is meant to be overridden by the template instantiator.
261 TemplateArgument ForgetPartiallySubstitutedPack() {
262 return TemplateArgument();
263 }
264
265 /// \brief "Remember" the partially-substituted pack template argument
266 /// after performing an instantiation that must preserve the parameter pack
267 /// use.
268 ///
269 /// This routine is meant to be overridden by the template instantiator.
270 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
271
Douglas Gregorf3010112011-01-07 16:43:16 +0000272 /// \brief Note to the derived class when a function parameter pack is
273 /// being expanded.
274 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
275
Douglas Gregord6ff3322009-08-04 16:50:30 +0000276 /// \brief Transforms the given type into another type.
277 ///
John McCall550e0c22009-10-21 00:40:46 +0000278 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000279 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000280 /// function. This is expensive, but we don't mind, because
281 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000282 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 ///
284 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000285 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000286
John McCall550e0c22009-10-21 00:40:46 +0000287 /// \brief Transforms the given type-with-location into a new
288 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
John McCall550e0c22009-10-21 00:40:46 +0000290 /// By default, this routine transforms a type by delegating to the
291 /// appropriate TransformXXXType to build a new type. Subclasses
292 /// may override this function (to take over all type
293 /// transformations) or some set of the TransformXXXType functions
294 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000295 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000296
297 /// \brief Transform the given type-with-location into a new
298 /// type, collecting location information in the given builder
299 /// as necessary.
300 ///
John McCall31f82722010-11-12 08:19:04 +0000301 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000302
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000303 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000304 ///
Mike Stump11289f42009-09-09 15:08:12 +0000305 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000306 /// appropriate TransformXXXStmt function to transform a specific kind of
307 /// statement or the TransformExpr() function to transform an expression.
308 /// Subclasses may override this function to transform statements using some
309 /// other mechanism.
310 ///
311 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000312 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000313
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000314 /// \brief Transform the given expression.
315 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000316 /// By default, this routine transforms an expression by delegating to the
317 /// appropriate TransformXXXExpr function to build a new expression.
318 /// Subclasses may override this function to transform expressions using some
319 /// other mechanism.
320 ///
321 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000322 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000323
Douglas Gregora3efea12011-01-03 19:04:46 +0000324 /// \brief Transform the given list of expressions.
325 ///
326 /// This routine transforms a list of expressions by invoking
327 /// \c TransformExpr() for each subexpression. However, it also provides
328 /// support for variadic templates by expanding any pack expansions (if the
329 /// derived class permits such expansion) along the way. When pack expansions
330 /// are present, the number of outputs may not equal the number of inputs.
331 ///
332 /// \param Inputs The set of expressions to be transformed.
333 ///
334 /// \param NumInputs The number of expressions in \c Inputs.
335 ///
336 /// \param IsCall If \c true, then this transform is being performed on
337 /// function-call arguments, and any arguments that should be dropped, will
338 /// be.
339 ///
340 /// \param Outputs The transformed input expressions will be added to this
341 /// vector.
342 ///
343 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
344 /// due to transformation.
345 ///
346 /// \returns true if an error occurred, false otherwise.
347 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000348 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +0000349 bool *ArgChanged = 0);
350
Douglas Gregord6ff3322009-08-04 16:50:30 +0000351 /// \brief Transform the given declaration, which is referenced from a type
352 /// or expression.
353 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000354 /// By default, acts as the identity function on declarations. Subclasses
355 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000356 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000357
358 /// \brief Transform the definition of the given declaration.
359 ///
Mike Stump11289f42009-09-09 15:08:12 +0000360 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000361 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000362 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
363 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000364 }
Mike Stump11289f42009-09-09 15:08:12 +0000365
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000366 /// \brief Transform the given declaration, which was the first part of a
367 /// nested-name-specifier in a member access expression.
368 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000369 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000370 /// identifier in a nested-name-specifier of a member access expression, e.g.,
371 /// the \c T in \c x->T::member
372 ///
373 /// By default, invokes TransformDecl() to transform the declaration.
374 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000375 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
376 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000377 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000378
Douglas Gregor14454802011-02-25 02:25:35 +0000379 /// \brief Transform the given nested-name-specifier with source-location
380 /// information.
381 ///
382 /// By default, transforms all of the types and declarations within the
383 /// nested-name-specifier. Subclasses may override this function to provide
384 /// alternate behavior.
385 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
386 NestedNameSpecifierLoc NNS,
387 QualType ObjectType = QualType(),
388 NamedDecl *FirstQualifierInScope = 0);
389
Douglas Gregorf816bd72009-09-03 22:13:48 +0000390 /// \brief Transform the given declaration name.
391 ///
392 /// By default, transforms the types of conversion function, constructor,
393 /// and destructor names and then (if needed) rebuilds the declaration name.
394 /// Identifiers and selectors are returned unmodified. Sublcasses may
395 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000396 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000397 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000398
Douglas Gregord6ff3322009-08-04 16:50:30 +0000399 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000400 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000401 /// \param SS The nested-name-specifier that qualifies the template
402 /// name. This nested-name-specifier must already have been transformed.
403 ///
404 /// \param Name The template name to transform.
405 ///
406 /// \param NameLoc The source location of the template name.
407 ///
408 /// \param ObjectType If we're translating a template name within a member
409 /// access expression, this is the type of the object whose member template
410 /// is being referenced.
411 ///
412 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
413 /// also refers to a name within the current (lexical) scope, this is the
414 /// declaration it refers to.
415 ///
416 /// By default, transforms the template name by transforming the declarations
417 /// and nested-name-specifiers that occur within the template name.
418 /// Subclasses may override this function to provide alternate behavior.
419 TemplateName TransformTemplateName(CXXScopeSpec &SS,
420 TemplateName Name,
421 SourceLocation NameLoc,
422 QualType ObjectType = QualType(),
423 NamedDecl *FirstQualifierInScope = 0);
424
Douglas Gregord6ff3322009-08-04 16:50:30 +0000425 /// \brief Transform the given template argument.
426 ///
Mike Stump11289f42009-09-09 15:08:12 +0000427 /// By default, this operation transforms the type, expression, or
428 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000429 /// new template argument from the transformed result. Subclasses may
430 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000431 ///
432 /// Returns true if there was an error.
433 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
434 TemplateArgumentLoc &Output);
435
Douglas Gregor62e06f22010-12-20 17:31:10 +0000436 /// \brief Transform the given set of template arguments.
437 ///
438 /// By default, this operation transforms all of the template arguments
439 /// in the input set using \c TransformTemplateArgument(), and appends
440 /// the transformed arguments to the output list.
441 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000442 /// Note that this overload of \c TransformTemplateArguments() is merely
443 /// a convenience function. Subclasses that wish to override this behavior
444 /// should override the iterator-based member template version.
445 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000446 /// \param Inputs The set of template arguments to be transformed.
447 ///
448 /// \param NumInputs The number of template arguments in \p Inputs.
449 ///
450 /// \param Outputs The set of transformed template arguments output by this
451 /// routine.
452 ///
453 /// Returns true if an error occurred.
454 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
455 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000456 TemplateArgumentListInfo &Outputs) {
457 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
458 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000459
460 /// \brief Transform the given set of template arguments.
461 ///
462 /// By default, this operation transforms all of the template arguments
463 /// in the input set using \c TransformTemplateArgument(), and appends
464 /// the transformed arguments to the output list.
465 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000466 /// \param First An iterator to the first template argument.
467 ///
468 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000469 ///
470 /// \param Outputs The set of transformed template arguments output by this
471 /// routine.
472 ///
473 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000474 template<typename InputIterator>
475 bool TransformTemplateArguments(InputIterator First,
476 InputIterator Last,
477 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000478
John McCall0ad16662009-10-29 08:12:44 +0000479 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
480 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
481 TemplateArgumentLoc &ArgLoc);
482
John McCallbcd03502009-12-07 02:54:59 +0000483 /// \brief Fakes up a TypeSourceInfo for a type.
484 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
485 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000486 getDerived().getBaseLocation());
487 }
Mike Stump11289f42009-09-09 15:08:12 +0000488
John McCall550e0c22009-10-21 00:40:46 +0000489#define ABSTRACT_TYPELOC(CLASS, PARENT)
490#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000491 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000492#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000493
John Wiegley1c0675e2011-04-28 01:08:34 +0000494 StmtResult
495 TransformSEHHandler(Stmt *Handler);
496
John McCall31f82722010-11-12 08:19:04 +0000497 QualType
498 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
499 TemplateSpecializationTypeLoc TL,
500 TemplateName Template);
501
502 QualType
503 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
504 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000505 TemplateName Template,
506 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000507
508 QualType
509 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000510 DependentTemplateSpecializationTypeLoc TL,
511 NestedNameSpecifierLoc QualifierLoc);
512
John McCall58f10c32010-03-11 09:03:00 +0000513 /// \brief Transforms the parameters of a function type into the
514 /// given vectors.
515 ///
516 /// The result vectors should be kept in sync; null entries in the
517 /// variables vector are acceptable.
518 ///
519 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000520 bool TransformFunctionTypeParams(SourceLocation Loc,
521 ParmVarDecl **Params, unsigned NumParams,
522 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000523 SmallVectorImpl<QualType> &PTypes,
524 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000525
526 /// \brief Transforms a single function-type parameter. Return null
527 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000528 ///
529 /// \param indexAdjustment - A number to add to the parameter's
530 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000531 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000532 int indexAdjustment,
Douglas Gregor715e4612011-01-14 22:40:04 +0000533 llvm::Optional<unsigned> NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +0000534
John McCall31f82722010-11-12 08:19:04 +0000535 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000536
John McCalldadc5752010-08-24 06:29:42 +0000537 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
538 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000539
Douglas Gregorebe10102009-08-20 07:17:43 +0000540#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000541 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000542#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000543 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000544#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000545#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000546
Douglas Gregord6ff3322009-08-04 16:50:30 +0000547 /// \brief Build a new pointer type given its pointee type.
548 ///
549 /// By default, performs semantic analysis when building the pointer type.
550 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000551 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000552
553 /// \brief Build a new block pointer type given its pointee type.
554 ///
Mike Stump11289f42009-09-09 15:08:12 +0000555 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000556 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000557 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000558
John McCall70dd5f62009-10-30 00:06:24 +0000559 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000560 ///
John McCall70dd5f62009-10-30 00:06:24 +0000561 /// By default, performs semantic analysis when building the
562 /// reference type. Subclasses may override this routine to provide
563 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000564 ///
John McCall70dd5f62009-10-30 00:06:24 +0000565 /// \param LValue whether the type was written with an lvalue sigil
566 /// or an rvalue sigil.
567 QualType RebuildReferenceType(QualType ReferentType,
568 bool LValue,
569 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000570
Douglas Gregord6ff3322009-08-04 16:50:30 +0000571 /// \brief Build a new member pointer type given the pointee type and the
572 /// class type it refers into.
573 ///
574 /// By default, performs semantic analysis when building the member pointer
575 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000576 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
577 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000578
Douglas Gregord6ff3322009-08-04 16:50:30 +0000579 /// \brief Build a new array type given the element type, size
580 /// modifier, size of the array (if known), size expression, and index type
581 /// qualifiers.
582 ///
583 /// By default, performs semantic analysis when building the array type.
584 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000585 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000586 QualType RebuildArrayType(QualType ElementType,
587 ArrayType::ArraySizeModifier SizeMod,
588 const llvm::APInt *Size,
589 Expr *SizeExpr,
590 unsigned IndexTypeQuals,
591 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000592
Douglas Gregord6ff3322009-08-04 16:50:30 +0000593 /// \brief Build a new constant array type given the element type, size
594 /// modifier, (known) size of the array, and index type qualifiers.
595 ///
596 /// By default, performs semantic analysis when building the array type.
597 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000598 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000599 ArrayType::ArraySizeModifier SizeMod,
600 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000601 unsigned IndexTypeQuals,
602 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000603
Douglas Gregord6ff3322009-08-04 16:50:30 +0000604 /// \brief Build a new incomplete array type given the element type, size
605 /// modifier, and index type qualifiers.
606 ///
607 /// By default, performs semantic analysis when building the array type.
608 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000609 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000610 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000611 unsigned IndexTypeQuals,
612 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000613
Mike Stump11289f42009-09-09 15:08:12 +0000614 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000615 /// size modifier, size expression, and index type qualifiers.
616 ///
617 /// By default, performs semantic analysis when building the array type.
618 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000619 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000620 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000621 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000622 unsigned IndexTypeQuals,
623 SourceRange BracketsRange);
624
Mike Stump11289f42009-09-09 15:08:12 +0000625 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000626 /// size modifier, size expression, and index type qualifiers.
627 ///
628 /// By default, performs semantic analysis when building the array type.
629 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000630 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000631 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000632 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000633 unsigned IndexTypeQuals,
634 SourceRange BracketsRange);
635
636 /// \brief Build a new vector type given the element type and
637 /// number of elements.
638 ///
639 /// By default, performs semantic analysis when building the vector type.
640 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000641 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000642 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000643
Douglas Gregord6ff3322009-08-04 16:50:30 +0000644 /// \brief Build a new extended vector type given the element type and
645 /// number of elements.
646 ///
647 /// By default, performs semantic analysis when building the vector type.
648 /// Subclasses may override this routine to provide different behavior.
649 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
650 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000651
652 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000653 /// given the element type and number of elements.
654 ///
655 /// By default, performs semantic analysis when building the vector type.
656 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000657 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000658 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000659 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000660
Douglas Gregord6ff3322009-08-04 16:50:30 +0000661 /// \brief Build a new function type.
662 ///
663 /// By default, performs semantic analysis when building the function type.
664 /// Subclasses may override this routine to provide different behavior.
665 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000666 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000667 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000668 bool Variadic, unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +0000669 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +0000670 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000671
John McCall550e0c22009-10-21 00:40:46 +0000672 /// \brief Build a new unprototyped function type.
673 QualType RebuildFunctionNoProtoType(QualType ResultType);
674
John McCallb96ec562009-12-04 22:46:56 +0000675 /// \brief Rebuild an unresolved typename type, given the decl that
676 /// the UnresolvedUsingTypenameDecl was transformed to.
677 QualType RebuildUnresolvedUsingType(Decl *D);
678
Douglas Gregord6ff3322009-08-04 16:50:30 +0000679 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000680 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000681 return SemaRef.Context.getTypeDeclType(Typedef);
682 }
683
684 /// \brief Build a new class/struct/union type.
685 QualType RebuildRecordType(RecordDecl *Record) {
686 return SemaRef.Context.getTypeDeclType(Record);
687 }
688
689 /// \brief Build a new Enum type.
690 QualType RebuildEnumType(EnumDecl *Enum) {
691 return SemaRef.Context.getTypeDeclType(Enum);
692 }
John McCallfcc33b02009-09-05 00:15:47 +0000693
Mike Stump11289f42009-09-09 15:08:12 +0000694 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000695 ///
696 /// By default, performs semantic analysis when building the typeof type.
697 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000698 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000699
Mike Stump11289f42009-09-09 15:08:12 +0000700 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000701 ///
702 /// By default, builds a new TypeOfType with the given underlying type.
703 QualType RebuildTypeOfType(QualType Underlying);
704
Alexis Hunte852b102011-05-24 22:41:36 +0000705 /// \brief Build a new unary transform type.
706 QualType RebuildUnaryTransformType(QualType BaseType,
707 UnaryTransformType::UTTKind UKind,
708 SourceLocation Loc);
709
Mike Stump11289f42009-09-09 15:08:12 +0000710 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000711 ///
712 /// By default, performs semantic analysis when building the decltype type.
713 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000714 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000715
Richard Smith30482bc2011-02-20 03:19:35 +0000716 /// \brief Build a new C++0x auto type.
717 ///
718 /// By default, builds a new AutoType with the given deduced type.
719 QualType RebuildAutoType(QualType Deduced) {
720 return SemaRef.Context.getAutoType(Deduced);
721 }
722
Douglas Gregord6ff3322009-08-04 16:50:30 +0000723 /// \brief Build a new template specialization type.
724 ///
725 /// By default, performs semantic analysis when building the template
726 /// specialization type. Subclasses may override this routine to provide
727 /// different behavior.
728 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000729 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000730 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000731
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000732 /// \brief Build a new parenthesized type.
733 ///
734 /// By default, builds a new ParenType type from the inner type.
735 /// Subclasses may override this routine to provide different behavior.
736 QualType RebuildParenType(QualType InnerType) {
737 return SemaRef.Context.getParenType(InnerType);
738 }
739
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740 /// \brief Build a new qualified name type.
741 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000742 /// By default, builds a new ElaboratedType type from the keyword,
743 /// the nested-name-specifier and the named type.
744 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000745 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
746 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000747 NestedNameSpecifierLoc QualifierLoc,
748 QualType Named) {
749 return SemaRef.Context.getElaboratedType(Keyword,
750 QualifierLoc.getNestedNameSpecifier(),
751 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000752 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000753
754 /// \brief Build a new typename type that refers to a template-id.
755 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000756 /// By default, builds a new DependentNameType type from the
757 /// nested-name-specifier and the given type. Subclasses may override
758 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000759 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000760 ElaboratedTypeKeyword Keyword,
761 NestedNameSpecifierLoc QualifierLoc,
762 const IdentifierInfo *Name,
763 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000764 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000765 // Rebuild the template name.
766 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000767 CXXScopeSpec SS;
768 SS.Adopt(QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000769 TemplateName InstName
Douglas Gregor9db53502011-03-02 18:07:45 +0000770 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000771
772 if (InstName.isNull())
773 return QualType();
774
775 // If it's still dependent, make a dependent specialization.
776 if (InstName.getAsDependentTemplateName())
777 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
778 QualifierLoc.getNestedNameSpecifier(),
779 Name,
780 Args);
781
782 // Otherwise, make an elaborated type wrapping a non-dependent
783 // specialization.
784 QualType T =
785 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
786 if (T.isNull()) return QualType();
787
788 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
789 return T;
790
791 return SemaRef.Context.getElaboratedType(Keyword,
792 QualifierLoc.getNestedNameSpecifier(),
793 T);
794 }
795
Douglas Gregord6ff3322009-08-04 16:50:30 +0000796 /// \brief Build a new typename type that refers to an identifier.
797 ///
798 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000799 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000800 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000801 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000802 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000803 NestedNameSpecifierLoc QualifierLoc,
804 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000805 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000806 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000807 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000808
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000809 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000810 // If the name is still dependent, just build a new dependent name type.
811 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000812 return SemaRef.Context.getDependentNameType(Keyword,
813 QualifierLoc.getNestedNameSpecifier(),
814 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000815 }
816
Abramo Bagnara6150c882010-05-11 21:36:43 +0000817 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000818 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000819 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000820
821 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
822
Abramo Bagnarad7548482010-05-19 21:37:53 +0000823 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000824 // into a non-dependent elaborated-type-specifier. Find the tag we're
825 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000826 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000827 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
828 if (!DC)
829 return QualType();
830
John McCallbf8c5192010-05-27 06:40:31 +0000831 if (SemaRef.RequireCompleteDeclContext(SS, DC))
832 return QualType();
833
Douglas Gregore677daf2010-03-31 22:19:08 +0000834 TagDecl *Tag = 0;
835 SemaRef.LookupQualifiedName(Result, DC);
836 switch (Result.getResultKind()) {
837 case LookupResult::NotFound:
838 case LookupResult::NotFoundInCurrentInstantiation:
839 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000840
Douglas Gregore677daf2010-03-31 22:19:08 +0000841 case LookupResult::Found:
842 Tag = Result.getAsSingle<TagDecl>();
843 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000844
Douglas Gregore677daf2010-03-31 22:19:08 +0000845 case LookupResult::FoundOverloaded:
846 case LookupResult::FoundUnresolvedValue:
847 llvm_unreachable("Tag lookup cannot find non-tags");
848 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000849
Douglas Gregore677daf2010-03-31 22:19:08 +0000850 case LookupResult::Ambiguous:
851 // Let the LookupResult structure handle ambiguities.
852 return QualType();
853 }
854
855 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000856 // Check where the name exists but isn't a tag type and use that to emit
857 // better diagnostics.
858 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
859 SemaRef.LookupQualifiedName(Result, DC);
860 switch (Result.getResultKind()) {
861 case LookupResult::Found:
862 case LookupResult::FoundOverloaded:
863 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000864 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000865 unsigned Kind = 0;
866 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000867 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
868 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000869 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
870 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
871 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000872 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000873 default:
874 // FIXME: Would be nice to highlight just the source range.
875 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
876 << Kind << Id << DC;
877 break;
878 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000879 return QualType();
880 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000881
Richard Trieucaa33d32011-06-10 03:11:26 +0000882 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
883 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000884 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000885 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
886 return QualType();
887 }
888
889 // Build the elaborated-type-specifier type.
890 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000891 return SemaRef.Context.getElaboratedType(Keyword,
892 QualifierLoc.getNestedNameSpecifier(),
893 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000894 }
Mike Stump11289f42009-09-09 15:08:12 +0000895
Douglas Gregor822d0302011-01-12 17:07:58 +0000896 /// \brief Build a new pack expansion type.
897 ///
898 /// By default, builds a new PackExpansionType type from the given pattern.
899 /// Subclasses may override this routine to provide different behavior.
900 QualType RebuildPackExpansionType(QualType Pattern,
901 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000902 SourceLocation EllipsisLoc,
903 llvm::Optional<unsigned> NumExpansions) {
904 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
905 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000906 }
907
Eli Friedman0dfb8892011-10-06 23:00:33 +0000908 /// \brief Build a new atomic type given its value type.
909 ///
910 /// By default, performs semantic analysis when building the atomic type.
911 /// Subclasses may override this routine to provide different behavior.
912 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
913
Douglas Gregor71dc5092009-08-06 06:41:21 +0000914 /// \brief Build a new template name given a nested name specifier, a flag
915 /// indicating whether the "template" keyword was provided, and the template
916 /// that the template name refers to.
917 ///
918 /// By default, builds the new template name directly. Subclasses may override
919 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000920 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +0000921 bool TemplateKW,
922 TemplateDecl *Template);
923
Douglas Gregor71dc5092009-08-06 06:41:21 +0000924 /// \brief Build a new template name given a nested name specifier and the
925 /// name that is referred to as a template.
926 ///
927 /// By default, performs semantic analysis to determine whether the name can
928 /// be resolved to a specific template, then builds the appropriate kind of
929 /// template name. Subclasses may override this routine to provide different
930 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000931 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
932 const IdentifierInfo &Name,
933 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +0000934 QualType ObjectType,
935 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000936
Douglas Gregor71395fa2009-11-04 00:56:37 +0000937 /// \brief Build a new template name given a nested name specifier and the
938 /// overloaded operator name that is referred to as a template.
939 ///
940 /// By default, performs semantic analysis to determine whether the name can
941 /// be resolved to a specific template, then builds the appropriate kind of
942 /// template name. Subclasses may override this routine to provide different
943 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000944 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000945 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +0000946 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000947 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000948
949 /// \brief Build a new template name given a template template parameter pack
950 /// and the
951 ///
952 /// By default, performs semantic analysis to determine whether the name can
953 /// be resolved to a specific template, then builds the appropriate kind of
954 /// template name. Subclasses may override this routine to provide different
955 /// behavior.
956 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
957 const TemplateArgument &ArgPack) {
958 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
959 }
960
Douglas Gregorebe10102009-08-20 07:17:43 +0000961 /// \brief Build a new compound statement.
962 ///
963 /// By default, performs semantic analysis to build the new statement.
964 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000965 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000966 MultiStmtArg Statements,
967 SourceLocation RBraceLoc,
968 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000969 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000970 IsStmtExpr);
971 }
972
973 /// \brief Build a new case statement.
974 ///
975 /// By default, performs semantic analysis to build the new statement.
976 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000977 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000978 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000979 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000980 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000981 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000982 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000983 ColonLoc);
984 }
Mike Stump11289f42009-09-09 15:08:12 +0000985
Douglas Gregorebe10102009-08-20 07:17:43 +0000986 /// \brief Attach the body to a new case statement.
987 ///
988 /// By default, performs semantic analysis to build the new statement.
989 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000990 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000991 getSema().ActOnCaseStmtBody(S, Body);
992 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000993 }
Mike Stump11289f42009-09-09 15:08:12 +0000994
Douglas Gregorebe10102009-08-20 07:17:43 +0000995 /// \brief Build a new default statement.
996 ///
997 /// By default, performs semantic analysis to build the new statement.
998 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000999 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001000 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001001 Stmt *SubStmt) {
1002 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +00001003 /*CurScope=*/0);
1004 }
Mike Stump11289f42009-09-09 15:08:12 +00001005
Douglas Gregorebe10102009-08-20 07:17:43 +00001006 /// \brief Build a new label statement.
1007 ///
1008 /// By default, performs semantic analysis to build the new statement.
1009 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001010 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1011 SourceLocation ColonLoc, Stmt *SubStmt) {
1012 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001013 }
Mike Stump11289f42009-09-09 15:08:12 +00001014
Douglas Gregorebe10102009-08-20 07:17:43 +00001015 /// \brief Build a new "if" statement.
1016 ///
1017 /// By default, performs semantic analysis to build the new statement.
1018 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001019 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattnercab02a62011-02-17 20:34:02 +00001020 VarDecl *CondVar, Stmt *Then,
1021 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001022 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001023 }
Mike Stump11289f42009-09-09 15:08:12 +00001024
Douglas Gregorebe10102009-08-20 07:17:43 +00001025 /// \brief Start building a new switch statement.
1026 ///
1027 /// By default, performs semantic analysis to build the new statement.
1028 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001029 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001030 Expr *Cond, VarDecl *CondVar) {
John McCallb268a282010-08-23 23:25:46 +00001031 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001032 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001033 }
Mike Stump11289f42009-09-09 15:08:12 +00001034
Douglas Gregorebe10102009-08-20 07:17:43 +00001035 /// \brief Attach the body to the switch statement.
1036 ///
1037 /// By default, performs semantic analysis to build the new statement.
1038 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001039 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001040 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001041 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001042 }
1043
1044 /// \brief Build a new while statement.
1045 ///
1046 /// By default, performs semantic analysis to build the new statement.
1047 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001048 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1049 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001050 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001051 }
Mike Stump11289f42009-09-09 15:08:12 +00001052
Douglas Gregorebe10102009-08-20 07:17:43 +00001053 /// \brief Build a new do-while 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 RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001058 SourceLocation WhileLoc, SourceLocation LParenLoc,
1059 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001060 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1061 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001062 }
1063
1064 /// \brief Build a new for statement.
1065 ///
1066 /// By default, performs semantic analysis to build the new statement.
1067 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001068 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1069 Stmt *Init, Sema::FullExprArg Cond,
1070 VarDecl *CondVar, Sema::FullExprArg Inc,
1071 SourceLocation RParenLoc, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001072 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001073 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001074 }
Mike Stump11289f42009-09-09 15:08:12 +00001075
Douglas Gregorebe10102009-08-20 07:17:43 +00001076 /// \brief Build a new goto statement.
1077 ///
1078 /// By default, performs semantic analysis to build the new statement.
1079 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001080 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1081 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001082 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001083 }
1084
1085 /// \brief Build a new indirect goto statement.
1086 ///
1087 /// By default, performs semantic analysis to build the new statement.
1088 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001089 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001090 SourceLocation StarLoc,
1091 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001092 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001093 }
Mike Stump11289f42009-09-09 15:08:12 +00001094
Douglas Gregorebe10102009-08-20 07:17:43 +00001095 /// \brief Build a new return statement.
1096 ///
1097 /// By default, performs semantic analysis to build the new statement.
1098 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001099 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001100 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001101 }
Mike Stump11289f42009-09-09 15:08:12 +00001102
Douglas Gregorebe10102009-08-20 07:17:43 +00001103 /// \brief Build a new declaration statement.
1104 ///
1105 /// By default, performs semantic analysis to build the new statement.
1106 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001107 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001108 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001109 SourceLocation EndLoc) {
Richard Smith2abf6762011-02-23 00:37:57 +00001110 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1111 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001112 }
Mike Stump11289f42009-09-09 15:08:12 +00001113
Anders Carlssonaaeef072010-01-24 05:50:09 +00001114 /// \brief Build a new inline asm statement.
1115 ///
1116 /// By default, performs semantic analysis to build the new statement.
1117 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001118 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001119 bool IsSimple,
1120 bool IsVolatile,
1121 unsigned NumOutputs,
1122 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001123 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001124 MultiExprArg Constraints,
1125 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001126 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001127 MultiExprArg Clobbers,
1128 SourceLocation RParenLoc,
1129 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001130 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001131 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001132 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001133 RParenLoc, MSAsm);
1134 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001135
1136 /// \brief Build a new Objective-C @try statement.
1137 ///
1138 /// By default, performs semantic analysis to build the new statement.
1139 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001140 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001141 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001142 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001143 Stmt *Finally) {
1144 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1145 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001146 }
1147
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001148 /// \brief Rebuild an Objective-C exception declaration.
1149 ///
1150 /// By default, performs semantic analysis to build the new declaration.
1151 /// Subclasses may override this routine to provide different behavior.
1152 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1153 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001154 return getSema().BuildObjCExceptionDecl(TInfo, T,
1155 ExceptionDecl->getInnerLocStart(),
1156 ExceptionDecl->getLocation(),
1157 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001158 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001159
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001160 /// \brief Build a new Objective-C @catch statement.
1161 ///
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001164 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001165 SourceLocation RParenLoc,
1166 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001167 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001168 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001169 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001170 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001171
Douglas Gregor306de2f2010-04-22 23:59:56 +00001172 /// \brief Build a new Objective-C @finally statement.
1173 ///
1174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001176 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001177 Stmt *Body) {
1178 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001179 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001180
Douglas Gregor6148de72010-04-22 22:01:21 +00001181 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001182 ///
1183 /// By default, performs semantic analysis to build the new statement.
1184 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001185 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001186 Expr *Operand) {
1187 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001188 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001189
John McCalld9bb7432011-07-27 21:50:02 +00001190 /// \brief Rebuild the operand to an Objective-C @synchronized statement.
1191 ///
1192 /// By default, performs semantic analysis to build the new statement.
1193 /// Subclasses may override this routine to provide different behavior.
1194 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1195 Expr *object) {
1196 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1197 }
1198
Douglas Gregor6148de72010-04-22 22:01:21 +00001199 /// \brief Build a new Objective-C @synchronized statement.
1200 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001201 /// By default, performs semantic analysis to build the new statement.
1202 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001203 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001204 Expr *Object, Stmt *Body) {
1205 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001206 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001207
John McCall31168b02011-06-15 23:02:42 +00001208 /// \brief Build a new Objective-C @autoreleasepool statement.
1209 ///
1210 /// By default, performs semantic analysis to build the new statement.
1211 /// Subclasses may override this routine to provide different behavior.
1212 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1213 Stmt *Body) {
1214 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1215 }
John McCall53848232011-07-27 01:07:15 +00001216
1217 /// \brief Build the collection operand to a new Objective-C fast
1218 /// enumeration statement.
1219 ///
1220 /// By default, performs semantic analysis to build the new statement.
1221 /// Subclasses may override this routine to provide different behavior.
1222 ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc,
1223 Expr *collection) {
1224 return getSema().ActOnObjCForCollectionOperand(forLoc, collection);
1225 }
John McCall31168b02011-06-15 23:02:42 +00001226
Douglas Gregorf68a5082010-04-22 23:10:45 +00001227 /// \brief Build a new Objective-C fast enumeration statement.
1228 ///
1229 /// By default, performs semantic analysis to build the new statement.
1230 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001231 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001232 SourceLocation LParenLoc,
1233 Stmt *Element,
1234 Expr *Collection,
1235 SourceLocation RParenLoc,
1236 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001237 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001238 Element,
1239 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001240 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001241 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001242 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001243
Douglas Gregorebe10102009-08-20 07:17:43 +00001244 /// \brief Build a new C++ exception declaration.
1245 ///
1246 /// By default, performs semantic analysis to build the new decaration.
1247 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001248 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001249 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001250 SourceLocation StartLoc,
1251 SourceLocation IdLoc,
1252 IdentifierInfo *Id) {
Douglas Gregor40965fa2011-04-14 22:32:28 +00001253 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1254 StartLoc, IdLoc, Id);
1255 if (Var)
1256 getSema().CurContext->addDecl(Var);
1257 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001258 }
1259
1260 /// \brief Build a new C++ catch statement.
1261 ///
1262 /// By default, performs semantic analysis to build the new statement.
1263 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001264 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001265 VarDecl *ExceptionDecl,
1266 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001267 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1268 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001269 }
Mike Stump11289f42009-09-09 15:08:12 +00001270
Douglas Gregorebe10102009-08-20 07:17:43 +00001271 /// \brief Build a new C++ try statement.
1272 ///
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 RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001276 Stmt *TryBlock,
1277 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001278 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001279 }
Mike Stump11289f42009-09-09 15:08:12 +00001280
Richard Smith02e85f32011-04-14 22:09:26 +00001281 /// \brief Build a new C++0x range-based for statement.
1282 ///
1283 /// By default, performs semantic analysis to build the new statement.
1284 /// Subclasses may override this routine to provide different behavior.
1285 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1286 SourceLocation ColonLoc,
1287 Stmt *Range, Stmt *BeginEnd,
1288 Expr *Cond, Expr *Inc,
1289 Stmt *LoopVar,
1290 SourceLocation RParenLoc) {
1291 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1292 Cond, Inc, LoopVar, RParenLoc);
1293 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001294
1295 /// \brief Build a new C++0x range-based for statement.
1296 ///
1297 /// By default, performs semantic analysis to build the new statement.
1298 /// Subclasses may override this routine to provide different behavior.
1299 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
1300 bool IsIfExists,
1301 NestedNameSpecifierLoc QualifierLoc,
1302 DeclarationNameInfo NameInfo,
1303 Stmt *Nested) {
1304 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1305 QualifierLoc, NameInfo, Nested);
1306 }
1307
Richard Smith02e85f32011-04-14 22:09:26 +00001308 /// \brief Attach body to a C++0x range-based for statement.
1309 ///
1310 /// By default, performs semantic analysis to finish the new statement.
1311 /// Subclasses may override this routine to provide different behavior.
1312 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1313 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1314 }
1315
John Wiegley1c0675e2011-04-28 01:08:34 +00001316 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1317 SourceLocation TryLoc,
1318 Stmt *TryBlock,
1319 Stmt *Handler) {
1320 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1321 }
1322
1323 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1324 Expr *FilterExpr,
1325 Stmt *Block) {
1326 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1327 }
1328
1329 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1330 Stmt *Block) {
1331 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1332 }
1333
Douglas Gregora16548e2009-08-11 05:31:07 +00001334 /// \brief Build a new expression that references a declaration.
1335 ///
1336 /// By default, performs semantic analysis to build the new expression.
1337 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001338 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001339 LookupResult &R,
1340 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001341 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1342 }
1343
1344
1345 /// \brief Build a new expression that references a declaration.
1346 ///
1347 /// By default, performs semantic analysis to build the new expression.
1348 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001349 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001350 ValueDecl *VD,
1351 const DeclarationNameInfo &NameInfo,
1352 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001353 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001354 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001355
1356 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001357
1358 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001359 }
Mike Stump11289f42009-09-09 15:08:12 +00001360
Douglas Gregora16548e2009-08-11 05:31:07 +00001361 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001362 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001363 /// By default, performs semantic analysis to build the new expression.
1364 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001365 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001366 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001367 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001368 }
1369
Douglas Gregorad8a3362009-09-04 17:36:40 +00001370 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001371 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001372 /// By default, performs semantic analysis to build the new expression.
1373 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001374 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001375 SourceLocation OperatorLoc,
1376 bool isArrow,
1377 CXXScopeSpec &SS,
1378 TypeSourceInfo *ScopeType,
1379 SourceLocation CCLoc,
1380 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001381 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001382
Douglas Gregora16548e2009-08-11 05:31:07 +00001383 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001384 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001385 /// By default, performs semantic analysis to build the new expression.
1386 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001387 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001388 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001389 Expr *SubExpr) {
1390 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001391 }
Mike Stump11289f42009-09-09 15:08:12 +00001392
Douglas Gregor882211c2010-04-28 22:16:22 +00001393 /// \brief Build a new builtin offsetof expression.
1394 ///
1395 /// By default, performs semantic analysis to build the new expression.
1396 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001397 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001398 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001399 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001400 unsigned NumComponents,
1401 SourceLocation RParenLoc) {
1402 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1403 NumComponents, RParenLoc);
1404 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001405
Peter Collingbournee190dee2011-03-11 19:24:49 +00001406 /// \brief Build a new sizeof, alignof or vec_step expression with a
1407 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001408 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 /// By default, performs semantic analysis to build the new expression.
1410 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001411 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1412 SourceLocation OpLoc,
1413 UnaryExprOrTypeTrait ExprKind,
1414 SourceRange R) {
1415 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001416 }
1417
Peter Collingbournee190dee2011-03-11 19:24:49 +00001418 /// \brief Build a new sizeof, alignof or vec step expression with an
1419 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001420 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001421 /// By default, performs semantic analysis to build the new expression.
1422 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001423 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1424 UnaryExprOrTypeTrait ExprKind,
1425 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001426 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001427 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001428 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001429 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001430
Douglas Gregora16548e2009-08-11 05:31:07 +00001431 return move(Result);
1432 }
Mike Stump11289f42009-09-09 15:08:12 +00001433
Douglas Gregora16548e2009-08-11 05:31:07 +00001434 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001435 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001436 /// By default, performs semantic analysis to build the new expression.
1437 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001438 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001439 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001440 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001441 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001442 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1443 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001444 RBracketLoc);
1445 }
1446
1447 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001448 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001449 /// By default, performs semantic analysis to build the new expression.
1450 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001451 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001452 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001453 SourceLocation RParenLoc,
1454 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001455 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001456 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001457 }
1458
1459 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001460 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001461 /// By default, performs semantic analysis to build the new expression.
1462 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001463 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001464 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001465 NestedNameSpecifierLoc QualifierLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001466 const DeclarationNameInfo &MemberNameInfo,
1467 ValueDecl *Member,
1468 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001469 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001470 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001471 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001472 // We have a reference to an unnamed field. This is always the
1473 // base of an anonymous struct/union member access, i.e. the
1474 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001475 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001476 assert(Member->getType()->isRecordType() &&
1477 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001478
John Wiegley01296292011-04-08 18:41:53 +00001479 ExprResult BaseResult =
1480 getSema().PerformObjectMemberConversion(Base,
1481 QualifierLoc.getNestedNameSpecifier(),
1482 FoundDecl, Member);
1483 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001484 return ExprError();
John Wiegley01296292011-04-08 18:41:53 +00001485 Base = BaseResult.take();
John McCall7decc9e2010-11-18 06:31:45 +00001486 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001487 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001488 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001489 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001490 cast<FieldDecl>(Member)->getType(),
1491 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001492 return getSema().Owned(ME);
1493 }
Mike Stump11289f42009-09-09 15:08:12 +00001494
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001495 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001496 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001497
John Wiegley01296292011-04-08 18:41:53 +00001498 ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base);
1499 if (BaseResult.isInvalid())
1500 return ExprError();
Richard Smith841222e2011-10-25 00:41:24 +00001501 if (isArrow) {
1502 BaseResult = getSema().DefaultLvalueConversion(BaseResult.get());
1503 if (BaseResult.isInvalid())
1504 return ExprError();
1505 }
John Wiegley01296292011-04-08 18:41:53 +00001506 Base = BaseResult.take();
John McCallb268a282010-08-23 23:25:46 +00001507 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001508
John McCall16df1e52010-03-30 21:47:33 +00001509 // FIXME: this involves duplicating earlier analysis in a lot of
1510 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001511 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001512 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001513 R.resolveKind();
1514
John McCallb268a282010-08-23 23:25:46 +00001515 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001516 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001517 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001518 }
Mike Stump11289f42009-09-09 15:08:12 +00001519
Douglas Gregora16548e2009-08-11 05:31:07 +00001520 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001521 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 /// By default, performs semantic analysis to build the new expression.
1523 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001524 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001525 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001526 Expr *LHS, Expr *RHS) {
1527 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001528 }
1529
1530 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001531 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001532 /// By default, performs semantic analysis to build the new expression.
1533 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001534 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001535 SourceLocation QuestionLoc,
1536 Expr *LHS,
1537 SourceLocation ColonLoc,
1538 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001539 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1540 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001541 }
1542
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001544 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001545 /// By default, performs semantic analysis to build the new expression.
1546 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001547 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001548 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001549 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001550 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001551 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001552 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001553 }
Mike Stump11289f42009-09-09 15:08:12 +00001554
Douglas Gregora16548e2009-08-11 05:31:07 +00001555 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001556 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001557 /// By default, performs semantic analysis to build the new expression.
1558 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001559 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001560 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001561 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001562 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001563 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001564 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001565 }
Mike Stump11289f42009-09-09 15:08:12 +00001566
Douglas Gregora16548e2009-08-11 05:31:07 +00001567 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001568 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001569 /// By default, performs semantic analysis to build the new expression.
1570 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001571 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001572 SourceLocation OpLoc,
1573 SourceLocation AccessorLoc,
1574 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001575
John McCall10eae182009-11-30 22:42:35 +00001576 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001577 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001578 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001579 OpLoc, /*IsArrow*/ false,
1580 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001581 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001582 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001583 }
Mike Stump11289f42009-09-09 15:08:12 +00001584
Douglas Gregora16548e2009-08-11 05:31:07 +00001585 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001586 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001587 /// By default, performs semantic analysis to build the new expression.
1588 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001589 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001590 MultiExprArg Inits,
1591 SourceLocation RBraceLoc,
1592 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001593 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001594 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1595 if (Result.isInvalid() || ResultTy->isDependentType())
1596 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001597
Douglas Gregord3d93062009-11-09 17:16:50 +00001598 // Patch in the result type we were given, which may have been computed
1599 // when the initial InitListExpr was built.
1600 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1601 ILE->setType(ResultTy);
1602 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001603 }
Mike Stump11289f42009-09-09 15:08:12 +00001604
Douglas Gregora16548e2009-08-11 05:31:07 +00001605 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001606 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001607 /// By default, performs semantic analysis to build the new expression.
1608 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001609 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001610 MultiExprArg ArrayExprs,
1611 SourceLocation EqualOrColonLoc,
1612 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001613 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001614 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001615 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001616 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001617 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001618 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001619
Douglas Gregora16548e2009-08-11 05:31:07 +00001620 ArrayExprs.release();
1621 return move(Result);
1622 }
Mike Stump11289f42009-09-09 15:08:12 +00001623
Douglas Gregora16548e2009-08-11 05:31:07 +00001624 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001625 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001626 /// By default, builds the implicit value initialization without performing
1627 /// any semantic analysis. Subclasses may override this routine to provide
1628 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001629 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001630 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1631 }
Mike Stump11289f42009-09-09 15:08:12 +00001632
Douglas Gregora16548e2009-08-11 05:31:07 +00001633 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001634 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 /// By default, performs semantic analysis to build the new expression.
1636 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001637 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001638 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001639 SourceLocation RParenLoc) {
1640 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001641 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001642 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001643 }
1644
1645 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001646 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001647 /// By default, performs semantic analysis to build the new expression.
1648 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001649 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001650 MultiExprArg SubExprs,
1651 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001652 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001653 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001654 }
Mike Stump11289f42009-09-09 15:08:12 +00001655
Douglas Gregora16548e2009-08-11 05:31:07 +00001656 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001657 ///
1658 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001659 /// rather than attempting to map the label statement itself.
1660 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001661 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001662 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001663 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001664 }
Mike Stump11289f42009-09-09 15:08:12 +00001665
Douglas Gregora16548e2009-08-11 05:31:07 +00001666 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001667 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001668 /// By default, performs semantic analysis to build the new expression.
1669 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001670 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001671 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001672 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001673 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001674 }
Mike Stump11289f42009-09-09 15:08:12 +00001675
Douglas Gregora16548e2009-08-11 05:31:07 +00001676 /// \brief Build a new __builtin_choose_expr expression.
1677 ///
1678 /// By default, performs semantic analysis to build the new expression.
1679 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001680 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001681 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001682 SourceLocation RParenLoc) {
1683 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001684 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001685 RParenLoc);
1686 }
Mike Stump11289f42009-09-09 15:08:12 +00001687
Peter Collingbourne91147592011-04-15 00:35:48 +00001688 /// \brief Build a new generic selection expression.
1689 ///
1690 /// By default, performs semantic analysis to build the new expression.
1691 /// Subclasses may override this routine to provide different behavior.
1692 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1693 SourceLocation DefaultLoc,
1694 SourceLocation RParenLoc,
1695 Expr *ControllingExpr,
1696 TypeSourceInfo **Types,
1697 Expr **Exprs,
1698 unsigned NumAssocs) {
1699 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1700 ControllingExpr, Types, Exprs,
1701 NumAssocs);
1702 }
1703
Douglas Gregora16548e2009-08-11 05:31:07 +00001704 /// \brief Build a new overloaded operator call expression.
1705 ///
1706 /// By default, performs semantic analysis to build the new expression.
1707 /// The semantic analysis provides the behavior of template instantiation,
1708 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001709 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001710 /// argument-dependent lookup, etc. Subclasses may override this routine to
1711 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001712 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001713 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001714 Expr *Callee,
1715 Expr *First,
1716 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001717
1718 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001719 /// reinterpret_cast.
1720 ///
1721 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001722 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001723 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001724 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001725 Stmt::StmtClass Class,
1726 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001727 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001728 SourceLocation RAngleLoc,
1729 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001730 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001731 SourceLocation RParenLoc) {
1732 switch (Class) {
1733 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001734 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001735 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001736 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001737
1738 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001739 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001740 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001741 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001742
Douglas Gregora16548e2009-08-11 05:31:07 +00001743 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001744 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001745 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001746 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001747 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001748
Douglas Gregora16548e2009-08-11 05:31:07 +00001749 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001750 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001751 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001752 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001753
Douglas Gregora16548e2009-08-11 05:31:07 +00001754 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001755 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00001756 }
Mike Stump11289f42009-09-09 15:08:12 +00001757
John McCallfaf5fb42010-08-26 23:41:50 +00001758 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001759 }
Mike Stump11289f42009-09-09 15:08:12 +00001760
Douglas Gregora16548e2009-08-11 05:31:07 +00001761 /// \brief Build a new C++ static_cast expression.
1762 ///
1763 /// By default, performs semantic analysis to build the new expression.
1764 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001765 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001766 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001767 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001768 SourceLocation RAngleLoc,
1769 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001770 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001771 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001772 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001773 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001774 SourceRange(LAngleLoc, RAngleLoc),
1775 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001776 }
1777
1778 /// \brief Build a new C++ dynamic_cast expression.
1779 ///
1780 /// By default, performs semantic analysis to build the new expression.
1781 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001782 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001783 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001784 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001785 SourceLocation RAngleLoc,
1786 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001787 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001788 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001789 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001790 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001791 SourceRange(LAngleLoc, RAngleLoc),
1792 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001793 }
1794
1795 /// \brief Build a new C++ reinterpret_cast expression.
1796 ///
1797 /// By default, performs semantic analysis to build the new expression.
1798 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001799 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001800 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001801 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001802 SourceLocation RAngleLoc,
1803 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001804 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001805 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001806 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001807 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001808 SourceRange(LAngleLoc, RAngleLoc),
1809 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001810 }
1811
1812 /// \brief Build a new C++ const_cast expression.
1813 ///
1814 /// By default, performs semantic analysis to build the new expression.
1815 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001816 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001817 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001818 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001819 SourceLocation RAngleLoc,
1820 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001821 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001822 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001823 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001824 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001825 SourceRange(LAngleLoc, RAngleLoc),
1826 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001827 }
Mike Stump11289f42009-09-09 15:08:12 +00001828
Douglas Gregora16548e2009-08-11 05:31:07 +00001829 /// \brief Build a new C++ functional-style cast expression.
1830 ///
1831 /// By default, performs semantic analysis to build the new expression.
1832 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001833 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1834 SourceLocation LParenLoc,
1835 Expr *Sub,
1836 SourceLocation RParenLoc) {
1837 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001838 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001839 RParenLoc);
1840 }
Mike Stump11289f42009-09-09 15:08:12 +00001841
Douglas Gregora16548e2009-08-11 05:31:07 +00001842 /// \brief Build a new C++ typeid(type) expression.
1843 ///
1844 /// By default, performs semantic analysis to build the new expression.
1845 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001846 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001847 SourceLocation TypeidLoc,
1848 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001849 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001850 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001851 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001852 }
Mike Stump11289f42009-09-09 15:08:12 +00001853
Francois Pichet9f4f2072010-09-08 12:20:18 +00001854
Douglas Gregora16548e2009-08-11 05:31:07 +00001855 /// \brief Build a new C++ typeid(expr) expression.
1856 ///
1857 /// By default, performs semantic analysis to build the new expression.
1858 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001859 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001860 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001861 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001862 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001863 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001864 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001865 }
1866
Francois Pichet9f4f2072010-09-08 12:20:18 +00001867 /// \brief Build a new C++ __uuidof(type) expression.
1868 ///
1869 /// By default, performs semantic analysis to build the new expression.
1870 /// Subclasses may override this routine to provide different behavior.
1871 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1872 SourceLocation TypeidLoc,
1873 TypeSourceInfo *Operand,
1874 SourceLocation RParenLoc) {
1875 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1876 RParenLoc);
1877 }
1878
1879 /// \brief Build a new C++ __uuidof(expr) expression.
1880 ///
1881 /// By default, performs semantic analysis to build the new expression.
1882 /// Subclasses may override this routine to provide different behavior.
1883 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1884 SourceLocation TypeidLoc,
1885 Expr *Operand,
1886 SourceLocation RParenLoc) {
1887 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1888 RParenLoc);
1889 }
1890
Douglas Gregora16548e2009-08-11 05:31:07 +00001891 /// \brief Build a new C++ "this" expression.
1892 ///
1893 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001894 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001895 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001896 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001897 QualType ThisType,
1898 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001899 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001900 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1901 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001902 }
1903
1904 /// \brief Build a new C++ throw expression.
1905 ///
1906 /// By default, performs semantic analysis to build the new expression.
1907 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00001908 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1909 bool IsThrownVariableInScope) {
1910 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00001911 }
1912
1913 /// \brief Build a new C++ default-argument expression.
1914 ///
1915 /// By default, builds a new default-argument expression, which does not
1916 /// require any semantic analysis. Subclasses may override this routine to
1917 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001918 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001919 ParmVarDecl *Param) {
1920 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1921 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001922 }
1923
1924 /// \brief Build a new C++ zero-initialization expression.
1925 ///
1926 /// By default, performs semantic analysis to build the new expression.
1927 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001928 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1929 SourceLocation LParenLoc,
1930 SourceLocation RParenLoc) {
1931 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001932 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001933 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001934 }
Mike Stump11289f42009-09-09 15:08:12 +00001935
Douglas Gregora16548e2009-08-11 05:31:07 +00001936 /// \brief Build a new C++ "new" expression.
1937 ///
1938 /// By default, performs semantic analysis to build the new expression.
1939 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001940 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001941 bool UseGlobal,
1942 SourceLocation PlacementLParen,
1943 MultiExprArg PlacementArgs,
1944 SourceLocation PlacementRParen,
1945 SourceRange TypeIdParens,
1946 QualType AllocatedType,
1947 TypeSourceInfo *AllocatedTypeInfo,
1948 Expr *ArraySize,
1949 SourceLocation ConstructorLParen,
1950 MultiExprArg ConstructorArgs,
1951 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001952 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001953 PlacementLParen,
1954 move(PlacementArgs),
1955 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001956 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001957 AllocatedType,
1958 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001959 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001960 ConstructorLParen,
1961 move(ConstructorArgs),
1962 ConstructorRParen);
1963 }
Mike Stump11289f42009-09-09 15:08:12 +00001964
Douglas Gregora16548e2009-08-11 05:31:07 +00001965 /// \brief Build a new C++ "delete" expression.
1966 ///
1967 /// By default, performs semantic analysis to build the new expression.
1968 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001969 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001970 bool IsGlobalDelete,
1971 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001972 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001973 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001974 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001975 }
Mike Stump11289f42009-09-09 15:08:12 +00001976
Douglas Gregora16548e2009-08-11 05:31:07 +00001977 /// \brief Build a new unary type trait expression.
1978 ///
1979 /// By default, performs semantic analysis to build the new expression.
1980 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001981 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001982 SourceLocation StartLoc,
1983 TypeSourceInfo *T,
1984 SourceLocation RParenLoc) {
1985 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001986 }
1987
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001988 /// \brief Build a new binary type trait expression.
1989 ///
1990 /// By default, performs semantic analysis to build the new expression.
1991 /// Subclasses may override this routine to provide different behavior.
1992 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1993 SourceLocation StartLoc,
1994 TypeSourceInfo *LhsT,
1995 TypeSourceInfo *RhsT,
1996 SourceLocation RParenLoc) {
1997 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1998 }
1999
John Wiegley6242b6a2011-04-28 00:16:57 +00002000 /// \brief Build a new array type trait expression.
2001 ///
2002 /// By default, performs semantic analysis to build the new expression.
2003 /// Subclasses may override this routine to provide different behavior.
2004 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2005 SourceLocation StartLoc,
2006 TypeSourceInfo *TSInfo,
2007 Expr *DimExpr,
2008 SourceLocation RParenLoc) {
2009 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2010 }
2011
John Wiegleyf9f65842011-04-25 06:54:41 +00002012 /// \brief Build a new expression trait expression.
2013 ///
2014 /// By default, performs semantic analysis to build the new expression.
2015 /// Subclasses may override this routine to provide different behavior.
2016 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2017 SourceLocation StartLoc,
2018 Expr *Queried,
2019 SourceLocation RParenLoc) {
2020 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2021 }
2022
Mike Stump11289f42009-09-09 15:08:12 +00002023 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002024 /// expression.
2025 ///
2026 /// By default, performs semantic analysis to build the new expression.
2027 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002028 ExprResult RebuildDependentScopeDeclRefExpr(
2029 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002030 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00002031 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002032 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002033 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002034
2035 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002036 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00002037 *TemplateArgs);
2038
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002039 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00002040 }
2041
2042 /// \brief Build a new template-id expression.
2043 ///
2044 /// By default, performs semantic analysis to build the new expression.
2045 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002046 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00002047 LookupResult &R,
2048 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00002049 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00002050 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002051 }
2052
2053 /// \brief Build a new object-construction expression.
2054 ///
2055 /// By default, performs semantic analysis to build the new expression.
2056 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002057 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002058 SourceLocation Loc,
2059 CXXConstructorDecl *Constructor,
2060 bool IsElidable,
2061 MultiExprArg Args,
2062 bool HadMultipleCandidates,
2063 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002064 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002065 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00002066 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002067 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002068 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002069 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002070
Douglas Gregordb121ba2009-12-14 16:27:04 +00002071 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00002072 move_arg(ConvertedArgs),
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002073 HadMultipleCandidates,
Chandler Carruth01718152010-10-25 08:47:36 +00002074 RequiresZeroInit, ConstructKind,
2075 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002076 }
2077
2078 /// \brief Build a new object-construction expression.
2079 ///
2080 /// By default, performs semantic analysis to build the new expression.
2081 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002082 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2083 SourceLocation LParenLoc,
2084 MultiExprArg Args,
2085 SourceLocation RParenLoc) {
2086 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002087 LParenLoc,
2088 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002089 RParenLoc);
2090 }
2091
2092 /// \brief Build a new object-construction expression.
2093 ///
2094 /// By default, performs semantic analysis to build the new expression.
2095 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002096 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2097 SourceLocation LParenLoc,
2098 MultiExprArg Args,
2099 SourceLocation RParenLoc) {
2100 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002101 LParenLoc,
2102 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002103 RParenLoc);
2104 }
Mike Stump11289f42009-09-09 15:08:12 +00002105
Douglas Gregora16548e2009-08-11 05:31:07 +00002106 /// \brief Build a new member reference expression.
2107 ///
2108 /// By default, performs semantic analysis to build the new expression.
2109 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002110 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002111 QualType BaseType,
2112 bool IsArrow,
2113 SourceLocation OperatorLoc,
2114 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00002115 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002116 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002117 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002118 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002119 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002120
John McCallb268a282010-08-23 23:25:46 +00002121 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002122 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00002123 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002124 MemberNameInfo,
2125 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002126 }
2127
John McCall10eae182009-11-30 22:42:35 +00002128 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002129 ///
2130 /// By default, performs semantic analysis to build the new expression.
2131 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002132 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00002133 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00002134 SourceLocation OperatorLoc,
2135 bool IsArrow,
Douglas Gregor0da1d432011-02-28 20:01:57 +00002136 NestedNameSpecifierLoc QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00002137 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00002138 LookupResult &R,
2139 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002140 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002141 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002142
John McCallb268a282010-08-23 23:25:46 +00002143 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002144 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00002145 SS, FirstQualifierInScope,
2146 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002147 }
Mike Stump11289f42009-09-09 15:08:12 +00002148
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002149 /// \brief Build a new noexcept expression.
2150 ///
2151 /// By default, performs semantic analysis to build the new expression.
2152 /// Subclasses may override this routine to provide different behavior.
2153 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2154 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2155 }
2156
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002157 /// \brief Build a new expression to compute the length of a parameter pack.
2158 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2159 SourceLocation PackLoc,
2160 SourceLocation RParenLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002161 llvm::Optional<unsigned> Length) {
2162 if (Length)
2163 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2164 OperatorLoc, Pack, PackLoc,
2165 RParenLoc, *Length);
2166
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002167 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2168 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002169 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002170 }
2171
Douglas Gregora16548e2009-08-11 05:31:07 +00002172 /// \brief Build a new Objective-C @encode expression.
2173 ///
2174 /// By default, performs semantic analysis to build the new expression.
2175 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002176 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002177 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002178 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002179 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002180 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002181 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002182
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002183 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002184 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002185 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002186 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002187 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002188 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002189 MultiExprArg Args,
2190 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002191 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2192 ReceiverTypeInfo->getType(),
2193 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002194 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002195 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002196 }
2197
2198 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002199 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002200 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002201 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002202 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002203 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002204 MultiExprArg Args,
2205 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002206 return SemaRef.BuildInstanceMessage(Receiver,
2207 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002208 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002209 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002210 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002211 }
2212
Douglas Gregord51d90d2010-04-26 20:11:03 +00002213 /// \brief Build a new Objective-C ivar reference expression.
2214 ///
2215 /// By default, performs semantic analysis to build the new expression.
2216 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002217 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002218 SourceLocation IvarLoc,
2219 bool IsArrow, bool IsFreeIvar) {
2220 // FIXME: We lose track of the IsFreeIvar bit.
2221 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002222 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002223 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2224 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002225 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002226 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002227 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002228 false);
John Wiegley01296292011-04-08 18:41:53 +00002229 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002230 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002231
Douglas Gregord51d90d2010-04-26 20:11:03 +00002232 if (Result.get())
2233 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002234
John Wiegley01296292011-04-08 18:41:53 +00002235 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002236 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002237 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002238 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002239 /*TemplateArgs=*/0);
2240 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002241
2242 /// \brief Build a new Objective-C property reference expression.
2243 ///
2244 /// By default, performs semantic analysis to build the new expression.
2245 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002246 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002247 ObjCPropertyDecl *Property,
2248 SourceLocation PropertyLoc) {
2249 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002250 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002251 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2252 Sema::LookupMemberName);
2253 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002254 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002255 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002256 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002257 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002258 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002259
Douglas Gregor9faee212010-04-26 20:47:02 +00002260 if (Result.get())
2261 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002262
John Wiegley01296292011-04-08 18:41:53 +00002263 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002264 /*FIXME:*/PropertyLoc, IsArrow,
2265 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002266 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002267 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002268 /*TemplateArgs=*/0);
2269 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002270
John McCallb7bd14f2010-12-02 01:19:52 +00002271 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002272 ///
2273 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002274 /// Subclasses may override this routine to provide different behavior.
2275 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2276 ObjCMethodDecl *Getter,
2277 ObjCMethodDecl *Setter,
2278 SourceLocation PropertyLoc) {
2279 // Since these expressions can only be value-dependent, we do not
2280 // need to perform semantic analysis again.
2281 return Owned(
2282 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2283 VK_LValue, OK_ObjCProperty,
2284 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002285 }
2286
Douglas Gregord51d90d2010-04-26 20:11:03 +00002287 /// \brief Build a new Objective-C "isa" expression.
2288 ///
2289 /// By default, performs semantic analysis to build the new expression.
2290 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002291 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002292 bool IsArrow) {
2293 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002294 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002295 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2296 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002297 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002298 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002299 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002300 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002301 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002302
Douglas Gregord51d90d2010-04-26 20:11:03 +00002303 if (Result.get())
2304 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002305
John Wiegley01296292011-04-08 18:41:53 +00002306 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002307 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002308 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002309 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002310 /*TemplateArgs=*/0);
2311 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002312
Douglas Gregora16548e2009-08-11 05:31:07 +00002313 /// \brief Build a new shuffle vector expression.
2314 ///
2315 /// By default, performs semantic analysis to build the new expression.
2316 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002317 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002318 MultiExprArg SubExprs,
2319 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002320 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002321 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002322 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2323 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2324 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2325 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002326
Douglas Gregora16548e2009-08-11 05:31:07 +00002327 // Build a reference to the __builtin_shufflevector builtin
2328 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley01296292011-04-08 18:41:53 +00002329 ExprResult Callee
2330 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2331 VK_LValue, BuiltinLoc));
2332 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2333 if (Callee.isInvalid())
2334 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002335
2336 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002337 unsigned NumSubExprs = SubExprs.size();
2338 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley01296292011-04-08 18:41:53 +00002339 ExprResult TheCall = SemaRef.Owned(
2340 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregora16548e2009-08-11 05:31:07 +00002341 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002342 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002343 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley01296292011-04-08 18:41:53 +00002344 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002345
Douglas Gregora16548e2009-08-11 05:31:07 +00002346 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002347 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002348 }
John McCall31f82722010-11-12 08:19:04 +00002349
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002350 /// \brief Build a new template argument pack expansion.
2351 ///
2352 /// By default, performs semantic analysis to build a new pack expansion
2353 /// for a template argument. Subclasses may override this routine to provide
2354 /// different behavior.
2355 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002356 SourceLocation EllipsisLoc,
2357 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002358 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002359 case TemplateArgument::Expression: {
2360 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002361 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2362 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002363 if (Result.isInvalid())
2364 return TemplateArgumentLoc();
2365
2366 return TemplateArgumentLoc(Result.get(), Result.get());
2367 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002368
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002369 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002370 return TemplateArgumentLoc(TemplateArgument(
2371 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002372 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002373 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002374 Pattern.getTemplateNameLoc(),
2375 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002376
2377 case TemplateArgument::Null:
2378 case TemplateArgument::Integral:
2379 case TemplateArgument::Declaration:
2380 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002381 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002382 llvm_unreachable("Pack expansion pattern has no parameter packs");
2383
2384 case TemplateArgument::Type:
2385 if (TypeSourceInfo *Expansion
2386 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002387 EllipsisLoc,
2388 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002389 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2390 Expansion);
2391 break;
2392 }
2393
2394 return TemplateArgumentLoc();
2395 }
2396
Douglas Gregor968f23a2011-01-03 19:31:53 +00002397 /// \brief Build a new expression pack expansion.
2398 ///
2399 /// By default, performs semantic analysis to build a new pack expansion
2400 /// for an expression. Subclasses may override this routine to provide
2401 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002402 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2403 llvm::Optional<unsigned> NumExpansions) {
2404 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002405 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002406
2407 /// \brief Build a new atomic operation expression.
2408 ///
2409 /// By default, performs semantic analysis to build the new expression.
2410 /// Subclasses may override this routine to provide different behavior.
2411 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2412 MultiExprArg SubExprs,
2413 QualType RetTy,
2414 AtomicExpr::AtomicOp Op,
2415 SourceLocation RParenLoc) {
2416 // Just create the expression; there is not any interesting semantic
2417 // analysis here because we can't actually build an AtomicExpr until
2418 // we are sure it is semantically sound.
2419 unsigned NumSubExprs = SubExprs.size();
2420 Expr **Subs = (Expr **)SubExprs.release();
2421 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2422 NumSubExprs, RetTy, Op,
2423 RParenLoc);
2424 }
2425
John McCall31f82722010-11-12 08:19:04 +00002426private:
Douglas Gregor14454802011-02-25 02:25:35 +00002427 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2428 QualType ObjectType,
2429 NamedDecl *FirstQualifierInScope,
2430 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002431
2432 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2433 QualType ObjectType,
2434 NamedDecl *FirstQualifierInScope,
2435 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002436};
Douglas Gregora16548e2009-08-11 05:31:07 +00002437
Douglas Gregorebe10102009-08-20 07:17:43 +00002438template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002439StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002440 if (!S)
2441 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002442
Douglas Gregorebe10102009-08-20 07:17:43 +00002443 switch (S->getStmtClass()) {
2444 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002445
Douglas Gregorebe10102009-08-20 07:17:43 +00002446 // Transform individual statement nodes
2447#define STMT(Node, Parent) \
2448 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002449#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002450#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002451#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002452
Douglas Gregorebe10102009-08-20 07:17:43 +00002453 // Transform expressions by calling TransformExpr.
2454#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002455#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002456#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002457#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002458 {
John McCalldadc5752010-08-24 06:29:42 +00002459 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002460 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002461 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002462
John McCallb268a282010-08-23 23:25:46 +00002463 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002464 }
Mike Stump11289f42009-09-09 15:08:12 +00002465 }
2466
John McCallc3007a22010-10-26 07:05:15 +00002467 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002468}
Mike Stump11289f42009-09-09 15:08:12 +00002469
2470
Douglas Gregore922c772009-08-04 22:27:00 +00002471template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002472ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002473 if (!E)
2474 return SemaRef.Owned(E);
2475
2476 switch (E->getStmtClass()) {
2477 case Stmt::NoStmtClass: break;
2478#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002479#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002480#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002481 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002482#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002483 }
2484
John McCallc3007a22010-10-26 07:05:15 +00002485 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002486}
2487
2488template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002489bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2490 unsigned NumInputs,
2491 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002492 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002493 bool *ArgChanged) {
2494 for (unsigned I = 0; I != NumInputs; ++I) {
2495 // If requested, drop call arguments that need to be dropped.
2496 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2497 if (ArgChanged)
2498 *ArgChanged = true;
2499
2500 break;
2501 }
2502
Douglas Gregor968f23a2011-01-03 19:31:53 +00002503 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2504 Expr *Pattern = Expansion->getPattern();
2505
Chris Lattner01cf8db2011-07-20 06:58:45 +00002506 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002507 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2508 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2509
2510 // Determine whether the set of unexpanded parameter packs can and should
2511 // be expanded.
2512 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002513 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002514 llvm::Optional<unsigned> OrigNumExpansions
2515 = Expansion->getNumExpansions();
2516 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002517 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2518 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002519 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002520 Expand, RetainExpansion,
2521 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002522 return true;
2523
2524 if (!Expand) {
2525 // The transform has determined that we should perform a simple
2526 // transformation on the pack expansion, producing another pack
2527 // expansion.
2528 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2529 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2530 if (OutPattern.isInvalid())
2531 return true;
2532
2533 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002534 Expansion->getEllipsisLoc(),
2535 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002536 if (Out.isInvalid())
2537 return true;
2538
2539 if (ArgChanged)
2540 *ArgChanged = true;
2541 Outputs.push_back(Out.get());
2542 continue;
2543 }
John McCall542e7c62011-07-06 07:30:07 +00002544
2545 // Record right away that the argument was changed. This needs
2546 // to happen even if the array expands to nothing.
2547 if (ArgChanged) *ArgChanged = true;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002548
2549 // The transform has determined that we should perform an elementwise
2550 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002551 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002552 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2553 ExprResult Out = getDerived().TransformExpr(Pattern);
2554 if (Out.isInvalid())
2555 return true;
2556
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002557 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002558 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2559 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002560 if (Out.isInvalid())
2561 return true;
2562 }
2563
Douglas Gregor968f23a2011-01-03 19:31:53 +00002564 Outputs.push_back(Out.get());
2565 }
2566
2567 continue;
2568 }
2569
Douglas Gregora3efea12011-01-03 19:04:46 +00002570 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2571 if (Result.isInvalid())
2572 return true;
2573
2574 if (Result.get() != Inputs[I] && ArgChanged)
2575 *ArgChanged = true;
2576
2577 Outputs.push_back(Result.get());
2578 }
2579
2580 return false;
2581}
2582
2583template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002584NestedNameSpecifierLoc
2585TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2586 NestedNameSpecifierLoc NNS,
2587 QualType ObjectType,
2588 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002589 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregor14454802011-02-25 02:25:35 +00002590 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2591 Qualifier = Qualifier.getPrefix())
2592 Qualifiers.push_back(Qualifier);
2593
2594 CXXScopeSpec SS;
2595 while (!Qualifiers.empty()) {
2596 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2597 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2598
2599 switch (QNNS->getKind()) {
2600 case NestedNameSpecifier::Identifier:
2601 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2602 *QNNS->getAsIdentifier(),
2603 Q.getLocalBeginLoc(),
2604 Q.getLocalEndLoc(),
2605 ObjectType, false, SS,
2606 FirstQualifierInScope, false))
2607 return NestedNameSpecifierLoc();
2608
2609 break;
2610
2611 case NestedNameSpecifier::Namespace: {
2612 NamespaceDecl *NS
2613 = cast_or_null<NamespaceDecl>(
2614 getDerived().TransformDecl(
2615 Q.getLocalBeginLoc(),
2616 QNNS->getAsNamespace()));
2617 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2618 break;
2619 }
2620
2621 case NestedNameSpecifier::NamespaceAlias: {
2622 NamespaceAliasDecl *Alias
2623 = cast_or_null<NamespaceAliasDecl>(
2624 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2625 QNNS->getAsNamespaceAlias()));
2626 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2627 Q.getLocalEndLoc());
2628 break;
2629 }
2630
2631 case NestedNameSpecifier::Global:
2632 // There is no meaningful transformation that one could perform on the
2633 // global scope.
2634 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2635 break;
2636
2637 case NestedNameSpecifier::TypeSpecWithTemplate:
2638 case NestedNameSpecifier::TypeSpec: {
2639 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2640 FirstQualifierInScope, SS);
2641
2642 if (!TL)
2643 return NestedNameSpecifierLoc();
2644
2645 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2646 (SemaRef.getLangOptions().CPlusPlus0x &&
2647 TL.getType()->isEnumeralType())) {
2648 assert(!TL.getType().hasLocalQualifiers() &&
2649 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00002650 if (TL.getType()->isEnumeralType())
2651 SemaRef.Diag(TL.getBeginLoc(),
2652 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00002653 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2654 Q.getLocalEndLoc());
2655 break;
2656 }
Richard Trieude756fb2011-05-07 01:36:37 +00002657 // If the nested-name-specifier is an invalid type def, don't emit an
2658 // error because a previous error should have already been emitted.
2659 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2660 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2661 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2662 << TL.getType() << SS.getRange();
2663 }
Douglas Gregor14454802011-02-25 02:25:35 +00002664 return NestedNameSpecifierLoc();
2665 }
Douglas Gregore16af532011-02-28 18:50:33 +00002666 }
Douglas Gregor14454802011-02-25 02:25:35 +00002667
Douglas Gregore16af532011-02-28 18:50:33 +00002668 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002669 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002670 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002671 }
2672
2673 // Don't rebuild the nested-name-specifier if we don't have to.
2674 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2675 !getDerived().AlwaysRebuild())
2676 return NNS;
2677
2678 // If we can re-use the source-location data from the original
2679 // nested-name-specifier, do so.
2680 if (SS.location_size() == NNS.getDataLength() &&
2681 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2682 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2683
2684 // Allocate new nested-name-specifier location information.
2685 return SS.getWithLocInContext(SemaRef.Context);
2686}
2687
2688template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002689DeclarationNameInfo
2690TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002691::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002692 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002693 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002694 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002695
2696 switch (Name.getNameKind()) {
2697 case DeclarationName::Identifier:
2698 case DeclarationName::ObjCZeroArgSelector:
2699 case DeclarationName::ObjCOneArgSelector:
2700 case DeclarationName::ObjCMultiArgSelector:
2701 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002702 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002703 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002704 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002705
Douglas Gregorf816bd72009-09-03 22:13:48 +00002706 case DeclarationName::CXXConstructorName:
2707 case DeclarationName::CXXDestructorName:
2708 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002709 TypeSourceInfo *NewTInfo;
2710 CanQualType NewCanTy;
2711 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002712 NewTInfo = getDerived().TransformType(OldTInfo);
2713 if (!NewTInfo)
2714 return DeclarationNameInfo();
2715 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002716 }
2717 else {
2718 NewTInfo = 0;
2719 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002720 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002721 if (NewT.isNull())
2722 return DeclarationNameInfo();
2723 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2724 }
Mike Stump11289f42009-09-09 15:08:12 +00002725
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002726 DeclarationName NewName
2727 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2728 NewCanTy);
2729 DeclarationNameInfo NewNameInfo(NameInfo);
2730 NewNameInfo.setName(NewName);
2731 NewNameInfo.setNamedTypeInfo(NewTInfo);
2732 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002733 }
Mike Stump11289f42009-09-09 15:08:12 +00002734 }
2735
David Blaikie83d382b2011-09-23 05:06:16 +00002736 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00002737}
2738
2739template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002740TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00002741TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2742 TemplateName Name,
2743 SourceLocation NameLoc,
2744 QualType ObjectType,
2745 NamedDecl *FirstQualifierInScope) {
2746 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2747 TemplateDecl *Template = QTN->getTemplateDecl();
2748 assert(Template && "qualified template name must refer to a template");
2749
2750 TemplateDecl *TransTemplate
2751 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2752 Template));
2753 if (!TransTemplate)
2754 return TemplateName();
2755
2756 if (!getDerived().AlwaysRebuild() &&
2757 SS.getScopeRep() == QTN->getQualifier() &&
2758 TransTemplate == Template)
2759 return Name;
2760
2761 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2762 TransTemplate);
2763 }
2764
2765 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2766 if (SS.getScopeRep()) {
2767 // These apply to the scope specifier, not the template.
2768 ObjectType = QualType();
2769 FirstQualifierInScope = 0;
2770 }
2771
2772 if (!getDerived().AlwaysRebuild() &&
2773 SS.getScopeRep() == DTN->getQualifier() &&
2774 ObjectType.isNull())
2775 return Name;
2776
2777 if (DTN->isIdentifier()) {
2778 return getDerived().RebuildTemplateName(SS,
2779 *DTN->getIdentifier(),
2780 NameLoc,
2781 ObjectType,
2782 FirstQualifierInScope);
2783 }
2784
2785 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2786 ObjectType);
2787 }
2788
2789 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2790 TemplateDecl *TransTemplate
2791 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2792 Template));
2793 if (!TransTemplate)
2794 return TemplateName();
2795
2796 if (!getDerived().AlwaysRebuild() &&
2797 TransTemplate == Template)
2798 return Name;
2799
2800 return TemplateName(TransTemplate);
2801 }
2802
2803 if (SubstTemplateTemplateParmPackStorage *SubstPack
2804 = Name.getAsSubstTemplateTemplateParmPack()) {
2805 TemplateTemplateParmDecl *TransParam
2806 = cast_or_null<TemplateTemplateParmDecl>(
2807 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2808 if (!TransParam)
2809 return TemplateName();
2810
2811 if (!getDerived().AlwaysRebuild() &&
2812 TransParam == SubstPack->getParameterPack())
2813 return Name;
2814
2815 return getDerived().RebuildTemplateName(TransParam,
2816 SubstPack->getArgumentPack());
2817 }
2818
2819 // These should be getting filtered out before they reach the AST.
2820 llvm_unreachable("overloaded function decl survived to here");
2821 return TemplateName();
2822}
2823
2824template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002825void TreeTransform<Derived>::InventTemplateArgumentLoc(
2826 const TemplateArgument &Arg,
2827 TemplateArgumentLoc &Output) {
2828 SourceLocation Loc = getDerived().getBaseLocation();
2829 switch (Arg.getKind()) {
2830 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002831 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002832 break;
2833
2834 case TemplateArgument::Type:
2835 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002836 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002837
John McCall0ad16662009-10-29 08:12:44 +00002838 break;
2839
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002840 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00002841 case TemplateArgument::TemplateExpansion: {
2842 NestedNameSpecifierLocBuilder Builder;
2843 TemplateName Template = Arg.getAsTemplate();
2844 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2845 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2846 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2847 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2848
2849 if (Arg.getKind() == TemplateArgument::Template)
2850 Output = TemplateArgumentLoc(Arg,
2851 Builder.getWithLocInContext(SemaRef.Context),
2852 Loc);
2853 else
2854 Output = TemplateArgumentLoc(Arg,
2855 Builder.getWithLocInContext(SemaRef.Context),
2856 Loc, Loc);
2857
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002858 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00002859 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002860
John McCall0ad16662009-10-29 08:12:44 +00002861 case TemplateArgument::Expression:
2862 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2863 break;
2864
2865 case TemplateArgument::Declaration:
2866 case TemplateArgument::Integral:
2867 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002868 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002869 break;
2870 }
2871}
2872
2873template<typename Derived>
2874bool TreeTransform<Derived>::TransformTemplateArgument(
2875 const TemplateArgumentLoc &Input,
2876 TemplateArgumentLoc &Output) {
2877 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002878 switch (Arg.getKind()) {
2879 case TemplateArgument::Null:
2880 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002881 Output = Input;
2882 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002883
Douglas Gregore922c772009-08-04 22:27:00 +00002884 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002885 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002886 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002887 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002888
2889 DI = getDerived().TransformType(DI);
2890 if (!DI) return true;
2891
2892 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2893 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002894 }
Mike Stump11289f42009-09-09 15:08:12 +00002895
Douglas Gregore922c772009-08-04 22:27:00 +00002896 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002897 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002898 DeclarationName Name;
2899 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2900 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002901 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002902 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002903 if (!D) return true;
2904
John McCall0d07eb32009-10-29 18:45:58 +00002905 Expr *SourceExpr = Input.getSourceDeclExpression();
2906 if (SourceExpr) {
2907 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002908 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002909 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002910 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002911 }
2912
2913 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002914 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002915 }
Mike Stump11289f42009-09-09 15:08:12 +00002916
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002917 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00002918 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2919 if (QualifierLoc) {
2920 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2921 if (!QualifierLoc)
2922 return true;
2923 }
2924
Douglas Gregordf846d12011-03-02 18:46:51 +00002925 CXXScopeSpec SS;
2926 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002927 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00002928 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2929 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002930 if (Template.isNull())
2931 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002932
Douglas Gregor9d802122011-03-02 17:09:35 +00002933 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002934 Input.getTemplateNameLoc());
2935 return false;
2936 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002937
2938 case TemplateArgument::TemplateExpansion:
2939 llvm_unreachable("Caller should expand pack expansions");
2940
Douglas Gregore922c772009-08-04 22:27:00 +00002941 case TemplateArgument::Expression: {
2942 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002943 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002944 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002945
John McCall0ad16662009-10-29 08:12:44 +00002946 Expr *InputExpr = Input.getSourceExpression();
2947 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2948
Chris Lattnercdb591a2011-04-25 20:37:58 +00002949 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall0ad16662009-10-29 08:12:44 +00002950 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002951 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002952 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002953 }
Mike Stump11289f42009-09-09 15:08:12 +00002954
Douglas Gregore922c772009-08-04 22:27:00 +00002955 case TemplateArgument::Pack: {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002956 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregore922c772009-08-04 22:27:00 +00002957 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002958 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002959 AEnd = Arg.pack_end();
2960 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002961
John McCall0ad16662009-10-29 08:12:44 +00002962 // FIXME: preserve source information here when we start
2963 // caring about parameter packs.
2964
John McCall0d07eb32009-10-29 18:45:58 +00002965 TemplateArgumentLoc InputArg;
2966 TemplateArgumentLoc OutputArg;
2967 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2968 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002969 return true;
2970
John McCall0d07eb32009-10-29 18:45:58 +00002971 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002972 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002973
2974 TemplateArgument *TransformedArgsPtr
2975 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2976 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2977 TransformedArgsPtr);
2978 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2979 TransformedArgs.size()),
2980 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002981 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002982 }
2983 }
Mike Stump11289f42009-09-09 15:08:12 +00002984
Douglas Gregore922c772009-08-04 22:27:00 +00002985 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002986 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002987}
2988
Douglas Gregorfe921a72010-12-20 23:36:19 +00002989/// \brief Iterator adaptor that invents template argument location information
2990/// for each of the template arguments in its underlying iterator.
2991template<typename Derived, typename InputIterator>
2992class TemplateArgumentLocInventIterator {
2993 TreeTransform<Derived> &Self;
2994 InputIterator Iter;
2995
2996public:
2997 typedef TemplateArgumentLoc value_type;
2998 typedef TemplateArgumentLoc reference;
2999 typedef typename std::iterator_traits<InputIterator>::difference_type
3000 difference_type;
3001 typedef std::input_iterator_tag iterator_category;
3002
3003 class pointer {
3004 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003005
Douglas Gregorfe921a72010-12-20 23:36:19 +00003006 public:
3007 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3008
3009 const TemplateArgumentLoc *operator->() const { return &Arg; }
3010 };
3011
3012 TemplateArgumentLocInventIterator() { }
3013
3014 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3015 InputIterator Iter)
3016 : Self(Self), Iter(Iter) { }
3017
3018 TemplateArgumentLocInventIterator &operator++() {
3019 ++Iter;
3020 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003021 }
3022
Douglas Gregorfe921a72010-12-20 23:36:19 +00003023 TemplateArgumentLocInventIterator operator++(int) {
3024 TemplateArgumentLocInventIterator Old(*this);
3025 ++(*this);
3026 return Old;
3027 }
3028
3029 reference operator*() const {
3030 TemplateArgumentLoc Result;
3031 Self.InventTemplateArgumentLoc(*Iter, Result);
3032 return Result;
3033 }
3034
3035 pointer operator->() const { return pointer(**this); }
3036
3037 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3038 const TemplateArgumentLocInventIterator &Y) {
3039 return X.Iter == Y.Iter;
3040 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003041
Douglas Gregorfe921a72010-12-20 23:36:19 +00003042 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3043 const TemplateArgumentLocInventIterator &Y) {
3044 return X.Iter != Y.Iter;
3045 }
3046};
3047
Douglas Gregor42cafa82010-12-20 17:42:22 +00003048template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003049template<typename InputIterator>
3050bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3051 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003052 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003053 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003054 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003055 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003056
3057 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3058 // Unpack argument packs, which we translate them into separate
3059 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003060 // FIXME: We could do much better if we could guarantee that the
3061 // TemplateArgumentLocInfo for the pack expansion would be usable for
3062 // all of the template arguments in the argument pack.
3063 typedef TemplateArgumentLocInventIterator<Derived,
3064 TemplateArgument::pack_iterator>
3065 PackLocIterator;
3066 if (TransformTemplateArguments(PackLocIterator(*this,
3067 In.getArgument().pack_begin()),
3068 PackLocIterator(*this,
3069 In.getArgument().pack_end()),
3070 Outputs))
3071 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003072
3073 continue;
3074 }
3075
3076 if (In.getArgument().isPackExpansion()) {
3077 // We have a pack expansion, for which we will be substituting into
3078 // the pattern.
3079 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003080 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003081 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003082 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3083 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003084
Chris Lattner01cf8db2011-07-20 06:58:45 +00003085 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003086 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3087 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3088
3089 // Determine whether the set of unexpanded parameter packs can and should
3090 // be expanded.
3091 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003092 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003093 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003094 if (getDerived().TryExpandParameterPacks(Ellipsis,
3095 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003096 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003097 Expand,
3098 RetainExpansion,
3099 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003100 return true;
3101
3102 if (!Expand) {
3103 // The transform has determined that we should perform a simple
3104 // transformation on the pack expansion, producing another pack
3105 // expansion.
3106 TemplateArgumentLoc OutPattern;
3107 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3108 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3109 return true;
3110
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003111 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3112 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003113 if (Out.getArgument().isNull())
3114 return true;
3115
3116 Outputs.addArgument(Out);
3117 continue;
3118 }
3119
3120 // The transform has determined that we should perform an elementwise
3121 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003122 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003123 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3124
3125 if (getDerived().TransformTemplateArgument(Pattern, Out))
3126 return true;
3127
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003128 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003129 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3130 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003131 if (Out.getArgument().isNull())
3132 return true;
3133 }
3134
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003135 Outputs.addArgument(Out);
3136 }
3137
Douglas Gregor48d24112011-01-10 20:53:55 +00003138 // If we're supposed to retain a pack expansion, do so by temporarily
3139 // forgetting the partially-substituted parameter pack.
3140 if (RetainExpansion) {
3141 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3142
3143 if (getDerived().TransformTemplateArgument(Pattern, Out))
3144 return true;
3145
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003146 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3147 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003148 if (Out.getArgument().isNull())
3149 return true;
3150
3151 Outputs.addArgument(Out);
3152 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003153
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003154 continue;
3155 }
3156
3157 // The simple case:
3158 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003159 return true;
3160
3161 Outputs.addArgument(Out);
3162 }
3163
3164 return false;
3165
3166}
3167
Douglas Gregord6ff3322009-08-04 16:50:30 +00003168//===----------------------------------------------------------------------===//
3169// Type transformation
3170//===----------------------------------------------------------------------===//
3171
3172template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003173QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003174 if (getDerived().AlreadyTransformed(T))
3175 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003176
John McCall550e0c22009-10-21 00:40:46 +00003177 // Temporary workaround. All of these transformations should
3178 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003179 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3180 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003181
John McCall31f82722010-11-12 08:19:04 +00003182 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003183
John McCall550e0c22009-10-21 00:40:46 +00003184 if (!NewDI)
3185 return QualType();
3186
3187 return NewDI->getType();
3188}
3189
3190template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003191TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003192 if (getDerived().AlreadyTransformed(DI->getType()))
3193 return DI;
3194
3195 TypeLocBuilder TLB;
3196
3197 TypeLoc TL = DI->getTypeLoc();
3198 TLB.reserve(TL.getFullDataSize());
3199
John McCall31f82722010-11-12 08:19:04 +00003200 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003201 if (Result.isNull())
3202 return 0;
3203
John McCallbcd03502009-12-07 02:54:59 +00003204 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003205}
3206
3207template<typename Derived>
3208QualType
John McCall31f82722010-11-12 08:19:04 +00003209TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003210 switch (T.getTypeLocClass()) {
3211#define ABSTRACT_TYPELOC(CLASS, PARENT)
3212#define TYPELOC(CLASS, PARENT) \
3213 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003214 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003215#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003216 }
Mike Stump11289f42009-09-09 15:08:12 +00003217
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003218 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003219 return QualType();
3220}
3221
3222/// FIXME: By default, this routine adds type qualifiers only to types
3223/// that can have qualifiers, and silently suppresses those qualifiers
3224/// that are not permitted (e.g., qualifiers on reference or function
3225/// types). This is the right thing for template instantiation, but
3226/// probably not for other clients.
3227template<typename Derived>
3228QualType
3229TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003230 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003231 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003232
John McCall31f82722010-11-12 08:19:04 +00003233 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003234 if (Result.isNull())
3235 return QualType();
3236
3237 // Silently suppress qualifiers if the result type can't be qualified.
3238 // FIXME: this is the right thing for template instantiation, but
3239 // probably not for other clients.
3240 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003241 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003242
John McCall31168b02011-06-15 23:02:42 +00003243 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003244 // resulting type.
3245 if (Quals.hasObjCLifetime()) {
3246 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3247 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003248 else if (Result.getObjCLifetime()) {
Douglas Gregore46db902011-06-17 22:11:49 +00003249 // Objective-C ARC:
3250 // A lifetime qualifier applied to a substituted template parameter
3251 // overrides the lifetime qualifier from the template argument.
3252 if (const SubstTemplateTypeParmType *SubstTypeParam
3253 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3254 QualType Replacement = SubstTypeParam->getReplacementType();
3255 Qualifiers Qs = Replacement.getQualifiers();
3256 Qs.removeObjCLifetime();
3257 Replacement
3258 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3259 Qs);
3260 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3261 SubstTypeParam->getReplacedParameter(),
3262 Replacement);
3263 TLB.TypeWasModifiedSafely(Result);
3264 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003265 // Otherwise, complain about the addition of a qualifier to an
3266 // already-qualified type.
3267 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003268 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003269 << Result << R;
3270
Douglas Gregore46db902011-06-17 22:11:49 +00003271 Quals.removeObjCLifetime();
3272 }
3273 }
3274 }
John McCallcb0f89a2010-06-05 06:41:15 +00003275 if (!Quals.empty()) {
3276 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3277 TLB.push<QualifiedTypeLoc>(Result);
3278 // No location information to preserve.
3279 }
John McCall550e0c22009-10-21 00:40:46 +00003280
3281 return Result;
3282}
3283
Douglas Gregor14454802011-02-25 02:25:35 +00003284template<typename Derived>
3285TypeLoc
3286TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3287 QualType ObjectType,
3288 NamedDecl *UnqualLookup,
3289 CXXScopeSpec &SS) {
Douglas Gregor14454802011-02-25 02:25:35 +00003290 QualType T = TL.getType();
3291 if (getDerived().AlreadyTransformed(T))
3292 return TL;
3293
3294 TypeLocBuilder TLB;
3295 QualType Result;
3296
3297 if (isa<TemplateSpecializationType>(T)) {
3298 TemplateSpecializationTypeLoc SpecTL
3299 = cast<TemplateSpecializationTypeLoc>(TL);
3300
3301 TemplateName Template =
Douglas Gregor9db53502011-03-02 18:07:45 +00003302 getDerived().TransformTemplateName(SS,
3303 SpecTL.getTypePtr()->getTemplateName(),
3304 SpecTL.getTemplateNameLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003305 ObjectType, UnqualLookup);
3306 if (Template.isNull())
3307 return TypeLoc();
3308
3309 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3310 Template);
3311 } else if (isa<DependentTemplateSpecializationType>(T)) {
3312 DependentTemplateSpecializationTypeLoc SpecTL
3313 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3314
Douglas Gregor5a064722011-02-28 17:23:35 +00003315 TemplateName Template
Douglas Gregor9db53502011-03-02 18:07:45 +00003316 = getDerived().RebuildTemplateName(SS,
Douglas Gregore16af532011-02-28 18:50:33 +00003317 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003318 SpecTL.getNameLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00003319 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003320 if (Template.isNull())
3321 return TypeLoc();
3322
Douglas Gregor14454802011-02-25 02:25:35 +00003323 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003324 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003325 Template,
3326 SS);
Douglas Gregor14454802011-02-25 02:25:35 +00003327 } else {
3328 // Nothing special needs to be done for these.
3329 Result = getDerived().TransformType(TLB, TL);
3330 }
3331
3332 if (Result.isNull())
3333 return TypeLoc();
3334
3335 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3336}
3337
Douglas Gregor579c15f2011-03-02 18:32:08 +00003338template<typename Derived>
3339TypeSourceInfo *
3340TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3341 QualType ObjectType,
3342 NamedDecl *UnqualLookup,
3343 CXXScopeSpec &SS) {
3344 // FIXME: Painfully copy-paste from the above!
3345
3346 QualType T = TSInfo->getType();
3347 if (getDerived().AlreadyTransformed(T))
3348 return TSInfo;
3349
3350 TypeLocBuilder TLB;
3351 QualType Result;
3352
3353 TypeLoc TL = TSInfo->getTypeLoc();
3354 if (isa<TemplateSpecializationType>(T)) {
3355 TemplateSpecializationTypeLoc SpecTL
3356 = cast<TemplateSpecializationTypeLoc>(TL);
3357
3358 TemplateName Template
3359 = getDerived().TransformTemplateName(SS,
3360 SpecTL.getTypePtr()->getTemplateName(),
3361 SpecTL.getTemplateNameLoc(),
3362 ObjectType, UnqualLookup);
3363 if (Template.isNull())
3364 return 0;
3365
3366 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3367 Template);
3368 } else if (isa<DependentTemplateSpecializationType>(T)) {
3369 DependentTemplateSpecializationTypeLoc SpecTL
3370 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3371
3372 TemplateName Template
3373 = getDerived().RebuildTemplateName(SS,
3374 *SpecTL.getTypePtr()->getIdentifier(),
3375 SpecTL.getNameLoc(),
3376 ObjectType, UnqualLookup);
3377 if (Template.isNull())
3378 return 0;
3379
3380 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3381 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003382 Template,
3383 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003384 } else {
3385 // Nothing special needs to be done for these.
3386 Result = getDerived().TransformType(TLB, TL);
3387 }
3388
3389 if (Result.isNull())
3390 return 0;
3391
3392 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3393}
3394
John McCall550e0c22009-10-21 00:40:46 +00003395template <class TyLoc> static inline
3396QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3397 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3398 NewT.setNameLoc(T.getNameLoc());
3399 return T.getType();
3400}
3401
John McCall550e0c22009-10-21 00:40:46 +00003402template<typename Derived>
3403QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003404 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003405 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3406 NewT.setBuiltinLoc(T.getBuiltinLoc());
3407 if (T.needsExtraLocalData())
3408 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3409 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003410}
Mike Stump11289f42009-09-09 15:08:12 +00003411
Douglas Gregord6ff3322009-08-04 16:50:30 +00003412template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003413QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003414 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003415 // FIXME: recurse?
3416 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003417}
Mike Stump11289f42009-09-09 15:08:12 +00003418
Douglas Gregord6ff3322009-08-04 16:50:30 +00003419template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003420QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003421 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003422 QualType PointeeType
3423 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003424 if (PointeeType.isNull())
3425 return QualType();
3426
3427 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003428 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003429 // A dependent pointer type 'T *' has is being transformed such
3430 // that an Objective-C class type is being replaced for 'T'. The
3431 // resulting pointer type is an ObjCObjectPointerType, not a
3432 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003433 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003434
John McCall8b07ec22010-05-15 11:32:37 +00003435 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3436 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003437 return Result;
3438 }
John McCall31f82722010-11-12 08:19:04 +00003439
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003440 if (getDerived().AlwaysRebuild() ||
3441 PointeeType != TL.getPointeeLoc().getType()) {
3442 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3443 if (Result.isNull())
3444 return QualType();
3445 }
John McCall31168b02011-06-15 23:02:42 +00003446
3447 // Objective-C ARC can add lifetime qualifiers to the type that we're
3448 // pointing to.
3449 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3450
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003451 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3452 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003453 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003454}
Mike Stump11289f42009-09-09 15:08:12 +00003455
3456template<typename Derived>
3457QualType
John McCall550e0c22009-10-21 00:40:46 +00003458TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003459 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003460 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003461 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3462 if (PointeeType.isNull())
3463 return QualType();
3464
3465 QualType Result = TL.getType();
3466 if (getDerived().AlwaysRebuild() ||
3467 PointeeType != TL.getPointeeLoc().getType()) {
3468 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003469 TL.getSigilLoc());
3470 if (Result.isNull())
3471 return QualType();
3472 }
3473
Douglas Gregor049211a2010-04-22 16:50:51 +00003474 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003475 NewT.setSigilLoc(TL.getSigilLoc());
3476 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003477}
3478
John McCall70dd5f62009-10-30 00:06:24 +00003479/// Transforms a reference type. Note that somewhat paradoxically we
3480/// don't care whether the type itself is an l-value type or an r-value
3481/// type; we only care if the type was *written* as an l-value type
3482/// or an r-value type.
3483template<typename Derived>
3484QualType
3485TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003486 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003487 const ReferenceType *T = TL.getTypePtr();
3488
3489 // Note that this works with the pointee-as-written.
3490 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3491 if (PointeeType.isNull())
3492 return QualType();
3493
3494 QualType Result = TL.getType();
3495 if (getDerived().AlwaysRebuild() ||
3496 PointeeType != T->getPointeeTypeAsWritten()) {
3497 Result = getDerived().RebuildReferenceType(PointeeType,
3498 T->isSpelledAsLValue(),
3499 TL.getSigilLoc());
3500 if (Result.isNull())
3501 return QualType();
3502 }
3503
John McCall31168b02011-06-15 23:02:42 +00003504 // Objective-C ARC can add lifetime qualifiers to the type that we're
3505 // referring to.
3506 TLB.TypeWasModifiedSafely(
3507 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3508
John McCall70dd5f62009-10-30 00:06:24 +00003509 // r-value references can be rebuilt as l-value references.
3510 ReferenceTypeLoc NewTL;
3511 if (isa<LValueReferenceType>(Result))
3512 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3513 else
3514 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3515 NewTL.setSigilLoc(TL.getSigilLoc());
3516
3517 return Result;
3518}
3519
Mike Stump11289f42009-09-09 15:08:12 +00003520template<typename Derived>
3521QualType
John McCall550e0c22009-10-21 00:40:46 +00003522TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003523 LValueReferenceTypeLoc TL) {
3524 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003525}
3526
Mike Stump11289f42009-09-09 15:08:12 +00003527template<typename Derived>
3528QualType
John McCall550e0c22009-10-21 00:40:46 +00003529TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003530 RValueReferenceTypeLoc TL) {
3531 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003532}
Mike Stump11289f42009-09-09 15:08:12 +00003533
Douglas Gregord6ff3322009-08-04 16:50:30 +00003534template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003535QualType
John McCall550e0c22009-10-21 00:40:46 +00003536TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003537 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003538 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003539 if (PointeeType.isNull())
3540 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003541
Abramo Bagnara509357842011-03-05 14:42:21 +00003542 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3543 TypeSourceInfo* NewClsTInfo = 0;
3544 if (OldClsTInfo) {
3545 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3546 if (!NewClsTInfo)
3547 return QualType();
3548 }
3549
3550 const MemberPointerType *T = TL.getTypePtr();
3551 QualType OldClsType = QualType(T->getClass(), 0);
3552 QualType NewClsType;
3553 if (NewClsTInfo)
3554 NewClsType = NewClsTInfo->getType();
3555 else {
3556 NewClsType = getDerived().TransformType(OldClsType);
3557 if (NewClsType.isNull())
3558 return QualType();
3559 }
Mike Stump11289f42009-09-09 15:08:12 +00003560
John McCall550e0c22009-10-21 00:40:46 +00003561 QualType Result = TL.getType();
3562 if (getDerived().AlwaysRebuild() ||
3563 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003564 NewClsType != OldClsType) {
3565 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003566 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003567 if (Result.isNull())
3568 return QualType();
3569 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003570
John McCall550e0c22009-10-21 00:40:46 +00003571 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3572 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003573 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003574
3575 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003576}
3577
Mike Stump11289f42009-09-09 15:08:12 +00003578template<typename Derived>
3579QualType
John McCall550e0c22009-10-21 00:40:46 +00003580TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003581 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003582 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003583 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003584 if (ElementType.isNull())
3585 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003586
John McCall550e0c22009-10-21 00:40:46 +00003587 QualType Result = TL.getType();
3588 if (getDerived().AlwaysRebuild() ||
3589 ElementType != T->getElementType()) {
3590 Result = getDerived().RebuildConstantArrayType(ElementType,
3591 T->getSizeModifier(),
3592 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003593 T->getIndexTypeCVRQualifiers(),
3594 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003595 if (Result.isNull())
3596 return QualType();
3597 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003598
John McCall550e0c22009-10-21 00:40:46 +00003599 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3600 NewTL.setLBracketLoc(TL.getLBracketLoc());
3601 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003602
John McCall550e0c22009-10-21 00:40:46 +00003603 Expr *Size = TL.getSizeExpr();
3604 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003605 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003606 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3607 }
3608 NewTL.setSizeExpr(Size);
3609
3610 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003611}
Mike Stump11289f42009-09-09 15:08:12 +00003612
Douglas Gregord6ff3322009-08-04 16:50:30 +00003613template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003614QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003615 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003616 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003617 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003618 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003619 if (ElementType.isNull())
3620 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003621
John McCall550e0c22009-10-21 00:40:46 +00003622 QualType Result = TL.getType();
3623 if (getDerived().AlwaysRebuild() ||
3624 ElementType != T->getElementType()) {
3625 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003626 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003627 T->getIndexTypeCVRQualifiers(),
3628 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003629 if (Result.isNull())
3630 return QualType();
3631 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003632
John McCall550e0c22009-10-21 00:40:46 +00003633 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3634 NewTL.setLBracketLoc(TL.getLBracketLoc());
3635 NewTL.setRBracketLoc(TL.getRBracketLoc());
3636 NewTL.setSizeExpr(0);
3637
3638 return Result;
3639}
3640
3641template<typename Derived>
3642QualType
3643TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003644 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003645 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003646 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3647 if (ElementType.isNull())
3648 return QualType();
3649
3650 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003651 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003652
John McCalldadc5752010-08-24 06:29:42 +00003653 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003654 = getDerived().TransformExpr(T->getSizeExpr());
3655 if (SizeResult.isInvalid())
3656 return QualType();
3657
John McCallb268a282010-08-23 23:25:46 +00003658 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003659
3660 QualType Result = TL.getType();
3661 if (getDerived().AlwaysRebuild() ||
3662 ElementType != T->getElementType() ||
3663 Size != T->getSizeExpr()) {
3664 Result = getDerived().RebuildVariableArrayType(ElementType,
3665 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003666 Size,
John McCall550e0c22009-10-21 00:40:46 +00003667 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003668 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003669 if (Result.isNull())
3670 return QualType();
3671 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003672
John McCall550e0c22009-10-21 00:40:46 +00003673 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3674 NewTL.setLBracketLoc(TL.getLBracketLoc());
3675 NewTL.setRBracketLoc(TL.getRBracketLoc());
3676 NewTL.setSizeExpr(Size);
3677
3678 return Result;
3679}
3680
3681template<typename Derived>
3682QualType
3683TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003684 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003685 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003686 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3687 if (ElementType.isNull())
3688 return QualType();
3689
3690 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003691 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003692
John McCall33ddac02011-01-19 10:06:00 +00003693 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3694 Expr *origSize = TL.getSizeExpr();
3695 if (!origSize) origSize = T->getSizeExpr();
3696
3697 ExprResult sizeResult
3698 = getDerived().TransformExpr(origSize);
3699 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003700 return QualType();
3701
John McCall33ddac02011-01-19 10:06:00 +00003702 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003703
3704 QualType Result = TL.getType();
3705 if (getDerived().AlwaysRebuild() ||
3706 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003707 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003708 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3709 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003710 size,
John McCall550e0c22009-10-21 00:40:46 +00003711 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003712 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003713 if (Result.isNull())
3714 return QualType();
3715 }
John McCall550e0c22009-10-21 00:40:46 +00003716
3717 // We might have any sort of array type now, but fortunately they
3718 // all have the same location layout.
3719 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3720 NewTL.setLBracketLoc(TL.getLBracketLoc());
3721 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003722 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003723
3724 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003725}
Mike Stump11289f42009-09-09 15:08:12 +00003726
3727template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003728QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003729 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003730 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003731 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003732
3733 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003734 QualType ElementType = getDerived().TransformType(T->getElementType());
3735 if (ElementType.isNull())
3736 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003737
Douglas Gregore922c772009-08-04 22:27:00 +00003738 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003739 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003740
John McCalldadc5752010-08-24 06:29:42 +00003741 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003742 if (Size.isInvalid())
3743 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003744
John McCall550e0c22009-10-21 00:40:46 +00003745 QualType Result = TL.getType();
3746 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003747 ElementType != T->getElementType() ||
3748 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003749 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003750 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003751 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003752 if (Result.isNull())
3753 return QualType();
3754 }
John McCall550e0c22009-10-21 00:40:46 +00003755
3756 // Result might be dependent or not.
3757 if (isa<DependentSizedExtVectorType>(Result)) {
3758 DependentSizedExtVectorTypeLoc NewTL
3759 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3760 NewTL.setNameLoc(TL.getNameLoc());
3761 } else {
3762 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3763 NewTL.setNameLoc(TL.getNameLoc());
3764 }
3765
3766 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003767}
Mike Stump11289f42009-09-09 15:08:12 +00003768
3769template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003770QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003771 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003772 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003773 QualType ElementType = getDerived().TransformType(T->getElementType());
3774 if (ElementType.isNull())
3775 return QualType();
3776
John McCall550e0c22009-10-21 00:40:46 +00003777 QualType Result = TL.getType();
3778 if (getDerived().AlwaysRebuild() ||
3779 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003780 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003781 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003782 if (Result.isNull())
3783 return QualType();
3784 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003785
John McCall550e0c22009-10-21 00:40:46 +00003786 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3787 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003788
John McCall550e0c22009-10-21 00:40:46 +00003789 return Result;
3790}
3791
3792template<typename Derived>
3793QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003794 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003795 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003796 QualType ElementType = getDerived().TransformType(T->getElementType());
3797 if (ElementType.isNull())
3798 return QualType();
3799
3800 QualType Result = TL.getType();
3801 if (getDerived().AlwaysRebuild() ||
3802 ElementType != T->getElementType()) {
3803 Result = getDerived().RebuildExtVectorType(ElementType,
3804 T->getNumElements(),
3805 /*FIXME*/ SourceLocation());
3806 if (Result.isNull())
3807 return QualType();
3808 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003809
John McCall550e0c22009-10-21 00:40:46 +00003810 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3811 NewTL.setNameLoc(TL.getNameLoc());
3812
3813 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003814}
Mike Stump11289f42009-09-09 15:08:12 +00003815
3816template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003817ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003818TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003819 int indexAdjustment,
Douglas Gregor715e4612011-01-14 22:40:04 +00003820 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003821 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003822 TypeSourceInfo *NewDI = 0;
3823
3824 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3825 // If we're substituting into a pack expansion type and we know the
3826 TypeLoc OldTL = OldDI->getTypeLoc();
3827 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3828
3829 TypeLocBuilder TLB;
3830 TypeLoc NewTL = OldDI->getTypeLoc();
3831 TLB.reserve(NewTL.getFullDataSize());
3832
3833 QualType Result = getDerived().TransformType(TLB,
3834 OldExpansionTL.getPatternLoc());
3835 if (Result.isNull())
3836 return 0;
3837
3838 Result = RebuildPackExpansionType(Result,
3839 OldExpansionTL.getPatternLoc().getSourceRange(),
3840 OldExpansionTL.getEllipsisLoc(),
3841 NumExpansions);
3842 if (Result.isNull())
3843 return 0;
3844
3845 PackExpansionTypeLoc NewExpansionTL
3846 = TLB.push<PackExpansionTypeLoc>(Result);
3847 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3848 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3849 } else
3850 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003851 if (!NewDI)
3852 return 0;
3853
John McCall8fb0d9d2011-05-01 22:35:37 +00003854 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00003855 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00003856
3857 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3858 OldParm->getDeclContext(),
3859 OldParm->getInnerLocStart(),
3860 OldParm->getLocation(),
3861 OldParm->getIdentifier(),
3862 NewDI->getType(),
3863 NewDI,
3864 OldParm->getStorageClass(),
3865 OldParm->getStorageClassAsWritten(),
3866 /* DefArg */ NULL);
3867 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3868 OldParm->getFunctionScopeIndex() + indexAdjustment);
3869 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00003870}
3871
3872template<typename Derived>
3873bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003874 TransformFunctionTypeParams(SourceLocation Loc,
3875 ParmVarDecl **Params, unsigned NumParams,
3876 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003877 SmallVectorImpl<QualType> &OutParamTypes,
3878 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003879 int indexAdjustment = 0;
3880
Douglas Gregordd472162011-01-07 00:20:55 +00003881 for (unsigned i = 0; i != NumParams; ++i) {
3882 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003883 assert(OldParm->getFunctionScopeIndex() == i);
3884
Douglas Gregor715e4612011-01-14 22:40:04 +00003885 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003886 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00003887 if (OldParm->isParameterPack()) {
3888 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00003889 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003890
Douglas Gregor5499af42011-01-05 23:12:31 +00003891 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003892 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3893 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3894 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3895 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00003896 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3897
Douglas Gregor5499af42011-01-05 23:12:31 +00003898 // Determine whether we should expand the parameter packs.
3899 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003900 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003901 llvm::Optional<unsigned> OrigNumExpansions
3902 = ExpansionTL.getTypePtr()->getNumExpansions();
3903 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003904 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3905 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003906 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003907 ShouldExpand,
3908 RetainExpansion,
3909 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003910 return true;
3911 }
3912
3913 if (ShouldExpand) {
3914 // Expand the function parameter pack into multiple, separate
3915 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003916 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003917 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003918 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3919 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003920 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003921 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003922 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003923 if (!NewParm)
3924 return true;
3925
Douglas Gregordd472162011-01-07 00:20:55 +00003926 OutParamTypes.push_back(NewParm->getType());
3927 if (PVars)
3928 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003929 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003930
3931 // If we're supposed to retain a pack expansion, do so by temporarily
3932 // forgetting the partially-substituted parameter pack.
3933 if (RetainExpansion) {
3934 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3935 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003936 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003937 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003938 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003939 if (!NewParm)
3940 return true;
3941
3942 OutParamTypes.push_back(NewParm->getType());
3943 if (PVars)
3944 PVars->push_back(NewParm);
3945 }
3946
John McCall8fb0d9d2011-05-01 22:35:37 +00003947 // The next parameter should have the same adjustment as the
3948 // last thing we pushed, but we post-incremented indexAdjustment
3949 // on every push. Also, if we push nothing, the adjustment should
3950 // go down by one.
3951 indexAdjustment--;
3952
Douglas Gregor5499af42011-01-05 23:12:31 +00003953 // We're done with the pack expansion.
3954 continue;
3955 }
3956
3957 // We'll substitute the parameter now without expanding the pack
3958 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00003959 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3960 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003961 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003962 NumExpansions);
3963 } else {
3964 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003965 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003966 llvm::Optional<unsigned>());
Douglas Gregor5499af42011-01-05 23:12:31 +00003967 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00003968
John McCall58f10c32010-03-11 09:03:00 +00003969 if (!NewParm)
3970 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003971
Douglas Gregordd472162011-01-07 00:20:55 +00003972 OutParamTypes.push_back(NewParm->getType());
3973 if (PVars)
3974 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003975 continue;
3976 }
John McCall58f10c32010-03-11 09:03:00 +00003977
3978 // Deal with the possibility that we don't have a parameter
3979 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003980 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003981 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003982 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003983 QualType NewType;
Douglas Gregor5499af42011-01-05 23:12:31 +00003984 if (const PackExpansionType *Expansion
3985 = dyn_cast<PackExpansionType>(OldType)) {
3986 // We have a function parameter pack that may need to be expanded.
3987 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00003988 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00003989 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3990
3991 // Determine whether we should expand the parameter packs.
3992 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003993 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003994 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003995 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003996 ShouldExpand,
3997 RetainExpansion,
3998 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003999 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004000 }
4001
4002 if (ShouldExpand) {
4003 // Expand the function parameter pack into multiple, separate
4004 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004005 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004006 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4007 QualType NewType = getDerived().TransformType(Pattern);
4008 if (NewType.isNull())
4009 return true;
John McCall58f10c32010-03-11 09:03:00 +00004010
Douglas Gregordd472162011-01-07 00:20:55 +00004011 OutParamTypes.push_back(NewType);
4012 if (PVars)
4013 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00004014 }
4015
4016 // We're done with the pack expansion.
4017 continue;
4018 }
4019
Douglas Gregor48d24112011-01-10 20:53:55 +00004020 // If we're supposed to retain a pack expansion, do so by temporarily
4021 // forgetting the partially-substituted parameter pack.
4022 if (RetainExpansion) {
4023 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4024 QualType NewType = getDerived().TransformType(Pattern);
4025 if (NewType.isNull())
4026 return true;
4027
4028 OutParamTypes.push_back(NewType);
4029 if (PVars)
4030 PVars->push_back(0);
4031 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004032
Douglas Gregor5499af42011-01-05 23:12:31 +00004033 // We'll substitute the parameter now without expanding the pack
4034 // expansion.
4035 OldType = Expansion->getPattern();
4036 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004037 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4038 NewType = getDerived().TransformType(OldType);
4039 } else {
4040 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004041 }
4042
Douglas Gregor5499af42011-01-05 23:12:31 +00004043 if (NewType.isNull())
4044 return true;
4045
4046 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004047 NewType = getSema().Context.getPackExpansionType(NewType,
4048 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00004049
Douglas Gregordd472162011-01-07 00:20:55 +00004050 OutParamTypes.push_back(NewType);
4051 if (PVars)
4052 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00004053 }
4054
John McCall8fb0d9d2011-05-01 22:35:37 +00004055#ifndef NDEBUG
4056 if (PVars) {
4057 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4058 if (ParmVarDecl *parm = (*PVars)[i])
4059 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004060 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004061#endif
4062
4063 return false;
4064}
John McCall58f10c32010-03-11 09:03:00 +00004065
4066template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004067QualType
John McCall550e0c22009-10-21 00:40:46 +00004068TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004069 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004070 // Transform the parameters and return type.
4071 //
4072 // We instantiate in source order, with the return type first followed by
4073 // the parameters, because users tend to expect this (even if they shouldn't
4074 // rely on it!).
4075 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00004076 // When the function has a trailing return type, we instantiate the
4077 // parameters before the return type, since the return type can then refer
4078 // to the parameters themselves (via decltype, sizeof, etc.).
4079 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004080 SmallVector<QualType, 4> ParamTypes;
4081 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004082 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004083
Douglas Gregor7fb25412010-10-01 18:44:50 +00004084 QualType ResultType;
4085
4086 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00004087 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4088 TL.getParmArray(),
4089 TL.getNumArgs(),
4090 TL.getTypePtr()->arg_type_begin(),
4091 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004092 return QualType();
4093
4094 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4095 if (ResultType.isNull())
4096 return QualType();
4097 }
4098 else {
4099 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4100 if (ResultType.isNull())
4101 return QualType();
4102
Douglas Gregordd472162011-01-07 00:20:55 +00004103 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4104 TL.getParmArray(),
4105 TL.getNumArgs(),
4106 TL.getTypePtr()->arg_type_begin(),
4107 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004108 return QualType();
4109 }
4110
John McCall550e0c22009-10-21 00:40:46 +00004111 QualType Result = TL.getType();
4112 if (getDerived().AlwaysRebuild() ||
4113 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00004114 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00004115 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4116 Result = getDerived().RebuildFunctionProtoType(ResultType,
4117 ParamTypes.data(),
4118 ParamTypes.size(),
4119 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004120 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00004121 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004122 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00004123 if (Result.isNull())
4124 return QualType();
4125 }
Mike Stump11289f42009-09-09 15:08:12 +00004126
John McCall550e0c22009-10-21 00:40:46 +00004127 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004128 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4129 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004130 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00004131 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4132 NewTL.setArg(i, ParamDecls[i]);
4133
4134 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004135}
Mike Stump11289f42009-09-09 15:08:12 +00004136
Douglas Gregord6ff3322009-08-04 16:50:30 +00004137template<typename Derived>
4138QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004139 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004140 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004141 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004142 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4143 if (ResultType.isNull())
4144 return QualType();
4145
4146 QualType Result = TL.getType();
4147 if (getDerived().AlwaysRebuild() ||
4148 ResultType != T->getResultType())
4149 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4150
4151 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004152 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4153 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004154 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00004155
4156 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004157}
Mike Stump11289f42009-09-09 15:08:12 +00004158
John McCallb96ec562009-12-04 22:46:56 +00004159template<typename Derived> QualType
4160TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004161 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004162 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004163 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004164 if (!D)
4165 return QualType();
4166
4167 QualType Result = TL.getType();
4168 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4169 Result = getDerived().RebuildUnresolvedUsingType(D);
4170 if (Result.isNull())
4171 return QualType();
4172 }
4173
4174 // We might get an arbitrary type spec type back. We should at
4175 // least always get a type spec type, though.
4176 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4177 NewTL.setNameLoc(TL.getNameLoc());
4178
4179 return Result;
4180}
4181
Douglas Gregord6ff3322009-08-04 16:50:30 +00004182template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004183QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004184 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004185 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004186 TypedefNameDecl *Typedef
4187 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4188 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004189 if (!Typedef)
4190 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004191
John McCall550e0c22009-10-21 00:40:46 +00004192 QualType Result = TL.getType();
4193 if (getDerived().AlwaysRebuild() ||
4194 Typedef != T->getDecl()) {
4195 Result = getDerived().RebuildTypedefType(Typedef);
4196 if (Result.isNull())
4197 return QualType();
4198 }
Mike Stump11289f42009-09-09 15:08:12 +00004199
John McCall550e0c22009-10-21 00:40:46 +00004200 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4201 NewTL.setNameLoc(TL.getNameLoc());
4202
4203 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004204}
Mike Stump11289f42009-09-09 15:08:12 +00004205
Douglas Gregord6ff3322009-08-04 16:50:30 +00004206template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004207QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004208 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004209 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004210 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004211
John McCalldadc5752010-08-24 06:29:42 +00004212 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004213 if (E.isInvalid())
4214 return QualType();
4215
John McCall550e0c22009-10-21 00:40:46 +00004216 QualType Result = TL.getType();
4217 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004218 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004219 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004220 if (Result.isNull())
4221 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004222 }
John McCall550e0c22009-10-21 00:40:46 +00004223 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004224
John McCall550e0c22009-10-21 00:40:46 +00004225 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004226 NewTL.setTypeofLoc(TL.getTypeofLoc());
4227 NewTL.setLParenLoc(TL.getLParenLoc());
4228 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004229
4230 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004231}
Mike Stump11289f42009-09-09 15:08:12 +00004232
4233template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004234QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004235 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004236 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4237 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4238 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004239 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004240
John McCall550e0c22009-10-21 00:40:46 +00004241 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004242 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4243 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004244 if (Result.isNull())
4245 return QualType();
4246 }
Mike Stump11289f42009-09-09 15:08:12 +00004247
John McCall550e0c22009-10-21 00:40:46 +00004248 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004249 NewTL.setTypeofLoc(TL.getTypeofLoc());
4250 NewTL.setLParenLoc(TL.getLParenLoc());
4251 NewTL.setRParenLoc(TL.getRParenLoc());
4252 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004253
4254 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004255}
Mike Stump11289f42009-09-09 15:08:12 +00004256
4257template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004258QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004259 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004260 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004261
Douglas Gregore922c772009-08-04 22:27:00 +00004262 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004263 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004264
John McCalldadc5752010-08-24 06:29:42 +00004265 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004266 if (E.isInvalid())
4267 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004268
John McCall550e0c22009-10-21 00:40:46 +00004269 QualType Result = TL.getType();
4270 if (getDerived().AlwaysRebuild() ||
4271 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004272 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004273 if (Result.isNull())
4274 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004275 }
John McCall550e0c22009-10-21 00:40:46 +00004276 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004277
John McCall550e0c22009-10-21 00:40:46 +00004278 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4279 NewTL.setNameLoc(TL.getNameLoc());
4280
4281 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004282}
4283
4284template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004285QualType TreeTransform<Derived>::TransformUnaryTransformType(
4286 TypeLocBuilder &TLB,
4287 UnaryTransformTypeLoc TL) {
4288 QualType Result = TL.getType();
4289 if (Result->isDependentType()) {
4290 const UnaryTransformType *T = TL.getTypePtr();
4291 QualType NewBase =
4292 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4293 Result = getDerived().RebuildUnaryTransformType(NewBase,
4294 T->getUTTKind(),
4295 TL.getKWLoc());
4296 if (Result.isNull())
4297 return QualType();
4298 }
4299
4300 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4301 NewTL.setKWLoc(TL.getKWLoc());
4302 NewTL.setParensRange(TL.getParensRange());
4303 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4304 return Result;
4305}
4306
4307template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004308QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4309 AutoTypeLoc TL) {
4310 const AutoType *T = TL.getTypePtr();
4311 QualType OldDeduced = T->getDeducedType();
4312 QualType NewDeduced;
4313 if (!OldDeduced.isNull()) {
4314 NewDeduced = getDerived().TransformType(OldDeduced);
4315 if (NewDeduced.isNull())
4316 return QualType();
4317 }
4318
4319 QualType Result = TL.getType();
4320 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4321 Result = getDerived().RebuildAutoType(NewDeduced);
4322 if (Result.isNull())
4323 return QualType();
4324 }
4325
4326 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4327 NewTL.setNameLoc(TL.getNameLoc());
4328
4329 return Result;
4330}
4331
4332template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004333QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004334 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004335 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004336 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004337 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4338 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004339 if (!Record)
4340 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004341
John McCall550e0c22009-10-21 00:40:46 +00004342 QualType Result = TL.getType();
4343 if (getDerived().AlwaysRebuild() ||
4344 Record != T->getDecl()) {
4345 Result = getDerived().RebuildRecordType(Record);
4346 if (Result.isNull())
4347 return QualType();
4348 }
Mike Stump11289f42009-09-09 15:08:12 +00004349
John McCall550e0c22009-10-21 00:40:46 +00004350 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4351 NewTL.setNameLoc(TL.getNameLoc());
4352
4353 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004354}
Mike Stump11289f42009-09-09 15:08:12 +00004355
4356template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004357QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004358 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004359 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004360 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004361 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4362 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004363 if (!Enum)
4364 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004365
John McCall550e0c22009-10-21 00:40:46 +00004366 QualType Result = TL.getType();
4367 if (getDerived().AlwaysRebuild() ||
4368 Enum != T->getDecl()) {
4369 Result = getDerived().RebuildEnumType(Enum);
4370 if (Result.isNull())
4371 return QualType();
4372 }
Mike Stump11289f42009-09-09 15:08:12 +00004373
John McCall550e0c22009-10-21 00:40:46 +00004374 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4375 NewTL.setNameLoc(TL.getNameLoc());
4376
4377 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004378}
John McCallfcc33b02009-09-05 00:15:47 +00004379
John McCalle78aac42010-03-10 03:28:59 +00004380template<typename Derived>
4381QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4382 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004383 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004384 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4385 TL.getTypePtr()->getDecl());
4386 if (!D) return QualType();
4387
4388 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4389 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4390 return T;
4391}
4392
Douglas Gregord6ff3322009-08-04 16:50:30 +00004393template<typename Derived>
4394QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004395 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004396 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004397 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004398}
4399
Mike Stump11289f42009-09-09 15:08:12 +00004400template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004401QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004402 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004403 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004404 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4405
4406 // Substitute into the replacement type, which itself might involve something
4407 // that needs to be transformed. This only tends to occur with default
4408 // template arguments of template template parameters.
4409 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4410 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4411 if (Replacement.isNull())
4412 return QualType();
4413
4414 // Always canonicalize the replacement type.
4415 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4416 QualType Result
4417 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4418 Replacement);
4419
4420 // Propagate type-source information.
4421 SubstTemplateTypeParmTypeLoc NewTL
4422 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4423 NewTL.setNameLoc(TL.getNameLoc());
4424 return Result;
4425
John McCallcebee162009-10-18 09:09:24 +00004426}
4427
4428template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004429QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4430 TypeLocBuilder &TLB,
4431 SubstTemplateTypeParmPackTypeLoc TL) {
4432 return TransformTypeSpecType(TLB, TL);
4433}
4434
4435template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004436QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004437 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004438 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004439 const TemplateSpecializationType *T = TL.getTypePtr();
4440
Douglas Gregordf846d12011-03-02 18:46:51 +00004441 // The nested-name-specifier never matters in a TemplateSpecializationType,
4442 // because we can't have a dependent nested-name-specifier anyway.
4443 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004444 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004445 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4446 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004447 if (Template.isNull())
4448 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004449
John McCall31f82722010-11-12 08:19:04 +00004450 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4451}
4452
Eli Friedman0dfb8892011-10-06 23:00:33 +00004453template<typename Derived>
4454QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4455 AtomicTypeLoc TL) {
4456 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4457 if (ValueType.isNull())
4458 return QualType();
4459
4460 QualType Result = TL.getType();
4461 if (getDerived().AlwaysRebuild() ||
4462 ValueType != TL.getValueLoc().getType()) {
4463 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4464 if (Result.isNull())
4465 return QualType();
4466 }
4467
4468 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4469 NewTL.setKWLoc(TL.getKWLoc());
4470 NewTL.setLParenLoc(TL.getLParenLoc());
4471 NewTL.setRParenLoc(TL.getRParenLoc());
4472
4473 return Result;
4474}
4475
Douglas Gregorfe921a72010-12-20 23:36:19 +00004476namespace {
4477 /// \brief Simple iterator that traverses the template arguments in a
4478 /// container that provides a \c getArgLoc() member function.
4479 ///
4480 /// This iterator is intended to be used with the iterator form of
4481 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4482 template<typename ArgLocContainer>
4483 class TemplateArgumentLocContainerIterator {
4484 ArgLocContainer *Container;
4485 unsigned Index;
4486
4487 public:
4488 typedef TemplateArgumentLoc value_type;
4489 typedef TemplateArgumentLoc reference;
4490 typedef int difference_type;
4491 typedef std::input_iterator_tag iterator_category;
4492
4493 class pointer {
4494 TemplateArgumentLoc Arg;
4495
4496 public:
4497 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4498
4499 const TemplateArgumentLoc *operator->() const {
4500 return &Arg;
4501 }
4502 };
4503
4504
4505 TemplateArgumentLocContainerIterator() {}
4506
4507 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4508 unsigned Index)
4509 : Container(&Container), Index(Index) { }
4510
4511 TemplateArgumentLocContainerIterator &operator++() {
4512 ++Index;
4513 return *this;
4514 }
4515
4516 TemplateArgumentLocContainerIterator operator++(int) {
4517 TemplateArgumentLocContainerIterator Old(*this);
4518 ++(*this);
4519 return Old;
4520 }
4521
4522 TemplateArgumentLoc operator*() const {
4523 return Container->getArgLoc(Index);
4524 }
4525
4526 pointer operator->() const {
4527 return pointer(Container->getArgLoc(Index));
4528 }
4529
4530 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004531 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004532 return X.Container == Y.Container && X.Index == Y.Index;
4533 }
4534
4535 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004536 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004537 return !(X == Y);
4538 }
4539 };
4540}
4541
4542
John McCall31f82722010-11-12 08:19:04 +00004543template <typename Derived>
4544QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4545 TypeLocBuilder &TLB,
4546 TemplateSpecializationTypeLoc TL,
4547 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004548 TemplateArgumentListInfo NewTemplateArgs;
4549 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4550 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004551 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4552 ArgIterator;
4553 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4554 ArgIterator(TL, TL.getNumArgs()),
4555 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004556 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004557
John McCall0ad16662009-10-29 08:12:44 +00004558 // FIXME: maybe don't rebuild if all the template arguments are the same.
4559
4560 QualType Result =
4561 getDerived().RebuildTemplateSpecializationType(Template,
4562 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004563 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004564
4565 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004566 // Specializations of template template parameters are represented as
4567 // TemplateSpecializationTypes, and substitution of type alias templates
4568 // within a dependent context can transform them into
4569 // DependentTemplateSpecializationTypes.
4570 if (isa<DependentTemplateSpecializationType>(Result)) {
4571 DependentTemplateSpecializationTypeLoc NewTL
4572 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4573 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4574 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4575 NewTL.setNameLoc(TL.getTemplateNameLoc());
4576 NewTL.setLAngleLoc(TL.getLAngleLoc());
4577 NewTL.setRAngleLoc(TL.getRAngleLoc());
4578 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4579 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4580 return Result;
4581 }
4582
John McCall0ad16662009-10-29 08:12:44 +00004583 TemplateSpecializationTypeLoc NewTL
4584 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4585 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4586 NewTL.setLAngleLoc(TL.getLAngleLoc());
4587 NewTL.setRAngleLoc(TL.getRAngleLoc());
4588 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4589 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004590 }
Mike Stump11289f42009-09-09 15:08:12 +00004591
John McCall0ad16662009-10-29 08:12:44 +00004592 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004593}
Mike Stump11289f42009-09-09 15:08:12 +00004594
Douglas Gregor5a064722011-02-28 17:23:35 +00004595template <typename Derived>
4596QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4597 TypeLocBuilder &TLB,
4598 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004599 TemplateName Template,
4600 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004601 TemplateArgumentListInfo NewTemplateArgs;
4602 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4603 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4604 typedef TemplateArgumentLocContainerIterator<
4605 DependentTemplateSpecializationTypeLoc> ArgIterator;
4606 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4607 ArgIterator(TL, TL.getNumArgs()),
4608 NewTemplateArgs))
4609 return QualType();
4610
4611 // FIXME: maybe don't rebuild if all the template arguments are the same.
4612
4613 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4614 QualType Result
4615 = getSema().Context.getDependentTemplateSpecializationType(
4616 TL.getTypePtr()->getKeyword(),
4617 DTN->getQualifier(),
4618 DTN->getIdentifier(),
4619 NewTemplateArgs);
4620
4621 DependentTemplateSpecializationTypeLoc NewTL
4622 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4623 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004624
Douglas Gregora7a795b2011-03-01 20:11:18 +00004625 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004626 NewTL.setNameLoc(TL.getNameLoc());
4627 NewTL.setLAngleLoc(TL.getLAngleLoc());
4628 NewTL.setRAngleLoc(TL.getRAngleLoc());
4629 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4630 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4631 return Result;
4632 }
4633
4634 QualType Result
4635 = getDerived().RebuildTemplateSpecializationType(Template,
4636 TL.getNameLoc(),
4637 NewTemplateArgs);
4638
4639 if (!Result.isNull()) {
4640 /// FIXME: Wrap this in an elaborated-type-specifier?
4641 TemplateSpecializationTypeLoc NewTL
4642 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4643 NewTL.setTemplateNameLoc(TL.getNameLoc());
4644 NewTL.setLAngleLoc(TL.getLAngleLoc());
4645 NewTL.setRAngleLoc(TL.getRAngleLoc());
4646 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4647 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4648 }
4649
4650 return Result;
4651}
4652
Mike Stump11289f42009-09-09 15:08:12 +00004653template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004654QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004655TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004656 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004657 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004658
Douglas Gregor844cb502011-03-01 18:12:44 +00004659 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004660 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004661 if (TL.getQualifierLoc()) {
4662 QualifierLoc
4663 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4664 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004665 return QualType();
4666 }
Mike Stump11289f42009-09-09 15:08:12 +00004667
John McCall31f82722010-11-12 08:19:04 +00004668 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4669 if (NamedT.isNull())
4670 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004671
Richard Smith3f1b5d02011-05-05 21:57:07 +00004672 // C++0x [dcl.type.elab]p2:
4673 // If the identifier resolves to a typedef-name or the simple-template-id
4674 // resolves to an alias template specialization, the
4675 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00004676 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4677 if (const TemplateSpecializationType *TST =
4678 NamedT->getAs<TemplateSpecializationType>()) {
4679 TemplateName Template = TST->getTemplateName();
4680 if (TypeAliasTemplateDecl *TAT =
4681 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4682 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4683 diag::err_tag_reference_non_tag) << 4;
4684 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4685 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00004686 }
4687 }
4688
John McCall550e0c22009-10-21 00:40:46 +00004689 QualType Result = TL.getType();
4690 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004691 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004692 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004693 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004694 T->getKeyword(),
4695 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004696 if (Result.isNull())
4697 return QualType();
4698 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004699
Abramo Bagnara6150c882010-05-11 21:36:43 +00004700 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004701 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004702 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004703 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004704}
Mike Stump11289f42009-09-09 15:08:12 +00004705
4706template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004707QualType TreeTransform<Derived>::TransformAttributedType(
4708 TypeLocBuilder &TLB,
4709 AttributedTypeLoc TL) {
4710 const AttributedType *oldType = TL.getTypePtr();
4711 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4712 if (modifiedType.isNull())
4713 return QualType();
4714
4715 QualType result = TL.getType();
4716
4717 // FIXME: dependent operand expressions?
4718 if (getDerived().AlwaysRebuild() ||
4719 modifiedType != oldType->getModifiedType()) {
4720 // TODO: this is really lame; we should really be rebuilding the
4721 // equivalent type from first principles.
4722 QualType equivalentType
4723 = getDerived().TransformType(oldType->getEquivalentType());
4724 if (equivalentType.isNull())
4725 return QualType();
4726 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4727 modifiedType,
4728 equivalentType);
4729 }
4730
4731 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4732 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4733 if (TL.hasAttrOperand())
4734 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4735 if (TL.hasAttrExprOperand())
4736 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4737 else if (TL.hasAttrEnumOperand())
4738 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4739
4740 return result;
4741}
4742
4743template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004744QualType
4745TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4746 ParenTypeLoc TL) {
4747 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4748 if (Inner.isNull())
4749 return QualType();
4750
4751 QualType Result = TL.getType();
4752 if (getDerived().AlwaysRebuild() ||
4753 Inner != TL.getInnerLoc().getType()) {
4754 Result = getDerived().RebuildParenType(Inner);
4755 if (Result.isNull())
4756 return QualType();
4757 }
4758
4759 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4760 NewTL.setLParenLoc(TL.getLParenLoc());
4761 NewTL.setRParenLoc(TL.getRParenLoc());
4762 return Result;
4763}
4764
4765template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004766QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004767 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004768 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004769
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004770 NestedNameSpecifierLoc QualifierLoc
4771 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4772 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004773 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004774
John McCallc392f372010-06-11 00:33:02 +00004775 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004776 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004777 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004778 QualifierLoc,
4779 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004780 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004781 if (Result.isNull())
4782 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004783
Abramo Bagnarad7548482010-05-19 21:37:53 +00004784 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4785 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004786 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4787
Abramo Bagnarad7548482010-05-19 21:37:53 +00004788 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4789 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004790 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004791 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004792 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4793 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004794 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004795 NewTL.setNameLoc(TL.getNameLoc());
4796 }
John McCall550e0c22009-10-21 00:40:46 +00004797 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004798}
Mike Stump11289f42009-09-09 15:08:12 +00004799
Douglas Gregord6ff3322009-08-04 16:50:30 +00004800template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004801QualType TreeTransform<Derived>::
4802 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004803 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004804 NestedNameSpecifierLoc QualifierLoc;
4805 if (TL.getQualifierLoc()) {
4806 QualifierLoc
4807 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4808 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004809 return QualType();
4810 }
4811
John McCall31f82722010-11-12 08:19:04 +00004812 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004813 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004814}
4815
4816template<typename Derived>
4817QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00004818TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4819 DependentTemplateSpecializationTypeLoc TL,
4820 NestedNameSpecifierLoc QualifierLoc) {
4821 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4822
4823 TemplateArgumentListInfo NewTemplateArgs;
4824 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4825 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4826
4827 typedef TemplateArgumentLocContainerIterator<
4828 DependentTemplateSpecializationTypeLoc> ArgIterator;
4829 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4830 ArgIterator(TL, TL.getNumArgs()),
4831 NewTemplateArgs))
4832 return QualType();
4833
4834 QualType Result
4835 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4836 QualifierLoc,
4837 T->getIdentifier(),
4838 TL.getNameLoc(),
4839 NewTemplateArgs);
4840 if (Result.isNull())
4841 return QualType();
4842
4843 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4844 QualType NamedT = ElabT->getNamedType();
4845
4846 // Copy information relevant to the template specialization.
4847 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00004848 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004849 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004850 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4851 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004852 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004853 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004854
4855 // Copy information relevant to the elaborated type.
4856 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4857 NewTL.setKeywordLoc(TL.getKeywordLoc());
4858 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00004859 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4860 DependentTemplateSpecializationTypeLoc SpecTL
4861 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor11ddf132011-03-07 15:13:34 +00004862 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004863 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004864 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004865 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4866 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004867 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004868 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004869 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00004870 TemplateSpecializationTypeLoc SpecTL
4871 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004872 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004873 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4874 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004875 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004876 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004877 }
4878 return Result;
4879}
4880
4881template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004882QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4883 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004884 QualType Pattern
4885 = getDerived().TransformType(TLB, TL.getPatternLoc());
4886 if (Pattern.isNull())
4887 return QualType();
4888
4889 QualType Result = TL.getType();
4890 if (getDerived().AlwaysRebuild() ||
4891 Pattern != TL.getPatternLoc().getType()) {
4892 Result = getDerived().RebuildPackExpansionType(Pattern,
4893 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004894 TL.getEllipsisLoc(),
4895 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004896 if (Result.isNull())
4897 return QualType();
4898 }
4899
4900 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4901 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4902 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004903}
4904
4905template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004906QualType
4907TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004908 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004909 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004910 TLB.pushFullCopy(TL);
4911 return TL.getType();
4912}
4913
4914template<typename Derived>
4915QualType
4916TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004917 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004918 // ObjCObjectType is never dependent.
4919 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004920 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004921}
Mike Stump11289f42009-09-09 15:08:12 +00004922
4923template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004924QualType
4925TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004926 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004927 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004928 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004929 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004930}
4931
Douglas Gregord6ff3322009-08-04 16:50:30 +00004932//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004933// Statement transformation
4934//===----------------------------------------------------------------------===//
4935template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004936StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004937TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004938 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004939}
4940
4941template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004942StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004943TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4944 return getDerived().TransformCompoundStmt(S, false);
4945}
4946
4947template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004948StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004949TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004950 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004951 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004952 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004953 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004954 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4955 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004956 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004957 if (Result.isInvalid()) {
4958 // Immediately fail if this was a DeclStmt, since it's very
4959 // likely that this will cause problems for future statements.
4960 if (isa<DeclStmt>(*B))
4961 return StmtError();
4962
4963 // Otherwise, just keep processing substatements and fail later.
4964 SubStmtInvalid = true;
4965 continue;
4966 }
Mike Stump11289f42009-09-09 15:08:12 +00004967
Douglas Gregorebe10102009-08-20 07:17:43 +00004968 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4969 Statements.push_back(Result.takeAs<Stmt>());
4970 }
Mike Stump11289f42009-09-09 15:08:12 +00004971
John McCall1ababa62010-08-27 19:56:05 +00004972 if (SubStmtInvalid)
4973 return StmtError();
4974
Douglas Gregorebe10102009-08-20 07:17:43 +00004975 if (!getDerived().AlwaysRebuild() &&
4976 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004977 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004978
4979 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4980 move_arg(Statements),
4981 S->getRBracLoc(),
4982 IsStmtExpr);
4983}
Mike Stump11289f42009-09-09 15:08:12 +00004984
Douglas Gregorebe10102009-08-20 07:17:43 +00004985template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004986StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004987TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004988 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004989 {
4990 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004991 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004992
Eli Friedman06577382009-11-19 03:14:00 +00004993 // Transform the left-hand case value.
4994 LHS = getDerived().TransformExpr(S->getLHS());
4995 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004996 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004997
Eli Friedman06577382009-11-19 03:14:00 +00004998 // Transform the right-hand case value (for the GNU case-range extension).
4999 RHS = getDerived().TransformExpr(S->getRHS());
5000 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005001 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005002 }
Mike Stump11289f42009-09-09 15:08:12 +00005003
Douglas Gregorebe10102009-08-20 07:17:43 +00005004 // Build the case statement.
5005 // Case statements are always rebuilt so that they will attached to their
5006 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005007 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005008 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005009 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005010 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005011 S->getColonLoc());
5012 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005013 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005014
Douglas Gregorebe10102009-08-20 07:17:43 +00005015 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005016 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005017 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005018 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005019
Douglas Gregorebe10102009-08-20 07:17:43 +00005020 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005021 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005022}
5023
5024template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005025StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005026TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005027 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005028 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005029 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005030 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005031
Douglas Gregorebe10102009-08-20 07:17:43 +00005032 // Default statements are always rebuilt
5033 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005034 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005035}
Mike Stump11289f42009-09-09 15:08:12 +00005036
Douglas Gregorebe10102009-08-20 07:17:43 +00005037template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005038StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005039TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005040 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005041 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005042 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005043
Chris Lattnercab02a62011-02-17 20:34:02 +00005044 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5045 S->getDecl());
5046 if (!LD)
5047 return StmtError();
5048
5049
Douglas Gregorebe10102009-08-20 07:17:43 +00005050 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005051 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005052 cast<LabelDecl>(LD), SourceLocation(),
5053 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005054}
Mike Stump11289f42009-09-09 15:08:12 +00005055
Douglas Gregorebe10102009-08-20 07:17:43 +00005056template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005057StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005058TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005059 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005060 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00005061 VarDecl *ConditionVar = 0;
5062 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005063 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005064 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005065 getDerived().TransformDefinition(
5066 S->getConditionVariable()->getLocation(),
5067 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005068 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005069 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005070 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005071 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005072
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005073 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005074 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005075
5076 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005077 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005078 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5079 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005080 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005081 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005082
John McCallb268a282010-08-23 23:25:46 +00005083 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005084 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005085 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005086
John McCallb268a282010-08-23 23:25:46 +00005087 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5088 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005089 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005090
Douglas Gregorebe10102009-08-20 07:17:43 +00005091 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005092 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005093 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005094 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005095
Douglas Gregorebe10102009-08-20 07:17:43 +00005096 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005097 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005098 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005099 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005100
Douglas Gregorebe10102009-08-20 07:17:43 +00005101 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005102 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005103 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005104 Then.get() == S->getThen() &&
5105 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00005106 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005107
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005108 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005109 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005110 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005111}
5112
5113template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005114StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005115TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005116 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005117 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00005118 VarDecl *ConditionVar = 0;
5119 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005120 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005121 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005122 getDerived().TransformDefinition(
5123 S->getConditionVariable()->getLocation(),
5124 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005125 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005126 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005127 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005128 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005129
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005130 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005131 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005132 }
Mike Stump11289f42009-09-09 15:08:12 +00005133
Douglas Gregorebe10102009-08-20 07:17:43 +00005134 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005135 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005136 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005137 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005138 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005139 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005140
Douglas Gregorebe10102009-08-20 07:17:43 +00005141 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005142 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005143 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005144 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005145
Douglas Gregorebe10102009-08-20 07:17:43 +00005146 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005147 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5148 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005149}
Mike Stump11289f42009-09-09 15:08:12 +00005150
Douglas Gregorebe10102009-08-20 07:17:43 +00005151template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005152StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005153TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005154 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005155 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005156 VarDecl *ConditionVar = 0;
5157 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005158 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005159 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005160 getDerived().TransformDefinition(
5161 S->getConditionVariable()->getLocation(),
5162 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005163 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005164 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005165 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005166 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005167
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005168 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005169 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005170
5171 if (S->getCond()) {
5172 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005173 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5174 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005175 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005176 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005177 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005178 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005179 }
Mike Stump11289f42009-09-09 15:08:12 +00005180
John McCallb268a282010-08-23 23:25:46 +00005181 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5182 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005183 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005184
Douglas Gregorebe10102009-08-20 07:17:43 +00005185 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005186 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005187 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005188 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005189
Douglas Gregorebe10102009-08-20 07:17:43 +00005190 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005191 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005192 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005193 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005194 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005195
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005196 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005197 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005198}
Mike Stump11289f42009-09-09 15:08:12 +00005199
Douglas Gregorebe10102009-08-20 07:17:43 +00005200template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005201StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005202TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005203 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005204 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005205 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005206 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005207
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005208 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005209 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005210 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005211 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005212
Douglas Gregorebe10102009-08-20 07:17:43 +00005213 if (!getDerived().AlwaysRebuild() &&
5214 Cond.get() == S->getCond() &&
5215 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005216 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005217
John McCallb268a282010-08-23 23:25:46 +00005218 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5219 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005220 S->getRParenLoc());
5221}
Mike Stump11289f42009-09-09 15:08:12 +00005222
Douglas Gregorebe10102009-08-20 07:17:43 +00005223template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005224StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005225TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005226 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005227 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005228 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005229 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005230
Douglas Gregorebe10102009-08-20 07:17:43 +00005231 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005232 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005233 VarDecl *ConditionVar = 0;
5234 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005235 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005236 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005237 getDerived().TransformDefinition(
5238 S->getConditionVariable()->getLocation(),
5239 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005240 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005241 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005242 } else {
5243 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005244
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005245 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005246 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005247
5248 if (S->getCond()) {
5249 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005250 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5251 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005252 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005253 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005254
John McCallb268a282010-08-23 23:25:46 +00005255 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005256 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005257 }
Mike Stump11289f42009-09-09 15:08:12 +00005258
John McCallb268a282010-08-23 23:25:46 +00005259 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5260 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005261 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005262
Douglas Gregorebe10102009-08-20 07:17:43 +00005263 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005264 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005265 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005266 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005267
John McCallb268a282010-08-23 23:25:46 +00005268 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5269 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005270 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005271
Douglas Gregorebe10102009-08-20 07:17:43 +00005272 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005273 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005274 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005275 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005276
Douglas Gregorebe10102009-08-20 07:17:43 +00005277 if (!getDerived().AlwaysRebuild() &&
5278 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005279 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005280 Inc.get() == S->getInc() &&
5281 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005282 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005283
Douglas Gregorebe10102009-08-20 07:17:43 +00005284 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005285 Init.get(), FullCond, ConditionVar,
5286 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005287}
5288
5289template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005290StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005291TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005292 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5293 S->getLabel());
5294 if (!LD)
5295 return StmtError();
5296
Douglas Gregorebe10102009-08-20 07:17:43 +00005297 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005298 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005299 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005300}
5301
5302template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005303StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005304TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005305 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005306 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005307 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005308
Douglas Gregorebe10102009-08-20 07:17:43 +00005309 if (!getDerived().AlwaysRebuild() &&
5310 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005311 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005312
5313 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005314 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005315}
5316
5317template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005318StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005319TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005320 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005321}
Mike Stump11289f42009-09-09 15:08:12 +00005322
Douglas Gregorebe10102009-08-20 07:17:43 +00005323template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005324StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005325TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005326 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005327}
Mike Stump11289f42009-09-09 15:08:12 +00005328
Douglas Gregorebe10102009-08-20 07:17:43 +00005329template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005330StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005331TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005332 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005333 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005334 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005335
Mike Stump11289f42009-09-09 15:08:12 +00005336 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005337 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005338 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005339}
Mike Stump11289f42009-09-09 15:08:12 +00005340
Douglas Gregorebe10102009-08-20 07:17:43 +00005341template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005342StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005343TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005344 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005345 SmallVector<Decl *, 4> Decls;
Douglas Gregorebe10102009-08-20 07:17:43 +00005346 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5347 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005348 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5349 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005350 if (!Transformed)
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 if (Transformed != *D)
5354 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005355
Douglas Gregorebe10102009-08-20 07:17:43 +00005356 Decls.push_back(Transformed);
5357 }
Mike Stump11289f42009-09-09 15:08:12 +00005358
Douglas Gregorebe10102009-08-20 07:17:43 +00005359 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005360 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005361
5362 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005363 S->getStartLoc(), S->getEndLoc());
5364}
Mike Stump11289f42009-09-09 15:08:12 +00005365
Douglas Gregorebe10102009-08-20 07:17:43 +00005366template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005367StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005368TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005369
John McCall37ad5512010-08-23 06:44:23 +00005370 ASTOwningVector<Expr*> Constraints(getSema());
5371 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner01cf8db2011-07-20 06:58:45 +00005372 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005373
John McCalldadc5752010-08-24 06:29:42 +00005374 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005375 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005376
5377 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005378
Anders Carlssonaaeef072010-01-24 05:50:09 +00005379 // Go through the outputs.
5380 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005381 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005382
Anders Carlssonaaeef072010-01-24 05:50:09 +00005383 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005384 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005385
Anders Carlssonaaeef072010-01-24 05:50:09 +00005386 // Transform the output expr.
5387 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005388 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005389 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005390 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005391
Anders Carlssonaaeef072010-01-24 05:50:09 +00005392 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005393
John McCallb268a282010-08-23 23:25:46 +00005394 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005395 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005396
Anders Carlssonaaeef072010-01-24 05:50:09 +00005397 // Go through the inputs.
5398 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005399 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005400
Anders Carlssonaaeef072010-01-24 05:50:09 +00005401 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005402 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005403
Anders Carlssonaaeef072010-01-24 05:50:09 +00005404 // Transform the input expr.
5405 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005406 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005407 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005408 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005409
Anders Carlssonaaeef072010-01-24 05:50:09 +00005410 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005411
John McCallb268a282010-08-23 23:25:46 +00005412 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005413 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005414
Anders Carlssonaaeef072010-01-24 05:50:09 +00005415 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005416 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005417
5418 // Go through the clobbers.
5419 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005420 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005421
5422 // No need to transform the asm string literal.
5423 AsmString = SemaRef.Owned(S->getAsmString());
5424
5425 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5426 S->isSimple(),
5427 S->isVolatile(),
5428 S->getNumOutputs(),
5429 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005430 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005431 move_arg(Constraints),
5432 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005433 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005434 move_arg(Clobbers),
5435 S->getRParenLoc(),
5436 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005437}
5438
5439
5440template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005441StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005442TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005443 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005444 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005445 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005446 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005447
Douglas Gregor96c79492010-04-23 22:50:49 +00005448 // Transform the @catch statements (if present).
5449 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005450 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005451 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005452 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005453 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005454 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005455 if (Catch.get() != S->getCatchStmt(I))
5456 AnyCatchChanged = true;
5457 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005458 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005459
Douglas Gregor306de2f2010-04-22 23:59:56 +00005460 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005461 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005462 if (S->getFinallyStmt()) {
5463 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5464 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005465 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005466 }
5467
5468 // If nothing changed, just retain this statement.
5469 if (!getDerived().AlwaysRebuild() &&
5470 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005471 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005472 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005473 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005474
Douglas Gregor306de2f2010-04-22 23:59:56 +00005475 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005476 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5477 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005478}
Mike Stump11289f42009-09-09 15:08:12 +00005479
Douglas Gregorebe10102009-08-20 07:17:43 +00005480template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005481StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005482TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005483 // Transform the @catch parameter, if there is one.
5484 VarDecl *Var = 0;
5485 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5486 TypeSourceInfo *TSInfo = 0;
5487 if (FromVar->getTypeSourceInfo()) {
5488 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5489 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005490 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005491 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005492
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005493 QualType T;
5494 if (TSInfo)
5495 T = TSInfo->getType();
5496 else {
5497 T = getDerived().TransformType(FromVar->getType());
5498 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005499 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005500 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005501
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005502 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5503 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005504 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005505 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005506
John McCalldadc5752010-08-24 06:29:42 +00005507 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005508 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005509 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005510
5511 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005512 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005513 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005514}
Mike Stump11289f42009-09-09 15:08:12 +00005515
Douglas Gregorebe10102009-08-20 07:17:43 +00005516template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005517StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005518TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005519 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005520 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005521 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005522 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005523
Douglas Gregor306de2f2010-04-22 23:59:56 +00005524 // If nothing changed, just retain this statement.
5525 if (!getDerived().AlwaysRebuild() &&
5526 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005527 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005528
5529 // Build a new statement.
5530 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005531 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005532}
Mike Stump11289f42009-09-09 15:08:12 +00005533
Douglas Gregorebe10102009-08-20 07:17:43 +00005534template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005535StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005536TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005537 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005538 if (S->getThrowExpr()) {
5539 Operand = getDerived().TransformExpr(S->getThrowExpr());
5540 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005541 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005542 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005543
Douglas Gregor2900c162010-04-22 21:44:01 +00005544 if (!getDerived().AlwaysRebuild() &&
5545 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005546 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005547
John McCallb268a282010-08-23 23:25:46 +00005548 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005549}
Mike Stump11289f42009-09-09 15:08:12 +00005550
Douglas Gregorebe10102009-08-20 07:17:43 +00005551template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005552StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005553TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005554 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005555 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005556 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005557 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005558 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00005559 Object =
5560 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5561 Object.get());
5562 if (Object.isInvalid())
5563 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005564
Douglas Gregor6148de72010-04-22 22:01:21 +00005565 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005566 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005567 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005568 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005569
Douglas Gregor6148de72010-04-22 22:01:21 +00005570 // If nothing change, just retain the current statement.
5571 if (!getDerived().AlwaysRebuild() &&
5572 Object.get() == S->getSynchExpr() &&
5573 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005574 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005575
5576 // Build a new statement.
5577 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005578 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005579}
5580
5581template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005582StmtResult
John McCall31168b02011-06-15 23:02:42 +00005583TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5584 ObjCAutoreleasePoolStmt *S) {
5585 // Transform the body.
5586 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5587 if (Body.isInvalid())
5588 return StmtError();
5589
5590 // If nothing changed, just retain this statement.
5591 if (!getDerived().AlwaysRebuild() &&
5592 Body.get() == S->getSubStmt())
5593 return SemaRef.Owned(S);
5594
5595 // Build a new statement.
5596 return getDerived().RebuildObjCAutoreleasePoolStmt(
5597 S->getAtLoc(), Body.get());
5598}
5599
5600template<typename Derived>
5601StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005602TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005603 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005604 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005605 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005606 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005607 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005608
Douglas Gregorf68a5082010-04-22 23:10:45 +00005609 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005610 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005611 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005612 return StmtError();
John McCall53848232011-07-27 01:07:15 +00005613 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5614 Collection.take());
5615 if (Collection.isInvalid())
5616 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005617
Douglas Gregorf68a5082010-04-22 23:10:45 +00005618 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005619 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005620 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005621 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005622
Douglas Gregorf68a5082010-04-22 23:10:45 +00005623 // If nothing changed, just retain this statement.
5624 if (!getDerived().AlwaysRebuild() &&
5625 Element.get() == S->getElement() &&
5626 Collection.get() == S->getCollection() &&
5627 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005628 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005629
Douglas Gregorf68a5082010-04-22 23:10:45 +00005630 // Build a new statement.
5631 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5632 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005633 Element.get(),
5634 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005635 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005636 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005637}
5638
5639
5640template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005641StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005642TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5643 // Transform the exception declaration, if any.
5644 VarDecl *Var = 0;
5645 if (S->getExceptionDecl()) {
5646 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005647 TypeSourceInfo *T = getDerived().TransformType(
5648 ExceptionDecl->getTypeSourceInfo());
5649 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005650 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005651
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005652 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaradff19302011-03-08 08:55:46 +00005653 ExceptionDecl->getInnerLocStart(),
5654 ExceptionDecl->getLocation(),
5655 ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00005656 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005657 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005658 }
Mike Stump11289f42009-09-09 15:08:12 +00005659
Douglas Gregorebe10102009-08-20 07:17:43 +00005660 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005661 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005662 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005663 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005664
Douglas Gregorebe10102009-08-20 07:17:43 +00005665 if (!getDerived().AlwaysRebuild() &&
5666 !Var &&
5667 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005668 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005669
5670 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5671 Var,
John McCallb268a282010-08-23 23:25:46 +00005672 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005673}
Mike Stump11289f42009-09-09 15:08:12 +00005674
Douglas Gregorebe10102009-08-20 07:17:43 +00005675template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005676StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005677TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5678 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005679 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005680 = getDerived().TransformCompoundStmt(S->getTryBlock());
5681 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005682 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005683
Douglas Gregorebe10102009-08-20 07:17:43 +00005684 // Transform the handlers.
5685 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005686 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005687 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005688 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005689 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5690 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005691 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005692
Douglas Gregorebe10102009-08-20 07:17:43 +00005693 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5694 Handlers.push_back(Handler.takeAs<Stmt>());
5695 }
Mike Stump11289f42009-09-09 15:08:12 +00005696
Douglas Gregorebe10102009-08-20 07:17:43 +00005697 if (!getDerived().AlwaysRebuild() &&
5698 TryBlock.get() == S->getTryBlock() &&
5699 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005700 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005701
John McCallb268a282010-08-23 23:25:46 +00005702 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005703 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005704}
Mike Stump11289f42009-09-09 15:08:12 +00005705
Richard Smith02e85f32011-04-14 22:09:26 +00005706template<typename Derived>
5707StmtResult
5708TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5709 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5710 if (Range.isInvalid())
5711 return StmtError();
5712
5713 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5714 if (BeginEnd.isInvalid())
5715 return StmtError();
5716
5717 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5718 if (Cond.isInvalid())
5719 return StmtError();
5720
5721 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5722 if (Inc.isInvalid())
5723 return StmtError();
5724
5725 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5726 if (LoopVar.isInvalid())
5727 return StmtError();
5728
5729 StmtResult NewStmt = S;
5730 if (getDerived().AlwaysRebuild() ||
5731 Range.get() != S->getRangeStmt() ||
5732 BeginEnd.get() != S->getBeginEndStmt() ||
5733 Cond.get() != S->getCond() ||
5734 Inc.get() != S->getInc() ||
5735 LoopVar.get() != S->getLoopVarStmt())
5736 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5737 S->getColonLoc(), Range.get(),
5738 BeginEnd.get(), Cond.get(),
5739 Inc.get(), LoopVar.get(),
5740 S->getRParenLoc());
5741
5742 StmtResult Body = getDerived().TransformStmt(S->getBody());
5743 if (Body.isInvalid())
5744 return StmtError();
5745
5746 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5747 // it now so we have a new statement to attach the body to.
5748 if (Body.get() != S->getBody() && NewStmt.get() == S)
5749 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5750 S->getColonLoc(), Range.get(),
5751 BeginEnd.get(), Cond.get(),
5752 Inc.get(), LoopVar.get(),
5753 S->getRParenLoc());
5754
5755 if (NewStmt.get() == S)
5756 return SemaRef.Owned(S);
5757
5758 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5759}
5760
John Wiegley1c0675e2011-04-28 01:08:34 +00005761template<typename Derived>
5762StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00005763TreeTransform<Derived>::TransformMSDependentExistsStmt(
5764 MSDependentExistsStmt *S) {
5765 // Transform the nested-name-specifier, if any.
5766 NestedNameSpecifierLoc QualifierLoc;
5767 if (S->getQualifierLoc()) {
5768 QualifierLoc
5769 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5770 if (!QualifierLoc)
5771 return StmtError();
5772 }
5773
5774 // Transform the declaration name.
5775 DeclarationNameInfo NameInfo = S->getNameInfo();
5776 if (NameInfo.getName()) {
5777 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5778 if (!NameInfo.getName())
5779 return StmtError();
5780 }
5781
5782 // Check whether anything changed.
5783 if (!getDerived().AlwaysRebuild() &&
5784 QualifierLoc == S->getQualifierLoc() &&
5785 NameInfo.getName() == S->getNameInfo().getName())
5786 return S;
5787
5788 // Determine whether this name exists, if we can.
5789 CXXScopeSpec SS;
5790 SS.Adopt(QualifierLoc);
5791 bool Dependent = false;
5792 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5793 case Sema::IER_Exists:
5794 if (S->isIfExists())
5795 break;
5796
5797 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5798
5799 case Sema::IER_DoesNotExist:
5800 if (S->isIfNotExists())
5801 break;
5802
5803 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5804
5805 case Sema::IER_Dependent:
5806 Dependent = true;
5807 break;
5808 }
5809
5810 // We need to continue with the instantiation, so do so now.
5811 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5812 if (SubStmt.isInvalid())
5813 return StmtError();
5814
5815 // If we have resolved the name, just transform to the substatement.
5816 if (!Dependent)
5817 return SubStmt;
5818
5819 // The name is still dependent, so build a dependent expression again.
5820 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5821 S->isIfExists(),
5822 QualifierLoc,
5823 NameInfo,
5824 SubStmt.get());
5825}
5826
5827template<typename Derived>
5828StmtResult
John Wiegley1c0675e2011-04-28 01:08:34 +00005829TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5830 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5831 if(TryBlock.isInvalid()) return StmtError();
5832
5833 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5834 if(!getDerived().AlwaysRebuild() &&
5835 TryBlock.get() == S->getTryBlock() &&
5836 Handler.get() == S->getHandler())
5837 return SemaRef.Owned(S);
5838
5839 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5840 S->getTryLoc(),
5841 TryBlock.take(),
5842 Handler.take());
5843}
5844
5845template<typename Derived>
5846StmtResult
5847TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5848 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5849 if(Block.isInvalid()) return StmtError();
5850
5851 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5852 Block.take());
5853}
5854
5855template<typename Derived>
5856StmtResult
5857TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5858 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5859 if(FilterExpr.isInvalid()) return StmtError();
5860
5861 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5862 if(Block.isInvalid()) return StmtError();
5863
5864 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5865 FilterExpr.take(),
5866 Block.take());
5867}
5868
5869template<typename Derived>
5870StmtResult
5871TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5872 if(isa<SEHFinallyStmt>(Handler))
5873 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5874 else
5875 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5876}
5877
Douglas Gregorebe10102009-08-20 07:17:43 +00005878//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005879// Expression transformation
5880//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005881template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005882ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005883TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005884 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005885}
Mike Stump11289f42009-09-09 15:08:12 +00005886
5887template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005888ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005889TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005890 NestedNameSpecifierLoc QualifierLoc;
5891 if (E->getQualifierLoc()) {
5892 QualifierLoc
5893 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5894 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005895 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005896 }
John McCallce546572009-12-08 09:08:17 +00005897
5898 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005899 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5900 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005901 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005902 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005903
John McCall815039a2010-08-17 21:27:17 +00005904 DeclarationNameInfo NameInfo = E->getNameInfo();
5905 if (NameInfo.getName()) {
5906 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5907 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005908 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005909 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005910
5911 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005912 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005913 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005914 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005915 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005916
5917 // Mark it referenced in the new context regardless.
5918 // FIXME: this is a bit instantiation-specific.
5919 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5920
John McCallc3007a22010-10-26 07:05:15 +00005921 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005922 }
John McCallce546572009-12-08 09:08:17 +00005923
5924 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005925 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005926 TemplateArgs = &TransArgs;
5927 TransArgs.setLAngleLoc(E->getLAngleLoc());
5928 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005929 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5930 E->getNumTemplateArgs(),
5931 TransArgs))
5932 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005933 }
5934
Douglas Gregorea972d32011-02-28 21:54:11 +00005935 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5936 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005937}
Mike Stump11289f42009-09-09 15:08:12 +00005938
Douglas Gregora16548e2009-08-11 05:31:07 +00005939template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005940ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005941TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005942 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005943}
Mike Stump11289f42009-09-09 15:08:12 +00005944
Douglas Gregora16548e2009-08-11 05:31:07 +00005945template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005946ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005947TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005948 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005949}
Mike Stump11289f42009-09-09 15:08:12 +00005950
Douglas Gregora16548e2009-08-11 05:31:07 +00005951template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005952ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005953TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005954 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005955}
Mike Stump11289f42009-09-09 15:08:12 +00005956
Douglas Gregora16548e2009-08-11 05:31:07 +00005957template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005958ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005959TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005960 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005961}
Mike Stump11289f42009-09-09 15:08:12 +00005962
Douglas Gregora16548e2009-08-11 05:31:07 +00005963template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005964ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005965TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005966 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005967}
5968
5969template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005970ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00005971TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5972 ExprResult ControllingExpr =
5973 getDerived().TransformExpr(E->getControllingExpr());
5974 if (ControllingExpr.isInvalid())
5975 return ExprError();
5976
Chris Lattner01cf8db2011-07-20 06:58:45 +00005977 SmallVector<Expr *, 4> AssocExprs;
5978 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00005979 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5980 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5981 if (TS) {
5982 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5983 if (!AssocType)
5984 return ExprError();
5985 AssocTypes.push_back(AssocType);
5986 } else {
5987 AssocTypes.push_back(0);
5988 }
5989
5990 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5991 if (AssocExpr.isInvalid())
5992 return ExprError();
5993 AssocExprs.push_back(AssocExpr.release());
5994 }
5995
5996 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5997 E->getDefaultLoc(),
5998 E->getRParenLoc(),
5999 ControllingExpr.release(),
6000 AssocTypes.data(),
6001 AssocExprs.data(),
6002 E->getNumAssocs());
6003}
6004
6005template<typename Derived>
6006ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006007TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006008 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006009 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006010 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006011
Douglas Gregora16548e2009-08-11 05:31:07 +00006012 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006013 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006014
John McCallb268a282010-08-23 23:25:46 +00006015 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006016 E->getRParen());
6017}
6018
Mike Stump11289f42009-09-09 15:08:12 +00006019template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006020ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006021TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006022 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006023 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006024 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006025
Douglas Gregora16548e2009-08-11 05:31:07 +00006026 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006027 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006028
Douglas Gregora16548e2009-08-11 05:31:07 +00006029 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6030 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006031 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006032}
Mike Stump11289f42009-09-09 15:08:12 +00006033
Douglas Gregora16548e2009-08-11 05:31:07 +00006034template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006035ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006036TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6037 // Transform the type.
6038 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6039 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00006040 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006041
Douglas Gregor882211c2010-04-28 22:16:22 +00006042 // Transform all of the components into components similar to what the
6043 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006044 // FIXME: It would be slightly more efficient in the non-dependent case to
6045 // just map FieldDecls, rather than requiring the rebuilder to look for
6046 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006047 // template code that we don't care.
6048 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006049 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006050 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006051 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006052 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6053 const Node &ON = E->getComponent(I);
6054 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006055 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006056 Comp.LocStart = ON.getSourceRange().getBegin();
6057 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006058 switch (ON.getKind()) {
6059 case Node::Array: {
6060 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006061 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006062 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006063 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006064
Douglas Gregor882211c2010-04-28 22:16:22 +00006065 ExprChanged = ExprChanged || Index.get() != FromIndex;
6066 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006067 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006068 break;
6069 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006070
Douglas Gregor882211c2010-04-28 22:16:22 +00006071 case Node::Field:
6072 case Node::Identifier:
6073 Comp.isBrackets = false;
6074 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006075 if (!Comp.U.IdentInfo)
6076 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006077
Douglas Gregor882211c2010-04-28 22:16:22 +00006078 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006079
Douglas Gregord1702062010-04-29 00:18:15 +00006080 case Node::Base:
6081 // Will be recomputed during the rebuild.
6082 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006083 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006084
Douglas Gregor882211c2010-04-28 22:16:22 +00006085 Components.push_back(Comp);
6086 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006087
Douglas Gregor882211c2010-04-28 22:16:22 +00006088 // If nothing changed, retain the existing expression.
6089 if (!getDerived().AlwaysRebuild() &&
6090 Type == E->getTypeSourceInfo() &&
6091 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006092 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006093
Douglas Gregor882211c2010-04-28 22:16:22 +00006094 // Build a new offsetof expression.
6095 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6096 Components.data(), Components.size(),
6097 E->getRParenLoc());
6098}
6099
6100template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006101ExprResult
John McCall8d69a212010-11-15 23:31:06 +00006102TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6103 assert(getDerived().AlreadyTransformed(E->getType()) &&
6104 "opaque value expression requires transformation");
6105 return SemaRef.Owned(E);
6106}
6107
6108template<typename Derived>
6109ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00006110TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6111 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006112 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006113 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006114
John McCallbcd03502009-12-07 02:54:59 +00006115 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006116 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006117 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006118
John McCall4c98fd82009-11-04 07:28:41 +00006119 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00006120 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006121
Peter Collingbournee190dee2011-03-11 19:24:49 +00006122 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6123 E->getKind(),
6124 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006125 }
Mike Stump11289f42009-09-09 15:08:12 +00006126
John McCalldadc5752010-08-24 06:29:42 +00006127 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00006128 {
Douglas Gregora16548e2009-08-11 05:31:07 +00006129 // C++0x [expr.sizeof]p1:
6130 // The operand is either an expression, which is an unevaluated operand
6131 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00006132 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006133
Douglas Gregora16548e2009-08-11 05:31:07 +00006134 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6135 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006136 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006137
Douglas Gregora16548e2009-08-11 05:31:07 +00006138 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00006139 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006140 }
Mike Stump11289f42009-09-09 15:08:12 +00006141
Peter Collingbournee190dee2011-03-11 19:24:49 +00006142 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6143 E->getOperatorLoc(),
6144 E->getKind(),
6145 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006146}
Mike Stump11289f42009-09-09 15:08:12 +00006147
Douglas Gregora16548e2009-08-11 05:31:07 +00006148template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006149ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006150TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006151 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006152 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006153 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006154
John McCalldadc5752010-08-24 06:29:42 +00006155 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006156 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006157 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006158
6159
Douglas Gregora16548e2009-08-11 05:31:07 +00006160 if (!getDerived().AlwaysRebuild() &&
6161 LHS.get() == E->getLHS() &&
6162 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006163 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006164
John McCallb268a282010-08-23 23:25:46 +00006165 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006166 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006167 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006168 E->getRBracketLoc());
6169}
Mike Stump11289f42009-09-09 15:08:12 +00006170
6171template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006172ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006173TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006174 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006175 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006176 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006177 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006178
6179 // Transform arguments.
6180 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006181 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006182 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6183 &ArgChanged))
6184 return ExprError();
6185
Douglas Gregora16548e2009-08-11 05:31:07 +00006186 if (!getDerived().AlwaysRebuild() &&
6187 Callee.get() == E->getCallee() &&
6188 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006189 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006190
Douglas Gregora16548e2009-08-11 05:31:07 +00006191 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006192 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006193 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006194 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006195 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006196 E->getRParenLoc());
6197}
Mike Stump11289f42009-09-09 15:08:12 +00006198
6199template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006200ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006201TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006202 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006203 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006204 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006205
Douglas Gregorea972d32011-02-28 21:54:11 +00006206 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006207 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006208 QualifierLoc
6209 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6210
6211 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006212 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006213 }
Mike Stump11289f42009-09-09 15:08:12 +00006214
Eli Friedman2cfcef62009-12-04 06:40:45 +00006215 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006216 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6217 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006218 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006219 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006220
John McCall16df1e52010-03-30 21:47:33 +00006221 NamedDecl *FoundDecl = E->getFoundDecl();
6222 if (FoundDecl == E->getMemberDecl()) {
6223 FoundDecl = Member;
6224 } else {
6225 FoundDecl = cast_or_null<NamedDecl>(
6226 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6227 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006228 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006229 }
6230
Douglas Gregora16548e2009-08-11 05:31:07 +00006231 if (!getDerived().AlwaysRebuild() &&
6232 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006233 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006234 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006235 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006236 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006237
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006238 // Mark it referenced in the new context regardless.
6239 // FIXME: this is a bit instantiation-specific.
6240 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00006241 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006242 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006243
John McCall6b51f282009-11-23 01:53:49 +00006244 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006245 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006246 TransArgs.setLAngleLoc(E->getLAngleLoc());
6247 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006248 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6249 E->getNumTemplateArgs(),
6250 TransArgs))
6251 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006252 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006253
Douglas Gregora16548e2009-08-11 05:31:07 +00006254 // FIXME: Bogus source location for the operator
6255 SourceLocation FakeOperatorLoc
6256 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6257
John McCall38836f02010-01-15 08:34:02 +00006258 // FIXME: to do this check properly, we will need to preserve the
6259 // first-qualifier-in-scope here, just in case we had a dependent
6260 // base (and therefore couldn't do the check) and a
6261 // nested-name-qualifier (and therefore could do the lookup).
6262 NamedDecl *FirstQualifierInScope = 0;
6263
John McCallb268a282010-08-23 23:25:46 +00006264 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006265 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006266 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006267 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006268 Member,
John McCall16df1e52010-03-30 21:47:33 +00006269 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006270 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006271 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006272 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006273}
Mike Stump11289f42009-09-09 15:08:12 +00006274
Douglas Gregora16548e2009-08-11 05:31:07 +00006275template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006276ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006277TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006278 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006279 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006280 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006281
John McCalldadc5752010-08-24 06:29:42 +00006282 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006283 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006284 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006285
Douglas Gregora16548e2009-08-11 05:31:07 +00006286 if (!getDerived().AlwaysRebuild() &&
6287 LHS.get() == E->getLHS() &&
6288 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006289 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006290
Douglas Gregora16548e2009-08-11 05:31:07 +00006291 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006292 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006293}
6294
Mike Stump11289f42009-09-09 15:08:12 +00006295template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006296ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006297TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006298 CompoundAssignOperator *E) {
6299 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006300}
Mike Stump11289f42009-09-09 15:08:12 +00006301
Douglas Gregora16548e2009-08-11 05:31:07 +00006302template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006303ExprResult TreeTransform<Derived>::
6304TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6305 // Just rebuild the common and RHS expressions and see whether we
6306 // get any changes.
6307
6308 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6309 if (commonExpr.isInvalid())
6310 return ExprError();
6311
6312 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6313 if (rhs.isInvalid())
6314 return ExprError();
6315
6316 if (!getDerived().AlwaysRebuild() &&
6317 commonExpr.get() == e->getCommon() &&
6318 rhs.get() == e->getFalseExpr())
6319 return SemaRef.Owned(e);
6320
6321 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6322 e->getQuestionLoc(),
6323 0,
6324 e->getColonLoc(),
6325 rhs.get());
6326}
6327
6328template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006329ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006330TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006331 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006332 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006333 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006334
John McCalldadc5752010-08-24 06:29:42 +00006335 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006336 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006337 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006338
John McCalldadc5752010-08-24 06:29:42 +00006339 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006340 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006341 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006342
Douglas Gregora16548e2009-08-11 05:31:07 +00006343 if (!getDerived().AlwaysRebuild() &&
6344 Cond.get() == E->getCond() &&
6345 LHS.get() == E->getLHS() &&
6346 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006347 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006348
John McCallb268a282010-08-23 23:25:46 +00006349 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006350 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006351 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006352 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006353 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006354}
Mike Stump11289f42009-09-09 15:08:12 +00006355
6356template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006357ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006358TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006359 // Implicit casts are eliminated during transformation, since they
6360 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006361 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006362}
Mike Stump11289f42009-09-09 15:08:12 +00006363
Douglas Gregora16548e2009-08-11 05:31:07 +00006364template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006365ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006366TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006367 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6368 if (!Type)
6369 return ExprError();
6370
John McCalldadc5752010-08-24 06:29:42 +00006371 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006372 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006373 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006374 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006375
Douglas Gregora16548e2009-08-11 05:31:07 +00006376 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006377 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006378 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006379 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006380
John McCall97513962010-01-15 18:39:57 +00006381 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006382 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006383 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006384 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006385}
Mike Stump11289f42009-09-09 15:08:12 +00006386
Douglas Gregora16548e2009-08-11 05:31:07 +00006387template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006388ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006389TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006390 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6391 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6392 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006393 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006394
John McCalldadc5752010-08-24 06:29:42 +00006395 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006396 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006397 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006398
Douglas Gregora16548e2009-08-11 05:31:07 +00006399 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006400 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006401 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00006402 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006403
John McCall5d7aa7f2010-01-19 22:33:45 +00006404 // Note: the expression type doesn't necessarily match the
6405 // type-as-written, but that's okay, because it should always be
6406 // derivable from the initializer.
6407
John McCalle15bbff2010-01-18 19:35:47 +00006408 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006409 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006410 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006411}
Mike Stump11289f42009-09-09 15:08:12 +00006412
Douglas Gregora16548e2009-08-11 05:31:07 +00006413template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006414ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006415TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006416 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006417 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006418 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006419
Douglas Gregora16548e2009-08-11 05:31:07 +00006420 if (!getDerived().AlwaysRebuild() &&
6421 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006422 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006423
Douglas Gregora16548e2009-08-11 05:31:07 +00006424 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00006425 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006426 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00006427 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006428 E->getAccessorLoc(),
6429 E->getAccessor());
6430}
Mike Stump11289f42009-09-09 15:08:12 +00006431
Douglas Gregora16548e2009-08-11 05:31:07 +00006432template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006433ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006434TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006435 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00006436
John McCall37ad5512010-08-23 06:44:23 +00006437 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006438 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6439 Inits, &InitChanged))
6440 return ExprError();
6441
Douglas Gregora16548e2009-08-11 05:31:07 +00006442 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00006443 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006444
Douglas Gregora16548e2009-08-11 05:31:07 +00006445 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00006446 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00006447}
Mike Stump11289f42009-09-09 15:08:12 +00006448
Douglas Gregora16548e2009-08-11 05:31:07 +00006449template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006450ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006451TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006452 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00006453
Douglas Gregorebe10102009-08-20 07:17:43 +00006454 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00006455 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006456 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006457 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006458
Douglas Gregorebe10102009-08-20 07:17:43 +00006459 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00006460 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006461 bool ExprChanged = false;
6462 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6463 DEnd = E->designators_end();
6464 D != DEnd; ++D) {
6465 if (D->isFieldDesignator()) {
6466 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6467 D->getDotLoc(),
6468 D->getFieldLoc()));
6469 continue;
6470 }
Mike Stump11289f42009-09-09 15:08:12 +00006471
Douglas Gregora16548e2009-08-11 05:31:07 +00006472 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00006473 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006474 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006475 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006476
6477 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006478 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006479
Douglas Gregora16548e2009-08-11 05:31:07 +00006480 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6481 ArrayExprs.push_back(Index.release());
6482 continue;
6483 }
Mike Stump11289f42009-09-09 15:08:12 +00006484
Douglas Gregora16548e2009-08-11 05:31:07 +00006485 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00006486 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00006487 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6488 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006489 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006490
John McCalldadc5752010-08-24 06:29:42 +00006491 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006492 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006493 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006494
6495 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006496 End.get(),
6497 D->getLBracketLoc(),
6498 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006499
Douglas Gregora16548e2009-08-11 05:31:07 +00006500 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6501 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00006502
Douglas Gregora16548e2009-08-11 05:31:07 +00006503 ArrayExprs.push_back(Start.release());
6504 ArrayExprs.push_back(End.release());
6505 }
Mike Stump11289f42009-09-09 15:08:12 +00006506
Douglas Gregora16548e2009-08-11 05:31:07 +00006507 if (!getDerived().AlwaysRebuild() &&
6508 Init.get() == E->getInit() &&
6509 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006510 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006511
Douglas Gregora16548e2009-08-11 05:31:07 +00006512 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6513 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006514 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006515}
Mike Stump11289f42009-09-09 15:08:12 +00006516
Douglas Gregora16548e2009-08-11 05:31:07 +00006517template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006518ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006519TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006520 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00006521 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006522
Douglas Gregor3da3c062009-10-28 00:29:27 +00006523 // FIXME: Will we ever have proper type location here? Will we actually
6524 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00006525 QualType T = getDerived().TransformType(E->getType());
6526 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006527 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006528
Douglas Gregora16548e2009-08-11 05:31:07 +00006529 if (!getDerived().AlwaysRebuild() &&
6530 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006531 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006532
Douglas Gregora16548e2009-08-11 05:31:07 +00006533 return getDerived().RebuildImplicitValueInitExpr(T);
6534}
Mike Stump11289f42009-09-09 15:08:12 +00006535
Douglas Gregora16548e2009-08-11 05:31:07 +00006536template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006537ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006538TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00006539 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6540 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006541 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006542
John McCalldadc5752010-08-24 06:29:42 +00006543 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006544 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006545 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006546
Douglas Gregora16548e2009-08-11 05:31:07 +00006547 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00006548 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006549 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006550 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006551
John McCallb268a282010-08-23 23:25:46 +00006552 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00006553 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006554}
6555
6556template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006557ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006558TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006559 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006560 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006561 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6562 &ArgumentChanged))
6563 return ExprError();
6564
Douglas Gregora16548e2009-08-11 05:31:07 +00006565 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6566 move_arg(Inits),
6567 E->getRParenLoc());
6568}
Mike Stump11289f42009-09-09 15:08:12 +00006569
Douglas Gregora16548e2009-08-11 05:31:07 +00006570/// \brief Transform an address-of-label expression.
6571///
6572/// By default, the transformation of an address-of-label expression always
6573/// rebuilds the expression, so that the label identifier can be resolved to
6574/// the corresponding label statement by semantic analysis.
6575template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006576ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006577TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006578 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6579 E->getLabel());
6580 if (!LD)
6581 return ExprError();
6582
Douglas Gregora16548e2009-08-11 05:31:07 +00006583 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006584 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006585}
Mike Stump11289f42009-09-09 15:08:12 +00006586
6587template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006588ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006589TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006590 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006591 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6592 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006593 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006594
Douglas Gregora16548e2009-08-11 05:31:07 +00006595 if (!getDerived().AlwaysRebuild() &&
6596 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006597 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006598
6599 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006600 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006601 E->getRParenLoc());
6602}
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
John McCall47f29ea2009-12-08 09:21:05 +00006606TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006607 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006608 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006609 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006610
John McCalldadc5752010-08-24 06:29:42 +00006611 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006612 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006613 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006614
John McCalldadc5752010-08-24 06:29:42 +00006615 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006616 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006617 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006618
Douglas Gregora16548e2009-08-11 05:31:07 +00006619 if (!getDerived().AlwaysRebuild() &&
6620 Cond.get() == E->getCond() &&
6621 LHS.get() == E->getLHS() &&
6622 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006623 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006624
Douglas Gregora16548e2009-08-11 05:31:07 +00006625 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006626 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006627 E->getRParenLoc());
6628}
Mike Stump11289f42009-09-09 15:08:12 +00006629
Douglas Gregora16548e2009-08-11 05:31:07 +00006630template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006631ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006632TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006633 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006634}
6635
6636template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006637ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006638TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006639 switch (E->getOperator()) {
6640 case OO_New:
6641 case OO_Delete:
6642 case OO_Array_New:
6643 case OO_Array_Delete:
6644 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006645 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006646
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006647 case OO_Call: {
6648 // This is a call to an object's operator().
6649 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6650
6651 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006652 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006653 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006654 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006655
6656 // FIXME: Poor location information
6657 SourceLocation FakeLParenLoc
6658 = SemaRef.PP.getLocForEndOfToken(
6659 static_cast<Expr *>(Object.get())->getLocEnd());
6660
6661 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006662 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006663 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6664 Args))
6665 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006666
John McCallb268a282010-08-23 23:25:46 +00006667 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006668 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006669 E->getLocEnd());
6670 }
6671
6672#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6673 case OO_##Name:
6674#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6675#include "clang/Basic/OperatorKinds.def"
6676 case OO_Subscript:
6677 // Handled below.
6678 break;
6679
6680 case OO_Conditional:
6681 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006682 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006683
6684 case OO_None:
6685 case NUM_OVERLOADED_OPERATORS:
6686 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006687 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006688 }
6689
John McCalldadc5752010-08-24 06:29:42 +00006690 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006691 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006692 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006693
John McCalldadc5752010-08-24 06:29:42 +00006694 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006695 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006696 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006697
John McCalldadc5752010-08-24 06:29:42 +00006698 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006699 if (E->getNumArgs() == 2) {
6700 Second = getDerived().TransformExpr(E->getArg(1));
6701 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006702 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006703 }
Mike Stump11289f42009-09-09 15:08:12 +00006704
Douglas Gregora16548e2009-08-11 05:31:07 +00006705 if (!getDerived().AlwaysRebuild() &&
6706 Callee.get() == E->getCallee() &&
6707 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006708 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006709 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006710
Douglas Gregora16548e2009-08-11 05:31:07 +00006711 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6712 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006713 Callee.get(),
6714 First.get(),
6715 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006716}
Mike Stump11289f42009-09-09 15:08:12 +00006717
Douglas Gregora16548e2009-08-11 05:31:07 +00006718template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006719ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006720TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6721 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006722}
Mike Stump11289f42009-09-09 15:08:12 +00006723
Douglas Gregora16548e2009-08-11 05:31:07 +00006724template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006725ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006726TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6727 // Transform the callee.
6728 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6729 if (Callee.isInvalid())
6730 return ExprError();
6731
6732 // Transform exec config.
6733 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6734 if (EC.isInvalid())
6735 return ExprError();
6736
6737 // Transform arguments.
6738 bool ArgChanged = false;
6739 ASTOwningVector<Expr*> Args(SemaRef);
6740 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6741 &ArgChanged))
6742 return ExprError();
6743
6744 if (!getDerived().AlwaysRebuild() &&
6745 Callee.get() == E->getCallee() &&
6746 !ArgChanged)
6747 return SemaRef.Owned(E);
6748
6749 // FIXME: Wrong source location information for the '('.
6750 SourceLocation FakeLParenLoc
6751 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6752 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6753 move_arg(Args),
6754 E->getRParenLoc(), EC.get());
6755}
6756
6757template<typename Derived>
6758ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006759TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006760 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6761 if (!Type)
6762 return ExprError();
6763
John McCalldadc5752010-08-24 06:29:42 +00006764 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006765 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006766 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006767 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006768
Douglas Gregora16548e2009-08-11 05:31:07 +00006769 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006770 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006771 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006772 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006773
Douglas Gregora16548e2009-08-11 05:31:07 +00006774 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006775 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006776 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6777 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6778 SourceLocation FakeRParenLoc
6779 = SemaRef.PP.getLocForEndOfToken(
6780 E->getSubExpr()->getSourceRange().getEnd());
6781 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006782 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006783 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006784 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006785 FakeRAngleLoc,
6786 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006787 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006788 FakeRParenLoc);
6789}
Mike Stump11289f42009-09-09 15:08:12 +00006790
Douglas Gregora16548e2009-08-11 05:31:07 +00006791template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006792ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006793TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6794 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006795}
Mike Stump11289f42009-09-09 15:08:12 +00006796
6797template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006798ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006799TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6800 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006801}
6802
Douglas Gregora16548e2009-08-11 05:31:07 +00006803template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006804ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006805TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006806 CXXReinterpretCastExpr *E) {
6807 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006808}
Mike Stump11289f42009-09-09 15:08:12 +00006809
Douglas Gregora16548e2009-08-11 05:31:07 +00006810template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006811ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006812TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6813 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006814}
Mike Stump11289f42009-09-09 15:08:12 +00006815
Douglas Gregora16548e2009-08-11 05:31:07 +00006816template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006817ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006818TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006819 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006820 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6821 if (!Type)
6822 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006823
John McCalldadc5752010-08-24 06:29:42 +00006824 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006825 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006826 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006827 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006828
Douglas Gregora16548e2009-08-11 05:31:07 +00006829 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006830 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006831 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006832 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006833
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006834 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006835 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006836 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006837 E->getRParenLoc());
6838}
Mike Stump11289f42009-09-09 15:08:12 +00006839
Douglas Gregora16548e2009-08-11 05:31:07 +00006840template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006841ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006842TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006843 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006844 TypeSourceInfo *TInfo
6845 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6846 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006847 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006848
Douglas Gregora16548e2009-08-11 05:31:07 +00006849 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006850 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006851 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006852
Douglas Gregor9da64192010-04-26 22:37:10 +00006853 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6854 E->getLocStart(),
6855 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006856 E->getLocEnd());
6857 }
Mike Stump11289f42009-09-09 15:08:12 +00006858
Douglas Gregora16548e2009-08-11 05:31:07 +00006859 // We don't know whether the expression is potentially evaluated until
6860 // after we perform semantic analysis, so the expression is potentially
6861 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006862 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006863 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006864
John McCalldadc5752010-08-24 06:29:42 +00006865 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006866 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006867 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006868
Douglas Gregora16548e2009-08-11 05:31:07 +00006869 if (!getDerived().AlwaysRebuild() &&
6870 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006871 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006872
Douglas Gregor9da64192010-04-26 22:37:10 +00006873 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6874 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006875 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006876 E->getLocEnd());
6877}
6878
6879template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006880ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006881TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6882 if (E->isTypeOperand()) {
6883 TypeSourceInfo *TInfo
6884 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6885 if (!TInfo)
6886 return ExprError();
6887
6888 if (!getDerived().AlwaysRebuild() &&
6889 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006890 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006891
Douglas Gregor69735112011-03-06 17:40:41 +00006892 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00006893 E->getLocStart(),
6894 TInfo,
6895 E->getLocEnd());
6896 }
6897
6898 // We don't know whether the expression is potentially evaluated until
6899 // after we perform semantic analysis, so the expression is potentially
6900 // potentially evaluated.
6901 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6902
6903 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6904 if (SubExpr.isInvalid())
6905 return ExprError();
6906
6907 if (!getDerived().AlwaysRebuild() &&
6908 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006909 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006910
6911 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6912 E->getLocStart(),
6913 SubExpr.get(),
6914 E->getLocEnd());
6915}
6916
6917template<typename Derived>
6918ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006919TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006920 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006921}
Mike Stump11289f42009-09-09 15:08:12 +00006922
Douglas Gregora16548e2009-08-11 05:31:07 +00006923template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006924ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006925TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006926 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006927 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006928}
Mike Stump11289f42009-09-09 15:08:12 +00006929
Douglas Gregora16548e2009-08-11 05:31:07 +00006930template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006931ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006932TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006933 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith938f40b2011-06-11 17:19:42 +00006934 QualType T;
6935 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
6936 T = MD->getThisType(getSema().Context);
6937 else
6938 T = getSema().Context.getPointerType(
6939 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump11289f42009-09-09 15:08:12 +00006940
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006941 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006942 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006943
Douglas Gregorb15af892010-01-07 23:12:05 +00006944 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006945}
Mike Stump11289f42009-09-09 15:08:12 +00006946
Douglas Gregora16548e2009-08-11 05:31:07 +00006947template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006948ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006949TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006950 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006951 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006952 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006953
Douglas Gregora16548e2009-08-11 05:31:07 +00006954 if (!getDerived().AlwaysRebuild() &&
6955 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006956 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006957
Douglas Gregor53e191ed2011-07-06 22:04:06 +00006958 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
6959 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00006960}
Mike Stump11289f42009-09-09 15:08:12 +00006961
Douglas Gregora16548e2009-08-11 05:31:07 +00006962template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006963ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006964TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006965 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006966 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6967 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006968 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006969 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006970
Chandler Carruth794da4c2010-02-08 06:42:49 +00006971 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006972 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006973 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006974
Douglas Gregor033f6752009-12-23 23:03:06 +00006975 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006976}
Mike Stump11289f42009-09-09 15:08:12 +00006977
Douglas Gregora16548e2009-08-11 05:31:07 +00006978template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006979ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006980TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6981 CXXScalarValueInitExpr *E) {
6982 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6983 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006984 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006985
Douglas Gregora16548e2009-08-11 05:31:07 +00006986 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006987 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006988 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006989
Douglas Gregor2b88c112010-09-08 00:15:04 +00006990 return getDerived().RebuildCXXScalarValueInitExpr(T,
6991 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006992 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006993}
Mike Stump11289f42009-09-09 15:08:12 +00006994
Douglas Gregora16548e2009-08-11 05:31:07 +00006995template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006996ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006997TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006998 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006999 TypeSourceInfo *AllocTypeInfo
7000 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7001 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007002 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007003
Douglas Gregora16548e2009-08-11 05:31:07 +00007004 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007005 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007006 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007007 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007008
Douglas Gregora16548e2009-08-11 05:31:07 +00007009 // Transform the placement arguments (if any).
7010 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007011 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007012 if (getDerived().TransformExprs(E->getPlacementArgs(),
7013 E->getNumPlacementArgs(), true,
7014 PlacementArgs, &ArgumentChanged))
7015 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007016
Douglas Gregorf333f8c2011-10-18 02:43:19 +00007017 // Transform the constructor arguments (if any).
7018 // As an annoying corner case, we may have introduced an implicit value-
7019 // initialization expression when allocating a new array, which we implicitly
7020 // drop. It will be re-created during type checking.
John McCall37ad5512010-08-23 06:44:23 +00007021 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregorf333f8c2011-10-18 02:43:19 +00007022 if (!(E->isArray() && E->getNumConstructorArgs() == 1 &&
7023 isa<ImplicitValueInitExpr>(E->getConstructorArgs()[0])) &&
7024 TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007025 ConstructorArgs, &ArgumentChanged))
7026 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007027
Douglas Gregord2d9da02010-02-26 00:38:10 +00007028 // Transform constructor, new operator, and delete operator.
7029 CXXConstructorDecl *Constructor = 0;
7030 if (E->getConstructor()) {
7031 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007032 getDerived().TransformDecl(E->getLocStart(),
7033 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007034 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007035 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007036 }
7037
7038 FunctionDecl *OperatorNew = 0;
7039 if (E->getOperatorNew()) {
7040 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007041 getDerived().TransformDecl(E->getLocStart(),
7042 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007043 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007044 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007045 }
7046
7047 FunctionDecl *OperatorDelete = 0;
7048 if (E->getOperatorDelete()) {
7049 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007050 getDerived().TransformDecl(E->getLocStart(),
7051 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007052 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007053 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007054 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007055
Douglas Gregora16548e2009-08-11 05:31:07 +00007056 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00007057 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007058 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007059 Constructor == E->getConstructor() &&
7060 OperatorNew == E->getOperatorNew() &&
7061 OperatorDelete == E->getOperatorDelete() &&
7062 !ArgumentChanged) {
7063 // Mark any declarations we need as referenced.
7064 // FIXME: instantiation-specific.
7065 if (Constructor)
7066 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
7067 if (OperatorNew)
7068 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
7069 if (OperatorDelete)
7070 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor72912fb2011-07-26 15:11:03 +00007071
7072 if (E->isArray() && Constructor &&
7073 !E->getAllocatedType()->isDependentType()) {
7074 QualType ElementType
7075 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7076 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7077 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7078 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
7079 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Destructor);
7080 }
7081 }
7082 }
7083
John McCallc3007a22010-10-26 07:05:15 +00007084 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007085 }
Mike Stump11289f42009-09-09 15:08:12 +00007086
Douglas Gregor0744ef62010-09-07 21:49:58 +00007087 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007088 if (!ArraySize.get()) {
7089 // If no array size was specified, but the new expression was
7090 // instantiated with an array type (e.g., "new T" where T is
7091 // instantiated with "int[4]"), extract the outer bound from the
7092 // array type as our array size. We do this with constant and
7093 // dependently-sized array types.
7094 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7095 if (!ArrayT) {
7096 // Do nothing
7097 } else if (const ConstantArrayType *ConsArrayT
7098 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007099 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007100 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7101 ConsArrayT->getSize(),
7102 SemaRef.Context.getSizeType(),
7103 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007104 AllocType = ConsArrayT->getElementType();
7105 } else if (const DependentSizedArrayType *DepArrayT
7106 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7107 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00007108 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007109 AllocType = DepArrayT->getElementType();
7110 }
7111 }
7112 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00007113
Douglas Gregora16548e2009-08-11 05:31:07 +00007114 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7115 E->isGlobalNew(),
7116 /*FIXME:*/E->getLocStart(),
7117 move_arg(PlacementArgs),
7118 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007119 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007120 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007121 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007122 ArraySize.get(),
Douglas Gregorf333f8c2011-10-18 02:43:19 +00007123 E->getConstructorLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007124 move_arg(ConstructorArgs),
Douglas Gregorf333f8c2011-10-18 02:43:19 +00007125 E->getConstructorRParen());
Douglas Gregora16548e2009-08-11 05:31:07 +00007126}
Mike Stump11289f42009-09-09 15:08:12 +00007127
Douglas Gregora16548e2009-08-11 05:31:07 +00007128template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007129ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007130TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007131 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007132 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007133 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007134
Douglas Gregord2d9da02010-02-26 00:38:10 +00007135 // Transform the delete operator, if known.
7136 FunctionDecl *OperatorDelete = 0;
7137 if (E->getOperatorDelete()) {
7138 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007139 getDerived().TransformDecl(E->getLocStart(),
7140 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007141 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007142 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007143 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007144
Douglas Gregora16548e2009-08-11 05:31:07 +00007145 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007146 Operand.get() == E->getArgument() &&
7147 OperatorDelete == E->getOperatorDelete()) {
7148 // Mark any declarations we need as referenced.
7149 // FIXME: instantiation-specific.
7150 if (OperatorDelete)
7151 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007152
7153 if (!E->getArgument()->isTypeDependent()) {
7154 QualType Destroyed = SemaRef.Context.getBaseElementType(
7155 E->getDestroyedType());
7156 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7157 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
7158 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
7159 SemaRef.LookupDestructor(Record));
7160 }
7161 }
7162
John McCallc3007a22010-10-26 07:05:15 +00007163 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007164 }
Mike Stump11289f42009-09-09 15:08:12 +00007165
Douglas Gregora16548e2009-08-11 05:31:07 +00007166 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7167 E->isGlobalDelete(),
7168 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007169 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007170}
Mike Stump11289f42009-09-09 15:08:12 +00007171
Douglas Gregora16548e2009-08-11 05:31:07 +00007172template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007173ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007174TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007175 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007176 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007177 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007178 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007179
John McCallba7bf592010-08-24 05:47:05 +00007180 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007181 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007182 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007183 E->getOperatorLoc(),
7184 E->isArrow()? tok::arrow : tok::period,
7185 ObjectTypePtr,
7186 MayBePseudoDestructor);
7187 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007188 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007189
John McCallba7bf592010-08-24 05:47:05 +00007190 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007191 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7192 if (QualifierLoc) {
7193 QualifierLoc
7194 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7195 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007196 return ExprError();
7197 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007198 CXXScopeSpec SS;
7199 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007200
Douglas Gregor678f90d2010-02-25 01:56:36 +00007201 PseudoDestructorTypeStorage Destroyed;
7202 if (E->getDestroyedTypeInfo()) {
7203 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007204 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00007205 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007206 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007207 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007208 Destroyed = DestroyedTypeInfo;
7209 } else if (ObjectType->isDependentType()) {
7210 // We aren't likely to be able to resolve the identifier down to a type
7211 // now anyway, so just retain the identifier.
7212 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7213 E->getDestroyedTypeLoc());
7214 } else {
7215 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007216 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007217 *E->getDestroyedTypeIdentifier(),
7218 E->getDestroyedTypeLoc(),
7219 /*Scope=*/0,
7220 SS, ObjectTypePtr,
7221 false);
7222 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007223 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007224
Douglas Gregor678f90d2010-02-25 01:56:36 +00007225 Destroyed
7226 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7227 E->getDestroyedTypeLoc());
7228 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007229
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007230 TypeSourceInfo *ScopeTypeInfo = 0;
7231 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00007232 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007233 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007234 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007235 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007236
John McCallb268a282010-08-23 23:25:46 +00007237 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007238 E->getOperatorLoc(),
7239 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007240 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007241 ScopeTypeInfo,
7242 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007243 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007244 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007245}
Mike Stump11289f42009-09-09 15:08:12 +00007246
Douglas Gregorad8a3362009-09-04 17:36:40 +00007247template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007248ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007249TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007250 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007251 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7252 Sema::LookupOrdinaryName);
7253
7254 // Transform all the decls.
7255 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7256 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007257 NamedDecl *InstD = static_cast<NamedDecl*>(
7258 getDerived().TransformDecl(Old->getNameLoc(),
7259 *I));
John McCall84d87672009-12-10 09:41:52 +00007260 if (!InstD) {
7261 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7262 // This can happen because of dependent hiding.
7263 if (isa<UsingShadowDecl>(*I))
7264 continue;
7265 else
John McCallfaf5fb42010-08-26 23:41:50 +00007266 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00007267 }
John McCalle66edc12009-11-24 19:00:30 +00007268
7269 // Expand using declarations.
7270 if (isa<UsingDecl>(InstD)) {
7271 UsingDecl *UD = cast<UsingDecl>(InstD);
7272 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7273 E = UD->shadow_end(); I != E; ++I)
7274 R.addDecl(*I);
7275 continue;
7276 }
7277
7278 R.addDecl(InstD);
7279 }
7280
7281 // Resolve a kind, but don't do any further analysis. If it's
7282 // ambiguous, the callee needs to deal with it.
7283 R.resolveKind();
7284
7285 // Rebuild the nested-name qualifier, if present.
7286 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007287 if (Old->getQualifierLoc()) {
7288 NestedNameSpecifierLoc QualifierLoc
7289 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7290 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007291 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007292
Douglas Gregor0da1d432011-02-28 20:01:57 +00007293 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007294 }
7295
Douglas Gregor9262f472010-04-27 18:19:34 +00007296 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007297 CXXRecordDecl *NamingClass
7298 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7299 Old->getNameLoc(),
7300 Old->getNamingClass()));
7301 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007302 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007303
Douglas Gregorda7be082010-04-27 16:10:10 +00007304 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007305 }
7306
7307 // If we have no template arguments, it's a normal declaration name.
7308 if (!Old->hasExplicitTemplateArgs())
7309 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7310
7311 // If we have template arguments, rebuild them, then rebuild the
7312 // templateid expression.
7313 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007314 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7315 Old->getNumTemplateArgs(),
7316 TransArgs))
7317 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00007318
7319 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7320 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007321}
Mike Stump11289f42009-09-09 15:08:12 +00007322
Douglas Gregora16548e2009-08-11 05:31:07 +00007323template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007324ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007325TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00007326 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7327 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007328 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007329
Douglas Gregora16548e2009-08-11 05:31:07 +00007330 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00007331 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007332 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007333
Mike Stump11289f42009-09-09 15:08:12 +00007334 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007335 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007336 T,
7337 E->getLocEnd());
7338}
Mike Stump11289f42009-09-09 15:08:12 +00007339
Douglas Gregora16548e2009-08-11 05:31:07 +00007340template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007341ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00007342TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7343 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7344 if (!LhsT)
7345 return ExprError();
7346
7347 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7348 if (!RhsT)
7349 return ExprError();
7350
7351 if (!getDerived().AlwaysRebuild() &&
7352 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7353 return SemaRef.Owned(E);
7354
7355 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7356 E->getLocStart(),
7357 LhsT, RhsT,
7358 E->getLocEnd());
7359}
7360
7361template<typename Derived>
7362ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00007363TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7364 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7365 if (!T)
7366 return ExprError();
7367
7368 if (!getDerived().AlwaysRebuild() &&
7369 T == E->getQueriedTypeSourceInfo())
7370 return SemaRef.Owned(E);
7371
7372 ExprResult SubExpr;
7373 {
7374 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7375 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7376 if (SubExpr.isInvalid())
7377 return ExprError();
7378
7379 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7380 return SemaRef.Owned(E);
7381 }
7382
7383 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7384 E->getLocStart(),
7385 T,
7386 SubExpr.get(),
7387 E->getLocEnd());
7388}
7389
7390template<typename Derived>
7391ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00007392TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7393 ExprResult SubExpr;
7394 {
7395 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7396 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7397 if (SubExpr.isInvalid())
7398 return ExprError();
7399
7400 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7401 return SemaRef.Owned(E);
7402 }
7403
7404 return getDerived().RebuildExpressionTrait(
7405 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7406}
7407
7408template<typename Derived>
7409ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007410TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007411 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007412 NestedNameSpecifierLoc QualifierLoc
7413 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7414 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007415 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007416
John McCall31f82722010-11-12 08:19:04 +00007417 // TODO: If this is a conversion-function-id, verify that the
7418 // destination type name (if present) resolves the same way after
7419 // instantiation as it did in the local scope.
7420
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007421 DeclarationNameInfo NameInfo
7422 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7423 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007424 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007425
John McCalle66edc12009-11-24 19:00:30 +00007426 if (!E->hasExplicitTemplateArgs()) {
7427 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007428 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007429 // Note: it is sufficient to compare the Name component of NameInfo:
7430 // if name has not changed, DNLoc has not changed either.
7431 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00007432 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007433
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007434 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007435 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007436 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00007437 }
John McCall6b51f282009-11-23 01:53:49 +00007438
7439 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007440 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7441 E->getNumTemplateArgs(),
7442 TransArgs))
7443 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007444
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007445 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007446 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007447 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007448}
7449
7450template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007451ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007452TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00007453 // CXXConstructExprs are always implicit, so when we have a
7454 // 1-argument construction we just transform that argument.
7455 if (E->getNumArgs() == 1 ||
7456 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7457 return getDerived().TransformExpr(E->getArg(0));
7458
Douglas Gregora16548e2009-08-11 05:31:07 +00007459 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7460
7461 QualType T = getDerived().TransformType(E->getType());
7462 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007463 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007464
7465 CXXConstructorDecl *Constructor
7466 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007467 getDerived().TransformDecl(E->getLocStart(),
7468 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007469 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007470 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007471
Douglas Gregora16548e2009-08-11 05:31:07 +00007472 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007473 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007474 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7475 &ArgumentChanged))
7476 return ExprError();
7477
Douglas Gregora16548e2009-08-11 05:31:07 +00007478 if (!getDerived().AlwaysRebuild() &&
7479 T == E->getType() &&
7480 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00007481 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00007482 // Mark the constructor as referenced.
7483 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00007484 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007485 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00007486 }
Mike Stump11289f42009-09-09 15:08:12 +00007487
Douglas Gregordb121ba2009-12-14 16:27:04 +00007488 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7489 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00007490 move_arg(Args),
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00007491 E->hadMultipleCandidates(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00007492 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00007493 E->getConstructionKind(),
7494 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007495}
Mike Stump11289f42009-09-09 15:08:12 +00007496
Douglas Gregora16548e2009-08-11 05:31:07 +00007497/// \brief Transform a C++ temporary-binding expression.
7498///
Douglas Gregor363b1512009-12-24 18:51:59 +00007499/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7500/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007501template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007502ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007503TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007504 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007505}
Mike Stump11289f42009-09-09 15:08:12 +00007506
John McCall5d413782010-12-06 08:20:24 +00007507/// \brief Transform a C++ expression that contains cleanups that should
7508/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00007509///
John McCall5d413782010-12-06 08:20:24 +00007510/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00007511/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007512template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007513ExprResult
John McCall5d413782010-12-06 08:20:24 +00007514TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007515 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007516}
Mike Stump11289f42009-09-09 15:08:12 +00007517
Douglas Gregora16548e2009-08-11 05:31:07 +00007518template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007519ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007520TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00007521 CXXTemporaryObjectExpr *E) {
7522 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7523 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007524 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007525
Douglas Gregora16548e2009-08-11 05:31:07 +00007526 CXXConstructorDecl *Constructor
7527 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00007528 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007529 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007530 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007531 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007532
Douglas Gregora16548e2009-08-11 05:31:07 +00007533 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007534 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00007535 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00007536 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7537 &ArgumentChanged))
7538 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007539
Douglas Gregora16548e2009-08-11 05:31:07 +00007540 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007541 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007542 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007543 !ArgumentChanged) {
7544 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00007545 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007546 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007547 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00007548
7549 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7550 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007551 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007552 E->getLocEnd());
7553}
Mike Stump11289f42009-09-09 15:08:12 +00007554
Douglas Gregora16548e2009-08-11 05:31:07 +00007555template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007556ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007557TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007558 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00007559 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7560 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007561 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007562
Douglas Gregora16548e2009-08-11 05:31:07 +00007563 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007564 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007565 Args.reserve(E->arg_size());
7566 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7567 &ArgumentChanged))
7568 return ExprError();
7569
Douglas Gregora16548e2009-08-11 05:31:07 +00007570 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007571 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007572 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007573 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007574
Douglas Gregora16548e2009-08-11 05:31:07 +00007575 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00007576 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00007577 E->getLParenLoc(),
7578 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007579 E->getRParenLoc());
7580}
Mike Stump11289f42009-09-09 15:08:12 +00007581
Douglas Gregora16548e2009-08-11 05:31:07 +00007582template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007583ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007584TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007585 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007586 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007587 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007588 Expr *OldBase;
7589 QualType BaseType;
7590 QualType ObjectType;
7591 if (!E->isImplicitAccess()) {
7592 OldBase = E->getBase();
7593 Base = getDerived().TransformExpr(OldBase);
7594 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007595 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007596
John McCall2d74de92009-12-01 22:10:20 +00007597 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00007598 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00007599 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007600 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007601 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007602 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00007603 ObjectTy,
7604 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00007605 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007606 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007607
John McCallba7bf592010-08-24 05:47:05 +00007608 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00007609 BaseType = ((Expr*) Base.get())->getType();
7610 } else {
7611 OldBase = 0;
7612 BaseType = getDerived().TransformType(E->getBaseType());
7613 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7614 }
Mike Stump11289f42009-09-09 15:08:12 +00007615
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007616 // Transform the first part of the nested-name-specifier that qualifies
7617 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007618 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007619 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00007620 E->getFirstQualifierFoundInScope(),
7621 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00007622
Douglas Gregore16af532011-02-28 18:50:33 +00007623 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007624 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00007625 QualifierLoc
7626 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7627 ObjectType,
7628 FirstQualifierInScope);
7629 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007630 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007631 }
Mike Stump11289f42009-09-09 15:08:12 +00007632
John McCall31f82722010-11-12 08:19:04 +00007633 // TODO: If this is a conversion-function-id, verify that the
7634 // destination type name (if present) resolves the same way after
7635 // instantiation as it did in the local scope.
7636
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007637 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007638 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007639 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007640 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007641
John McCall2d74de92009-12-01 22:10:20 +00007642 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007643 // This is a reference to a member without an explicitly-specified
7644 // template argument list. Optimize for this common case.
7645 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007646 Base.get() == OldBase &&
7647 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007648 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007649 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007650 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007651 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007652
John McCallb268a282010-08-23 23:25:46 +00007653 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007654 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007655 E->isArrow(),
7656 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007657 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007658 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007659 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007660 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007661 }
7662
John McCall6b51f282009-11-23 01:53:49 +00007663 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007664 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7665 E->getNumTemplateArgs(),
7666 TransArgs))
7667 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007668
John McCallb268a282010-08-23 23:25:46 +00007669 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007670 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007671 E->isArrow(),
7672 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007673 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007674 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007675 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007676 &TransArgs);
7677}
7678
7679template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007680ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007681TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007682 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007683 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007684 QualType BaseType;
7685 if (!Old->isImplicitAccess()) {
7686 Base = getDerived().TransformExpr(Old->getBase());
7687 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007688 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007689 BaseType = ((Expr*) Base.get())->getType();
7690 } else {
7691 BaseType = getDerived().TransformType(Old->getBaseType());
7692 }
John McCall10eae182009-11-30 22:42:35 +00007693
Douglas Gregor0da1d432011-02-28 20:01:57 +00007694 NestedNameSpecifierLoc QualifierLoc;
7695 if (Old->getQualifierLoc()) {
7696 QualifierLoc
7697 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7698 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007699 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007700 }
7701
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007702 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007703 Sema::LookupOrdinaryName);
7704
7705 // Transform all the decls.
7706 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7707 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007708 NamedDecl *InstD = static_cast<NamedDecl*>(
7709 getDerived().TransformDecl(Old->getMemberLoc(),
7710 *I));
John McCall84d87672009-12-10 09:41:52 +00007711 if (!InstD) {
7712 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7713 // This can happen because of dependent hiding.
7714 if (isa<UsingShadowDecl>(*I))
7715 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007716 else {
7717 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007718 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007719 }
John McCall84d87672009-12-10 09:41:52 +00007720 }
John McCall10eae182009-11-30 22:42:35 +00007721
7722 // Expand using declarations.
7723 if (isa<UsingDecl>(InstD)) {
7724 UsingDecl *UD = cast<UsingDecl>(InstD);
7725 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7726 E = UD->shadow_end(); I != E; ++I)
7727 R.addDecl(*I);
7728 continue;
7729 }
7730
7731 R.addDecl(InstD);
7732 }
7733
7734 R.resolveKind();
7735
Douglas Gregor9262f472010-04-27 18:19:34 +00007736 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007737 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007738 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007739 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007740 Old->getMemberLoc(),
7741 Old->getNamingClass()));
7742 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007743 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007744
Douglas Gregorda7be082010-04-27 16:10:10 +00007745 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007746 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007747
John McCall10eae182009-11-30 22:42:35 +00007748 TemplateArgumentListInfo TransArgs;
7749 if (Old->hasExplicitTemplateArgs()) {
7750 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7751 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007752 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7753 Old->getNumTemplateArgs(),
7754 TransArgs))
7755 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007756 }
John McCall38836f02010-01-15 08:34:02 +00007757
7758 // FIXME: to do this check properly, we will need to preserve the
7759 // first-qualifier-in-scope here, just in case we had a dependent
7760 // base (and therefore couldn't do the check) and a
7761 // nested-name-qualifier (and therefore could do the lookup).
7762 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007763
John McCallb268a282010-08-23 23:25:46 +00007764 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007765 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007766 Old->getOperatorLoc(),
7767 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007768 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007769 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007770 R,
7771 (Old->hasExplicitTemplateArgs()
7772 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007773}
7774
7775template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007776ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007777TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00007778 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007779 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7780 if (SubExpr.isInvalid())
7781 return ExprError();
7782
7783 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007784 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007785
7786 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7787}
7788
7789template<typename Derived>
7790ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007791TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007792 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7793 if (Pattern.isInvalid())
7794 return ExprError();
7795
7796 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7797 return SemaRef.Owned(E);
7798
Douglas Gregorb8840002011-01-14 21:20:45 +00007799 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7800 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007801}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007802
7803template<typename Derived>
7804ExprResult
7805TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7806 // If E is not value-dependent, then nothing will change when we transform it.
7807 // Note: This is an instantiation-centric view.
7808 if (!E->isValueDependent())
7809 return SemaRef.Owned(E);
7810
7811 // Note: None of the implementations of TryExpandParameterPacks can ever
7812 // produce a diagnostic when given only a single unexpanded parameter pack,
7813 // so
7814 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7815 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007816 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007817 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007818 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00007819 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007820 ShouldExpand, RetainExpansion,
7821 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007822 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007823
Douglas Gregorab96bcf2011-10-10 18:59:29 +00007824 if (RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007825 return SemaRef.Owned(E);
Douglas Gregorab96bcf2011-10-10 18:59:29 +00007826
7827 NamedDecl *Pack = E->getPack();
7828 if (!ShouldExpand) {
7829 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
7830 Pack));
7831 if (!Pack)
7832 return ExprError();
7833 }
7834
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007835
7836 // We now know the length of the parameter pack, so build a new expression
7837 // that stores that length.
Douglas Gregorab96bcf2011-10-10 18:59:29 +00007838 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007839 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00007840 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007841}
7842
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007843template<typename Derived>
7844ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007845TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7846 SubstNonTypeTemplateParmPackExpr *E) {
7847 // Default behavior is to do nothing with this transformation.
7848 return SemaRef.Owned(E);
7849}
7850
7851template<typename Derived>
7852ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00007853TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
7854 SubstNonTypeTemplateParmExpr *E) {
7855 // Default behavior is to do nothing with this transformation.
7856 return SemaRef.Owned(E);
7857}
7858
7859template<typename Derived>
7860ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00007861TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
7862 MaterializeTemporaryExpr *E) {
7863 return getDerived().TransformExpr(E->GetTemporaryExpr());
7864}
7865
7866template<typename Derived>
7867ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007868TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007869 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007870}
7871
Mike Stump11289f42009-09-09 15:08:12 +00007872template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007873ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007874TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007875 TypeSourceInfo *EncodedTypeInfo
7876 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7877 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007878 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007879
Douglas Gregora16548e2009-08-11 05:31:07 +00007880 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007881 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007882 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007883
7884 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007885 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007886 E->getRParenLoc());
7887}
Mike Stump11289f42009-09-09 15:08:12 +00007888
Douglas Gregora16548e2009-08-11 05:31:07 +00007889template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00007890ExprResult TreeTransform<Derived>::
7891TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7892 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7893 if (result.isInvalid()) return ExprError();
7894 Expr *subExpr = result.take();
7895
7896 if (!getDerived().AlwaysRebuild() &&
7897 subExpr == E->getSubExpr())
7898 return SemaRef.Owned(E);
7899
7900 return SemaRef.Owned(new(SemaRef.Context)
7901 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7902}
7903
7904template<typename Derived>
7905ExprResult TreeTransform<Derived>::
7906TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7907 TypeSourceInfo *TSInfo
7908 = getDerived().TransformType(E->getTypeInfoAsWritten());
7909 if (!TSInfo)
7910 return ExprError();
7911
7912 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7913 if (Result.isInvalid())
7914 return ExprError();
7915
7916 if (!getDerived().AlwaysRebuild() &&
7917 TSInfo == E->getTypeInfoAsWritten() &&
7918 Result.get() == E->getSubExpr())
7919 return SemaRef.Owned(E);
7920
7921 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
7922 E->getBridgeKeywordLoc(), TSInfo,
7923 Result.get());
7924}
7925
7926template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007927ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007928TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007929 // Transform arguments.
7930 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007931 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007932 Args.reserve(E->getNumArgs());
7933 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7934 &ArgChanged))
7935 return ExprError();
7936
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007937 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7938 // Class message: transform the receiver type.
7939 TypeSourceInfo *ReceiverTypeInfo
7940 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7941 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007942 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007943
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007944 // If nothing changed, just retain the existing message send.
7945 if (!getDerived().AlwaysRebuild() &&
7946 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007947 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007948
7949 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00007950 SmallVector<SourceLocation, 16> SelLocs;
7951 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007952 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7953 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00007954 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007955 E->getMethodDecl(),
7956 E->getLeftLoc(),
7957 move_arg(Args),
7958 E->getRightLoc());
7959 }
7960
7961 // Instance message: transform the receiver
7962 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7963 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007964 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007965 = getDerived().TransformExpr(E->getInstanceReceiver());
7966 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007967 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007968
7969 // If nothing changed, just retain the existing message send.
7970 if (!getDerived().AlwaysRebuild() &&
7971 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007972 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007973
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007974 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00007975 SmallVector<SourceLocation, 16> SelLocs;
7976 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00007977 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007978 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00007979 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007980 E->getMethodDecl(),
7981 E->getLeftLoc(),
7982 move_arg(Args),
7983 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007984}
7985
Mike Stump11289f42009-09-09 15:08:12 +00007986template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007987ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007988TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007989 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007990}
7991
Mike Stump11289f42009-09-09 15:08:12 +00007992template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007993ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007994TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007995 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007996}
7997
Mike Stump11289f42009-09-09 15:08:12 +00007998template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007999ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008000TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00008001 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00008002 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00008003 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008004 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00008005
8006 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00008007
Douglas Gregord51d90d2010-04-26 20:11:03 +00008008 // If nothing changed, just retain the existing expression.
8009 if (!getDerived().AlwaysRebuild() &&
8010 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00008011 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00008012
John McCallb268a282010-08-23 23:25:46 +00008013 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00008014 E->getLocation(),
8015 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00008016}
8017
Mike Stump11289f42009-09-09 15:08:12 +00008018template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008019ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008020TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00008021 // 'super' and types never change. Property never changes. Just
8022 // retain the existing expression.
8023 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00008024 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00008025
Douglas Gregor9faee212010-04-26 20:47:02 +00008026 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00008027 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00008028 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008029 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00008030
Douglas Gregor9faee212010-04-26 20:47:02 +00008031 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00008032
Douglas Gregor9faee212010-04-26 20:47:02 +00008033 // If nothing changed, just retain the existing expression.
8034 if (!getDerived().AlwaysRebuild() &&
8035 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00008036 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008037
John McCallb7bd14f2010-12-02 01:19:52 +00008038 if (E->isExplicitProperty())
8039 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8040 E->getExplicitProperty(),
8041 E->getLocation());
8042
8043 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8044 E->getType(),
8045 E->getImplicitPropertyGetter(),
8046 E->getImplicitPropertySetter(),
8047 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00008048}
8049
Mike Stump11289f42009-09-09 15:08:12 +00008050template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008051ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008052TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00008053 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00008054 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00008055 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008056 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00008057
Douglas Gregord51d90d2010-04-26 20:11:03 +00008058 // If nothing changed, just retain the existing expression.
8059 if (!getDerived().AlwaysRebuild() &&
8060 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00008061 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00008062
John McCallb268a282010-08-23 23:25:46 +00008063 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00008064 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00008065}
8066
Mike Stump11289f42009-09-09 15:08:12 +00008067template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008068ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008069TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008070 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00008071 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00008072 SubExprs.reserve(E->getNumSubExprs());
8073 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8074 SubExprs, &ArgumentChanged))
8075 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008076
Douglas Gregora16548e2009-08-11 05:31:07 +00008077 if (!getDerived().AlwaysRebuild() &&
8078 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00008079 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008080
Douglas Gregora16548e2009-08-11 05:31:07 +00008081 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8082 move_arg(SubExprs),
8083 E->getRParenLoc());
8084}
8085
Mike Stump11289f42009-09-09 15:08:12 +00008086template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008087ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008088TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00008089 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008090
John McCall490112f2011-02-04 18:33:18 +00008091 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8092 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8093
8094 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian4cc5df72011-05-05 17:18:12 +00008095 // We built a new blockScopeInfo in call to ActOnBlockStart
8096 // in above, CapturesCXXThis need be set here from the block
8097 // expression.
8098 blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
8099
Chris Lattner01cf8db2011-07-20 06:58:45 +00008100 SmallVector<ParmVarDecl*, 4> params;
8101 SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008102
8103 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00008104 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8105 oldBlock->param_begin(),
8106 oldBlock->param_size(),
8107 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00008108 return true;
John McCall490112f2011-02-04 18:33:18 +00008109
8110 const FunctionType *exprFunctionType = E->getFunctionType();
8111 QualType exprResultType = exprFunctionType->getResultType();
8112 if (!exprResultType.isNull()) {
8113 if (!exprResultType->isDependentType())
8114 blockScope->ReturnType = exprResultType;
8115 else if (exprResultType != getSema().Context.DependentTy)
8116 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008117 }
Douglas Gregor476e3022011-01-19 21:32:01 +00008118
8119 // If the return type has not been determined yet, leave it as a dependent
8120 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00008121 if (blockScope->ReturnType.isNull())
8122 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00008123
8124 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00008125 if (blockScope->ReturnType->isObjCObjectType()) {
8126 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00008127 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00008128 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00008129 return ExprError();
8130 }
John McCall3882ace2011-01-05 12:14:39 +00008131
John McCall490112f2011-02-04 18:33:18 +00008132 QualType functionType = getDerived().RebuildFunctionProtoType(
8133 blockScope->ReturnType,
8134 paramTypes.data(),
8135 paramTypes.size(),
8136 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00008137 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00008138 exprFunctionType->getExtInfo());
8139 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00008140
8141 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00008142 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00008143 blockScope->TheDecl->setParams(params);
Douglas Gregor476e3022011-01-19 21:32:01 +00008144
8145 // If the return type wasn't explicitly set, it will have been marked as a
8146 // dependent type (DependentTy); clear out the return type setting so
8147 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00008148 if (blockScope->ReturnType == getSema().Context.DependentTy)
8149 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00008150
John McCall3882ace2011-01-05 12:14:39 +00008151 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00008152 StmtResult body = getDerived().TransformStmt(E->getBody());
8153 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00008154 return ExprError();
8155
John McCall490112f2011-02-04 18:33:18 +00008156#ifndef NDEBUG
8157 // In builds with assertions, make sure that we captured everything we
8158 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00008159 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8160 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8161 e = oldBlock->capture_end(); i != e; ++i) {
8162 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00008163
Douglas Gregor4385d8b2011-05-20 15:32:55 +00008164 // Ignore parameter packs.
8165 if (isa<ParmVarDecl>(oldCapture) &&
8166 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8167 continue;
John McCall490112f2011-02-04 18:33:18 +00008168
Douglas Gregor4385d8b2011-05-20 15:32:55 +00008169 VarDecl *newCapture =
8170 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8171 oldCapture));
8172 assert(blockScope->CaptureMap.count(newCapture));
8173 }
John McCall490112f2011-02-04 18:33:18 +00008174 }
8175#endif
8176
8177 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8178 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00008179}
8180
Mike Stump11289f42009-09-09 15:08:12 +00008181template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008182ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008183TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008184 ValueDecl *ND
8185 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8186 E->getDecl()));
8187 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008188 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008189
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008190 if (!getDerived().AlwaysRebuild() &&
8191 ND == E->getDecl()) {
8192 // Mark it referenced in the new context regardless.
8193 // FIXME: this is a bit instantiation-specific.
8194 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
8195
John McCallc3007a22010-10-26 07:05:15 +00008196 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008197 }
8198
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008199 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00008200 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008201 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00008202}
Mike Stump11289f42009-09-09 15:08:12 +00008203
Tanya Lattner55808c12011-06-04 00:47:47 +00008204template<typename Derived>
8205ExprResult
8206TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00008207 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00008208}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00008209
8210template<typename Derived>
8211ExprResult
8212TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00008213 QualType RetTy = getDerived().TransformType(E->getType());
8214 bool ArgumentChanged = false;
8215 ASTOwningVector<Expr*> SubExprs(SemaRef);
8216 SubExprs.reserve(E->getNumSubExprs());
8217 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8218 SubExprs, &ArgumentChanged))
8219 return ExprError();
8220
8221 if (!getDerived().AlwaysRebuild() &&
8222 !ArgumentChanged)
8223 return SemaRef.Owned(E);
8224
8225 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8226 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00008227}
Tanya Lattner55808c12011-06-04 00:47:47 +00008228
Douglas Gregora16548e2009-08-11 05:31:07 +00008229//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008230// Type reconstruction
8231//===----------------------------------------------------------------------===//
8232
Mike Stump11289f42009-09-09 15:08:12 +00008233template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00008234QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8235 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00008236 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008237 getDerived().getBaseEntity());
8238}
8239
Mike Stump11289f42009-09-09 15:08:12 +00008240template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00008241QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8242 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00008243 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008244 getDerived().getBaseEntity());
8245}
8246
Mike Stump11289f42009-09-09 15:08:12 +00008247template<typename Derived>
8248QualType
John McCall70dd5f62009-10-30 00:06:24 +00008249TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8250 bool WrittenAsLValue,
8251 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00008252 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00008253 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008254}
8255
8256template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008257QualType
John McCall70dd5f62009-10-30 00:06:24 +00008258TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8259 QualType ClassType,
8260 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00008261 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00008262 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008263}
8264
8265template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008266QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00008267TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8268 ArrayType::ArraySizeModifier SizeMod,
8269 const llvm::APInt *Size,
8270 Expr *SizeExpr,
8271 unsigned IndexTypeQuals,
8272 SourceRange BracketsRange) {
8273 if (SizeExpr || !Size)
8274 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8275 IndexTypeQuals, BracketsRange,
8276 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00008277
8278 QualType Types[] = {
8279 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8280 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8281 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00008282 };
8283 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8284 QualType SizeType;
8285 for (unsigned I = 0; I != NumTypes; ++I)
8286 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8287 SizeType = Types[I];
8288 break;
8289 }
Mike Stump11289f42009-09-09 15:08:12 +00008290
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00008291 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
8292 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00008293 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008294 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00008295 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008296}
Mike Stump11289f42009-09-09 15:08:12 +00008297
Douglas Gregord6ff3322009-08-04 16:50:30 +00008298template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008299QualType
8300TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008301 ArrayType::ArraySizeModifier SizeMod,
8302 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00008303 unsigned IndexTypeQuals,
8304 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008305 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00008306 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008307}
8308
8309template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008310QualType
Mike Stump11289f42009-09-09 15:08:12 +00008311TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008312 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00008313 unsigned IndexTypeQuals,
8314 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008315 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00008316 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008317}
Mike Stump11289f42009-09-09 15:08:12 +00008318
Douglas Gregord6ff3322009-08-04 16:50:30 +00008319template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008320QualType
8321TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008322 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00008323 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008324 unsigned IndexTypeQuals,
8325 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008326 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00008327 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008328 IndexTypeQuals, BracketsRange);
8329}
8330
8331template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008332QualType
8333TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008334 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00008335 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008336 unsigned IndexTypeQuals,
8337 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008338 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00008339 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008340 IndexTypeQuals, BracketsRange);
8341}
8342
8343template<typename Derived>
8344QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00008345 unsigned NumElements,
8346 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00008347 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00008348 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008349}
Mike Stump11289f42009-09-09 15:08:12 +00008350
Douglas Gregord6ff3322009-08-04 16:50:30 +00008351template<typename Derived>
8352QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8353 unsigned NumElements,
8354 SourceLocation AttributeLoc) {
8355 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8356 NumElements, true);
8357 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00008358 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8359 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00008360 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008361}
Mike Stump11289f42009-09-09 15:08:12 +00008362
Douglas Gregord6ff3322009-08-04 16:50:30 +00008363template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008364QualType
8365TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00008366 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008367 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00008368 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008369}
Mike Stump11289f42009-09-09 15:08:12 +00008370
Douglas Gregord6ff3322009-08-04 16:50:30 +00008371template<typename Derived>
8372QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00008373 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008374 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00008375 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00008376 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00008377 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00008378 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00008379 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00008380 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008381 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00008382 getDerived().getBaseEntity(),
8383 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008384}
Mike Stump11289f42009-09-09 15:08:12 +00008385
Douglas Gregord6ff3322009-08-04 16:50:30 +00008386template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00008387QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8388 return SemaRef.Context.getFunctionNoProtoType(T);
8389}
8390
8391template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00008392QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8393 assert(D && "no decl found");
8394 if (D->isInvalidDecl()) return QualType();
8395
Douglas Gregorc298ffc2010-04-22 16:44:27 +00008396 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00008397 TypeDecl *Ty;
8398 if (isa<UsingDecl>(D)) {
8399 UsingDecl *Using = cast<UsingDecl>(D);
8400 assert(Using->isTypeName() &&
8401 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8402
8403 // A valid resolved using typename decl points to exactly one type decl.
8404 assert(++Using->shadow_begin() == Using->shadow_end());
8405 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00008406
John McCallb96ec562009-12-04 22:46:56 +00008407 } else {
8408 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8409 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8410 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8411 }
8412
8413 return SemaRef.Context.getTypeDeclType(Ty);
8414}
8415
8416template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008417QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8418 SourceLocation Loc) {
8419 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008420}
8421
8422template<typename Derived>
8423QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8424 return SemaRef.Context.getTypeOfType(Underlying);
8425}
8426
8427template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008428QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8429 SourceLocation Loc) {
8430 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008431}
8432
8433template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00008434QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8435 UnaryTransformType::UTTKind UKind,
8436 SourceLocation Loc) {
8437 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8438}
8439
8440template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00008441QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00008442 TemplateName Template,
8443 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00008444 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00008445 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008446}
Mike Stump11289f42009-09-09 15:08:12 +00008447
Douglas Gregor1135c352009-08-06 05:28:30 +00008448template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00008449QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
8450 SourceLocation KWLoc) {
8451 return SemaRef.BuildAtomicType(ValueType, KWLoc);
8452}
8453
8454template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008455TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008456TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008457 bool TemplateKW,
8458 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008459 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008460 Template);
8461}
8462
8463template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008464TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008465TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8466 const IdentifierInfo &Name,
8467 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00008468 QualType ObjectType,
8469 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008470 UnqualifiedId TemplateName;
8471 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00008472 Sema::TemplateTy Template;
8473 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008474 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008475 SS,
Douglas Gregor9db53502011-03-02 18:07:45 +00008476 TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00008477 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008478 /*EnteringContext=*/false,
8479 Template);
John McCall31f82722010-11-12 08:19:04 +00008480 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00008481}
Mike Stump11289f42009-09-09 15:08:12 +00008482
Douglas Gregora16548e2009-08-11 05:31:07 +00008483template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00008484TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008485TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008486 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00008487 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008488 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00008489 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00008490 // FIXME: Bogus location information.
8491 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8492 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00008493 Sema::TemplateTy Template;
8494 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008495 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008496 SS,
8497 Name,
John McCallba7bf592010-08-24 05:47:05 +00008498 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008499 /*EnteringContext=*/false,
8500 Template);
8501 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00008502}
Alexis Hunta8136cc2010-05-05 15:23:54 +00008503
Douglas Gregor71395fa2009-11-04 00:56:37 +00008504template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008505ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008506TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8507 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008508 Expr *OrigCallee,
8509 Expr *First,
8510 Expr *Second) {
8511 Expr *Callee = OrigCallee->IgnoreParenCasts();
8512 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00008513
Douglas Gregora16548e2009-08-11 05:31:07 +00008514 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00008515 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00008516 if (!First->getType()->isOverloadableType() &&
8517 !Second->getType()->isOverloadableType())
8518 return getSema().CreateBuiltinArraySubscriptExpr(First,
8519 Callee->getLocStart(),
8520 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00008521 } else if (Op == OO_Arrow) {
8522 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00008523 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8524 } else if (Second == 0 || isPostIncDec) {
8525 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008526 // The argument is not of overloadable type, so try to create a
8527 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00008528 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008529 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00008530
John McCallb268a282010-08-23 23:25:46 +00008531 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008532 }
8533 } else {
John McCallb268a282010-08-23 23:25:46 +00008534 if (!First->getType()->isOverloadableType() &&
8535 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008536 // Neither of the arguments is an overloadable type, so try to
8537 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00008538 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008539 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00008540 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00008541 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008542 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008543
Douglas Gregora16548e2009-08-11 05:31:07 +00008544 return move(Result);
8545 }
8546 }
Mike Stump11289f42009-09-09 15:08:12 +00008547
8548 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00008549 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00008550 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00008551
John McCallb268a282010-08-23 23:25:46 +00008552 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00008553 assert(ULE->requiresADL());
8554
8555 // FIXME: Do we have to check
8556 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00008557 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00008558 } else {
John McCallb268a282010-08-23 23:25:46 +00008559 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00008560 }
Mike Stump11289f42009-09-09 15:08:12 +00008561
Douglas Gregora16548e2009-08-11 05:31:07 +00008562 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00008563 Expr *Args[2] = { First, Second };
8564 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00008565
Douglas Gregora16548e2009-08-11 05:31:07 +00008566 // Create the overloaded operator invocation for unary operators.
8567 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00008568 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008569 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00008570 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008571 }
Mike Stump11289f42009-09-09 15:08:12 +00008572
Douglas Gregore9d62932011-07-15 16:25:15 +00008573 if (Op == OO_Subscript) {
8574 SourceLocation LBrace;
8575 SourceLocation RBrace;
8576
8577 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
8578 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
8579 LBrace = SourceLocation::getFromRawEncoding(
8580 NameLoc.CXXOperatorName.BeginOpNameLoc);
8581 RBrace = SourceLocation::getFromRawEncoding(
8582 NameLoc.CXXOperatorName.EndOpNameLoc);
8583 } else {
8584 LBrace = Callee->getLocStart();
8585 RBrace = OpLoc;
8586 }
8587
8588 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
8589 First, Second);
8590 }
Sebastian Redladba46e2009-10-29 20:17:01 +00008591
Douglas Gregora16548e2009-08-11 05:31:07 +00008592 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00008593 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008594 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00008595 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8596 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008597 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008598
Mike Stump11289f42009-09-09 15:08:12 +00008599 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00008600}
Mike Stump11289f42009-09-09 15:08:12 +00008601
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008602template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008603ExprResult
John McCallb268a282010-08-23 23:25:46 +00008604TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008605 SourceLocation OperatorLoc,
8606 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00008607 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008608 TypeSourceInfo *ScopeType,
8609 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008610 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008611 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00008612 QualType BaseType = Base->getType();
8613 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008614 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00008615 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00008616 !BaseType->getAs<PointerType>()->getPointeeType()
8617 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008618 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00008619 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008620 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008621 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008622 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008623 /*FIXME?*/true);
8624 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008625
Douglas Gregor678f90d2010-02-25 01:56:36 +00008626 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008627 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8628 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8629 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8630 NameInfo.setNamedTypeInfo(DestroyedType);
8631
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008632 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008633
John McCallb268a282010-08-23 23:25:46 +00008634 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008635 OperatorLoc, isArrow,
8636 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008637 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008638 /*TemplateArgs*/ 0);
8639}
8640
Douglas Gregord6ff3322009-08-04 16:50:30 +00008641} // end namespace clang
8642
8643#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H