blob: 03a1d78aa01cfd4cb6eaafb39f999ee9fcf74e39 [file] [log] [blame]
Chris Lattner57ad3782011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregor577f75a2009-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 Lattner57ad3782011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-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 Lattner57ad3782011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregor577f75a2009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
John McCall2d887082010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregore737f502010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor8491ffe2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregordcee1a12009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCall781472f2010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Richard Smith3e4c6c42011-05-05 21:57:07 +000024#include "clang/AST/DeclTemplate.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000025#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000026#include "clang/AST/ExprCXX.h"
27#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000028#include "clang/AST/Stmt.h"
29#include "clang/AST/StmtCXX.h"
30#include "clang/AST/StmtObjC.h"
John McCall19510852010-08-20 18:27:03 +000031#include "clang/Sema/Ownership.h"
32#include "clang/Sema/Designator.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000033#include "clang/Lex/Preprocessor.h"
David Blaikiea71f9d02011-09-22 02:34:54 +000034#include "llvm/ADT/ArrayRef.h"
John McCalla2becad2009-10-21 00:40:46 +000035#include "llvm/Support/ErrorHandling.h"
Douglas Gregor7e44e3f2010-12-02 00:05:49 +000036#include "TypeLocBuilder.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCall781472f2010-08-25 08:40:02 +000040using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000041
Douglas Gregor577f75a2009-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 Stump1eb44332009-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 Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor9151c112011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregor577f75a2009-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 Gregor43959a92009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-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 Gregor577f75a2009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregord3731192011-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 Gregor577f75a2009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000114
Mike Stump1eb44332009-09-09 15:08:12 +0000115public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000116 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000117 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000118
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000123 const Derived &getDerived() const {
124 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000125 }
126
John McCall60d7b3a2010-08-24 06:29:42 +0000127 static inline ExprResult Owned(Expr *E) { return E; }
128 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000129
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000133
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000140
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000144 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000145 /// provide an alternative implementation that provides better location
146 /// information.
147 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000148
Douglas Gregor577f75a2009-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 Gregorb98b1992009-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 Stump1eb44332009-09-09 15:08:12 +0000162
Douglas Gregorb98b1992009-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 Stump1eb44332009-09-09 15:08:12 +0000169
Douglas Gregorb98b1992009-08-11 05:31:07 +0000170 public:
171 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000172 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000173 OldLocation = Self.getDerived().getBaseLocation();
174 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregorae201f72011-01-25 17:51:48 +0000175
176 if (Location.isValid())
177 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000178 }
Mike Stump1eb44332009-09-09 15:08:12 +0000179
Douglas Gregorb98b1992009-08-11 05:31:07 +0000180 ~TemporaryBase() {
181 Self.getDerived().setBase(OldLocation, OldEntity);
182 }
183 };
Mike Stump1eb44332009-09-09 15:08:12 +0000184
185 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000186 /// transformed.
187 ///
188 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000189 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-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 Gregor6eef5192009-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 }
Sean Huntc3021132010-05-05 15:23:54 +0000205
Douglas Gregor8491ffe2010-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 Gregorb99268b2010-12-21 00:52:54 +0000210 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-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 Gregord3731192011-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 Gregor8491ffe2010-12-20 22:05:00 +0000234 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-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 Gregor8491ffe2010-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 Blaikiea71f9d02011-09-22 02:34:54 +0000248 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000249 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000250 bool &RetainExpansion,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000251 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000252 ShouldExpand = false;
253 return false;
254 }
255
Douglas Gregord3731192011-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 Gregor12c9c002011-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 Gregor577f75a2009-08-04 16:50:30 +0000276 /// \brief Transforms the given type into another type.
277 ///
John McCalla2becad2009-10-21 00:40:46 +0000278 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000279 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-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 McCalla93c9342009-12-07 02:54:59 +0000282 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000283 ///
284 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000285 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000286
John McCalla2becad2009-10-21 00:40:46 +0000287 /// \brief Transforms the given type-with-location into a new
288 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000289 ///
John McCalla2becad2009-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 McCall43fed0d2010-11-12 08:19:04 +0000295 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-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 McCall43fed0d2010-11-12 08:19:04 +0000301 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000302
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000303 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000304 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000305 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +0000312 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000313
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000314 /// \brief Transform the given expression.
315 ///
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +0000322 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000323
Douglas Gregoraa165f82011-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 Lattner686775d2011-07-20 06:58:45 +0000348 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000349 bool *ArgChanged = 0);
350
Douglas Gregor577f75a2009-08-04 16:50:30 +0000351 /// \brief Transform the given declaration, which is referenced from a type
352 /// or expression.
353 ///
Douglas Gregordcee1a12009-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 Gregor7c1e98f2010-03-01 15:56:25 +0000356 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregor43959a92009-08-20 07:17:43 +0000357
358 /// \brief Transform the definition of the given declaration.
359 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000360 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000361 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000362 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
363 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000364 }
Mike Stump1eb44332009-09-09 15:08:12 +0000365
Douglas Gregor6cd21982009-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 ///
Sean Huntc3021132010-05-05 15:23:54 +0000369 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-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.
Sean Huntc3021132010-05-05 15:23:54 +0000375 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
376 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000377 }
Sean Huntc3021132010-05-05 15:23:54 +0000378
Douglas Gregorc22b5ff2011-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 Gregor81499bb2009-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 Bagnara25777432010-08-11 22:01:17 +0000396 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000397 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000398
Douglas Gregor577f75a2009-08-04 16:50:30 +0000399 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000400 ///
Douglas Gregorfd4ffeb2011-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 Gregor577f75a2009-08-04 16:50:30 +0000425 /// \brief Transform the given template argument.
426 ///
Mike Stump1eb44332009-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 Gregor670444e2009-08-04 22:27:00 +0000429 /// new template argument from the transformed result. Subclasses may
430 /// override this function to provide alternate behavior.
John McCall833ca992009-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 Gregorfcc12532010-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 Gregor7ca7ac42010-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 Gregorfcc12532010-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 Gregor7ca7ac42010-12-20 23:36:19 +0000456 TemplateArgumentListInfo &Outputs) {
457 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
458 }
Douglas Gregor7f61f2f2010-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 Gregor7ca7ac42010-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 Gregor7f61f2f2010-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 Gregor7ca7ac42010-12-20 23:36:19 +0000474 template<typename InputIterator>
475 bool TransformTemplateArguments(InputIterator First,
476 InputIterator Last,
477 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000478
John McCall833ca992009-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 McCalla93c9342009-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 McCall833ca992009-10-29 08:12:44 +0000486 getDerived().getBaseLocation());
487 }
Mike Stump1eb44332009-09-09 15:08:12 +0000488
John McCalla2becad2009-10-21 00:40:46 +0000489#define ABSTRACT_TYPELOC(CLASS, PARENT)
490#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000491 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000492#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000493
John Wiegley28bbe4b2011-04-28 01:08:34 +0000494 StmtResult
495 TransformSEHHandler(Stmt *Handler);
496
John McCall43fed0d2010-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 Gregor087eb5a2011-03-04 18:53:13 +0000505 TemplateName Template,
506 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000507
508 QualType
509 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000510 DependentTemplateSpecializationTypeLoc TL,
511 NestedNameSpecifierLoc QualifierLoc);
512
John McCall21ef0fa2010-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 Gregora009b592011-01-07 00:20:55 +0000520 bool TransformFunctionTypeParams(SourceLocation Loc,
521 ParmVarDecl **Params, unsigned NumParams,
522 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000523 SmallVectorImpl<QualType> &PTypes,
524 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000525
526 /// \brief Transforms a single function-type parameter. Return null
527 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000528 ///
529 /// \param indexAdjustment - A number to add to the parameter's
530 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000531 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000532 int indexAdjustment,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000533 llvm::Optional<unsigned> NumExpansions);
John McCall21ef0fa2010-03-11 09:03:00 +0000534
John McCall43fed0d2010-11-12 08:19:04 +0000535 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000536
John McCall60d7b3a2010-08-24 06:29:42 +0000537 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
538 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000539
Douglas Gregor43959a92009-08-20 07:17:43 +0000540#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000541 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000542#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000543 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000544#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000545#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000546
Douglas Gregor577f75a2009-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 McCall85737a72009-10-30 00:06:24 +0000551 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000552
553 /// \brief Build a new block pointer type given its pointee type.
554 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000555 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000556 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000557 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000558
John McCall85737a72009-10-30 00:06:24 +0000559 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000560 ///
John McCall85737a72009-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 Gregor577f75a2009-08-04 16:50:30 +0000564 ///
John McCall85737a72009-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 Stump1eb44332009-09-09 15:08:12 +0000570
Douglas Gregor577f75a2009-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 McCall85737a72009-10-30 00:06:24 +0000576 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
577 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000578
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000585 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000592
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000598 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000599 ArrayType::ArraySizeModifier SizeMod,
600 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000601 unsigned IndexTypeQuals,
602 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000603
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000609 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000610 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000611 unsigned IndexTypeQuals,
612 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000613
Mike Stump1eb44332009-09-09 15:08:12 +0000614 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000619 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000620 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000621 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000622 unsigned IndexTypeQuals,
623 SourceRange BracketsRange);
624
Mike Stump1eb44332009-09-09 15:08:12 +0000625 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000630 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000631 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000632 Expr *SizeExpr,
Douglas Gregor577f75a2009-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 Thompson82287d12010-02-05 00:12:22 +0000641 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000642 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000643
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000651
652 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000657 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000658 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000659 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000660
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000666 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000667 unsigned NumParamTypes,
Eli Friedmanfa869542010-08-05 02:54:05 +0000668 bool Variadic, unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000669 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000670 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000671
John McCalla2becad2009-10-21 00:40:46 +0000672 /// \brief Build a new unprototyped function type.
673 QualType RebuildFunctionNoProtoType(QualType ResultType);
674
John McCalled976492009-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 Gregor577f75a2009-08-04 16:50:30 +0000679 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000680 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-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 McCall7da24312009-09-05 00:15:47 +0000693
Mike Stump1eb44332009-09-09 15:08:12 +0000694 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-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 McCall2a984ca2010-10-12 00:20:44 +0000698 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000699
Mike Stump1eb44332009-09-09 15:08:12 +0000700 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000701 ///
702 /// By default, builds a new TypeOfType with the given underlying type.
703 QualType RebuildTypeOfType(QualType Underlying);
704
Sean Huntca63c202011-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 Stump1eb44332009-09-09 15:08:12 +0000710 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-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 McCall2a984ca2010-10-12 00:20:44 +0000714 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000715
Richard Smith34b41d92011-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 Gregor577f75a2009-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 McCall833ca992009-10-29 08:12:44 +0000729 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000730 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000731
Abramo Bagnara075f8f12010-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 Gregor577f75a2009-08-04 16:50:30 +0000740 /// \brief Build a new qualified name type.
741 ///
Abramo Bagnara465d41b2010-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 McCall21e413f2010-11-04 19:04:38 +0000745 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
746 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000747 NestedNameSpecifierLoc QualifierLoc,
748 QualType Named) {
749 return SemaRef.Context.getElaboratedType(Keyword,
750 QualifierLoc.getNestedNameSpecifier(),
751 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000752 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000753
754 /// \brief Build a new typename type that refers to a template-id.
755 ///
Abramo Bagnarae4da7a02010-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 McCall33500952010-06-11 00:33:02 +0000759 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000760 ElaboratedTypeKeyword Keyword,
761 NestedNameSpecifierLoc QualifierLoc,
762 const IdentifierInfo *Name,
763 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000764 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000765 // Rebuild the template name.
766 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000767 CXXScopeSpec SS;
768 SS.Adopt(QualifierLoc);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000769 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000770 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregor94fdffa2011-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 Gregor577f75a2009-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 Bagnarae4da7a02010-05-19 21:37:53 +0000799 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000800 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000801 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000802 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000803 NestedNameSpecifierLoc QualifierLoc,
804 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000805 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000806 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000807 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000808
Douglas Gregor2494dd02011-03-01 01:34:45 +0000809 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-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 Gregor2494dd02011-03-01 01:34:45 +0000812 return SemaRef.Context.getDependentNameType(Keyword,
813 QualifierLoc.getNestedNameSpecifier(),
814 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000815 }
816
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000817 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000818 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000819 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000820
821 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
822
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000823 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000824 // into a non-dependent elaborated-type-specifier. Find the tag we're
825 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000826 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000827 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
828 if (!DC)
829 return QualType();
830
John McCall56138762010-05-27 06:40:31 +0000831 if (SemaRef.RequireCompleteDeclContext(SS, DC))
832 return QualType();
833
Douglas Gregor40336422010-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;
Sean Huntc3021132010-05-05 15:23:54 +0000840
Douglas Gregor40336422010-03-31 22:19:08 +0000841 case LookupResult::Found:
842 Tag = Result.getAsSingle<TagDecl>();
843 break;
Sean Huntc3021132010-05-05 15:23:54 +0000844
Douglas Gregor40336422010-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();
Sean Huntc3021132010-05-05 15:23:54 +0000849
Douglas Gregor40336422010-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 Lewycky446e4022011-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 Smith3e4c6c42011-05-05 21:57:07 +0000864 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000865 unsigned Kind = 0;
866 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000867 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
868 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-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 Smith3e4c6c42011-05-05 21:57:07 +0000872 }
Nick Lewycky446e4022011-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 Gregor40336422010-03-31 22:19:08 +0000879 return QualType();
880 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000881
Richard Trieubbf34c02011-06-10 03:11:26 +0000882 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
883 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000884 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-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 Gregor2494dd02011-03-01 01:34:45 +0000891 return SemaRef.Context.getElaboratedType(Keyword,
892 QualifierLoc.getNestedNameSpecifier(),
893 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000894 }
Mike Stump1eb44332009-09-09 15:08:12 +0000895
Douglas Gregor2fc1bb72011-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 Gregorcded4f62011-01-14 17:04:44 +0000902 SourceLocation EllipsisLoc,
903 llvm::Optional<unsigned> NumExpansions) {
904 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
905 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000906 }
907
Eli Friedmanb001de72011-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 Gregord1067e52009-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 Gregorfd4ffeb2011-03-02 18:07:45 +0000920 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000921 bool TemplateKW,
922 TemplateDecl *Template);
923
Douglas Gregord1067e52009-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 Gregorfd4ffeb2011-03-02 18:07:45 +0000931 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
932 const IdentifierInfo &Name,
933 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000934 QualType ObjectType,
935 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000936
Douglas Gregorca1bdd72009-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 Gregorfd4ffeb2011-03-02 18:07:45 +0000944 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000945 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000946 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000947 QualType ObjectType);
Douglas Gregor1aee05d2011-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 Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +0000965 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000966 MultiStmtArg Statements,
967 SourceLocation RBraceLoc,
968 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000969 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +0000977 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000978 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000979 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000980 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000981 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000982 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000983 ColonLoc);
984 }
Mike Stump1eb44332009-09-09 15:08:12 +0000985
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +0000990 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000991 getSema().ActOnCaseStmtBody(S, Body);
992 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000993 }
Mike Stump1eb44332009-09-09 15:08:12 +0000994
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +0000999 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001000 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001001 Stmt *SubStmt) {
1002 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001003 /*CurScope=*/0);
1004 }
Mike Stump1eb44332009-09-09 15:08:12 +00001005
Douglas Gregor43959a92009-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 Lattner57ad3782011-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 Gregor43959a92009-08-20 07:17:43 +00001013 }
Mike Stump1eb44332009-09-09 15:08:12 +00001014
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +00001019 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattner57ad3782011-02-17 20:34:02 +00001020 VarDecl *CondVar, Stmt *Then,
1021 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001022 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001023 }
Mike Stump1eb44332009-09-09 15:08:12 +00001024
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +00001029 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001030 Expr *Cond, VarDecl *CondVar) {
John McCall9ae2f072010-08-23 23:25:46 +00001031 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001032 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001033 }
Mike Stump1eb44332009-09-09 15:08:12 +00001034
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +00001039 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001040 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001041 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-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 Lattner57ad3782011-02-17 20:34:02 +00001048 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1049 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001050 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001051 }
Mike Stump1eb44332009-09-09 15:08:12 +00001052
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +00001057 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001058 SourceLocation WhileLoc, SourceLocation LParenLoc,
1059 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001060 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1061 Cond, RParenLoc);
Douglas Gregor43959a92009-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 Lattnerad8dcf42011-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 McCall9ae2f072010-08-23 23:25:46 +00001072 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001073 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001074 }
Mike Stump1eb44332009-09-09 15:08:12 +00001075
Douglas Gregor43959a92009-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 Lattnerad8dcf42011-02-17 07:39:24 +00001080 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1081 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001082 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +00001089 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001090 SourceLocation StarLoc,
1091 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001092 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001093 }
Mike Stump1eb44332009-09-09 15:08:12 +00001094
Douglas Gregor43959a92009-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 Lattnerad8dcf42011-02-17 07:39:24 +00001099 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001100 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001101 }
Mike Stump1eb44332009-09-09 15:08:12 +00001102
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +00001107 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001108 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001109 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001110 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1111 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001112 }
Mike Stump1eb44332009-09-09 15:08:12 +00001113
Anders Carlsson703e3942010-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 McCall60d7b3a2010-08-24 06:29:42 +00001118 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001119 bool IsSimple,
1120 bool IsVolatile,
1121 unsigned NumOutputs,
1122 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001123 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001124 MultiExprArg Constraints,
1125 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001126 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001127 MultiExprArg Clobbers,
1128 SourceLocation RParenLoc,
1129 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001130 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001131 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001132 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001133 RParenLoc, MSAsm);
1134 }
Douglas Gregor4dfdd1b2010-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 McCall60d7b3a2010-08-24 06:29:42 +00001140 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001141 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001142 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001143 Stmt *Finally) {
1144 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1145 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001146 }
1147
Douglas Gregorbe270a02010-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 Bagnaraff676cb2011-03-08 08:55:46 +00001154 return getSema().BuildObjCExceptionDecl(TInfo, T,
1155 ExceptionDecl->getInnerLocStart(),
1156 ExceptionDecl->getLocation(),
1157 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001158 }
Sean Huntc3021132010-05-05 15:23:54 +00001159
Douglas Gregorbe270a02010-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 McCall60d7b3a2010-08-24 06:29:42 +00001164 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001165 SourceLocation RParenLoc,
1166 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001167 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001168 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001169 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001170 }
Sean Huntc3021132010-05-05 15:23:54 +00001171
Douglas Gregor4dfdd1b2010-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 McCall60d7b3a2010-08-24 06:29:42 +00001176 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001177 Stmt *Body) {
1178 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001179 }
Sean Huntc3021132010-05-05 15:23:54 +00001180
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001181 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-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 McCall60d7b3a2010-08-24 06:29:42 +00001185 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001186 Expr *Operand) {
1187 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001188 }
Sean Huntc3021132010-05-05 15:23:54 +00001189
John McCall07524032011-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 Gregor8fdc13a2010-04-22 22:01:21 +00001199 /// \brief Build a new Objective-C @synchronized statement.
1200 ///
Douglas Gregor8fdc13a2010-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 McCall60d7b3a2010-08-24 06:29:42 +00001203 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001204 Expr *Object, Stmt *Body) {
1205 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001206 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001207
John McCallf85e1932011-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 McCall990567c2011-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 McCallf85e1932011-06-15 23:02:42 +00001226
Douglas Gregorc3203e72010-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 McCall60d7b3a2010-08-24 06:29:42 +00001231 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001232 SourceLocation LParenLoc,
1233 Stmt *Element,
1234 Expr *Collection,
1235 SourceLocation RParenLoc,
1236 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001237 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001238 Element,
1239 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001240 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001241 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001242 }
Sean Huntc3021132010-05-05 15:23:54 +00001243
Douglas Gregor43959a92009-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 Bagnaraff676cb2011-03-08 08:55:46 +00001248 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001249 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001250 SourceLocation StartLoc,
1251 SourceLocation IdLoc,
1252 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-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 Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +00001264 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001265 VarDecl *ExceptionDecl,
1266 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001267 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1268 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001269 }
Mike Stump1eb44332009-09-09 15:08:12 +00001270
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +00001275 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001276 Stmt *TryBlock,
1277 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001278 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001279 }
Mike Stump1eb44332009-09-09 15:08:12 +00001280
Richard Smithad762fc2011-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 }
1294
1295 /// \brief Attach body to a C++0x range-based for statement.
1296 ///
1297 /// By default, performs semantic analysis to finish the new statement.
1298 /// Subclasses may override this routine to provide different behavior.
1299 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1300 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1301 }
1302
John Wiegley28bbe4b2011-04-28 01:08:34 +00001303 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1304 SourceLocation TryLoc,
1305 Stmt *TryBlock,
1306 Stmt *Handler) {
1307 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1308 }
1309
1310 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1311 Expr *FilterExpr,
1312 Stmt *Block) {
1313 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1314 }
1315
1316 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1317 Stmt *Block) {
1318 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1319 }
1320
Douglas Gregorb98b1992009-08-11 05:31:07 +00001321 /// \brief Build a new expression that references a declaration.
1322 ///
1323 /// By default, performs semantic analysis to build the new expression.
1324 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001325 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001326 LookupResult &R,
1327 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001328 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1329 }
1330
1331
1332 /// \brief Build a new expression that references a declaration.
1333 ///
1334 /// By default, performs semantic analysis to build the new expression.
1335 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001336 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001337 ValueDecl *VD,
1338 const DeclarationNameInfo &NameInfo,
1339 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001340 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001341 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001342
1343 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001344
1345 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001346 }
Mike Stump1eb44332009-09-09 15:08:12 +00001347
Douglas Gregorb98b1992009-08-11 05:31:07 +00001348 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001349 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001350 /// By default, performs semantic analysis to build the new expression.
1351 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001352 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001353 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001354 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001355 }
1356
Douglas Gregora71d8192009-09-04 17:36:40 +00001357 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001358 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001359 /// By default, performs semantic analysis to build the new expression.
1360 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001361 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001362 SourceLocation OperatorLoc,
1363 bool isArrow,
1364 CXXScopeSpec &SS,
1365 TypeSourceInfo *ScopeType,
1366 SourceLocation CCLoc,
1367 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001368 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001369
Douglas Gregorb98b1992009-08-11 05:31:07 +00001370 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001371 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001372 /// By default, performs semantic analysis to build the new expression.
1373 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001374 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001375 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001376 Expr *SubExpr) {
1377 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001378 }
Mike Stump1eb44332009-09-09 15:08:12 +00001379
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001380 /// \brief Build a new builtin offsetof expression.
1381 ///
1382 /// By default, performs semantic analysis to build the new expression.
1383 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001384 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001385 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001386 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001387 unsigned NumComponents,
1388 SourceLocation RParenLoc) {
1389 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1390 NumComponents, RParenLoc);
1391 }
Sean Huntc3021132010-05-05 15:23:54 +00001392
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001393 /// \brief Build a new sizeof, alignof or vec_step expression with a
1394 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001395 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001396 /// By default, performs semantic analysis to build the new expression.
1397 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001398 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1399 SourceLocation OpLoc,
1400 UnaryExprOrTypeTrait ExprKind,
1401 SourceRange R) {
1402 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001403 }
1404
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001405 /// \brief Build a new sizeof, alignof or vec step expression with an
1406 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001407 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001408 /// By default, performs semantic analysis to build the new expression.
1409 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001410 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1411 UnaryExprOrTypeTrait ExprKind,
1412 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001413 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001414 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001415 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001416 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001417
Douglas Gregorb98b1992009-08-11 05:31:07 +00001418 return move(Result);
1419 }
Mike Stump1eb44332009-09-09 15:08:12 +00001420
Douglas Gregorb98b1992009-08-11 05:31:07 +00001421 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001422 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001423 /// By default, performs semantic analysis to build the new expression.
1424 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001425 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001426 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001427 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001428 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001429 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1430 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001431 RBracketLoc);
1432 }
1433
1434 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001435 ///
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001438 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001439 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001440 SourceLocation RParenLoc,
1441 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001442 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001443 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001444 }
1445
1446 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001447 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001448 /// By default, performs semantic analysis to build the new expression.
1449 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001450 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001451 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001452 NestedNameSpecifierLoc QualifierLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001453 const DeclarationNameInfo &MemberNameInfo,
1454 ValueDecl *Member,
1455 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001456 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001457 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001458 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001459 // We have a reference to an unnamed field. This is always the
1460 // base of an anonymous struct/union member access, i.e. the
1461 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001462 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001463 assert(Member->getType()->isRecordType() &&
1464 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001465
John Wiegley429bb272011-04-08 18:41:53 +00001466 ExprResult BaseResult =
1467 getSema().PerformObjectMemberConversion(Base,
1468 QualifierLoc.getNestedNameSpecifier(),
1469 FoundDecl, Member);
1470 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001471 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001472 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001473 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001474 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001475 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001476 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001477 cast<FieldDecl>(Member)->getType(),
1478 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001479 return getSema().Owned(ME);
1480 }
Mike Stump1eb44332009-09-09 15:08:12 +00001481
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001482 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001483 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001484
John Wiegley429bb272011-04-08 18:41:53 +00001485 ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base);
1486 if (BaseResult.isInvalid())
1487 return ExprError();
1488 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001489 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001490
John McCall6bb80172010-03-30 21:47:33 +00001491 // FIXME: this involves duplicating earlier analysis in a lot of
1492 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001493 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001494 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001495 R.resolveKind();
1496
John McCall9ae2f072010-08-23 23:25:46 +00001497 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001498 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001499 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001500 }
Mike Stump1eb44332009-09-09 15:08:12 +00001501
Douglas Gregorb98b1992009-08-11 05:31:07 +00001502 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001503 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001504 /// By default, performs semantic analysis to build the new expression.
1505 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001506 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001507 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001508 Expr *LHS, Expr *RHS) {
1509 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001510 }
1511
1512 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001513 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001514 /// By default, performs semantic analysis to build the new expression.
1515 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001516 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001517 SourceLocation QuestionLoc,
1518 Expr *LHS,
1519 SourceLocation ColonLoc,
1520 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001521 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1522 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001523 }
1524
Douglas Gregorb98b1992009-08-11 05:31:07 +00001525 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001526 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001527 /// By default, performs semantic analysis to build the new expression.
1528 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001529 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001530 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001531 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001532 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001533 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001534 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001535 }
Mike Stump1eb44332009-09-09 15:08:12 +00001536
Douglas Gregorb98b1992009-08-11 05:31:07 +00001537 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001538 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001539 /// By default, performs semantic analysis to build the new expression.
1540 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001541 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001542 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001543 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001544 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001545 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001546 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001547 }
Mike Stump1eb44332009-09-09 15:08:12 +00001548
Douglas Gregorb98b1992009-08-11 05:31:07 +00001549 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001550 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001551 /// By default, performs semantic analysis to build the new expression.
1552 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001553 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001554 SourceLocation OpLoc,
1555 SourceLocation AccessorLoc,
1556 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001557
John McCall129e2df2009-11-30 22:42:35 +00001558 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001559 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001560 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001561 OpLoc, /*IsArrow*/ false,
1562 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001563 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001564 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001565 }
Mike Stump1eb44332009-09-09 15:08:12 +00001566
Douglas Gregorb98b1992009-08-11 05:31:07 +00001567 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001568 ///
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +00001571 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001572 MultiExprArg Inits,
1573 SourceLocation RBraceLoc,
1574 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001575 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001576 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1577 if (Result.isInvalid() || ResultTy->isDependentType())
1578 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001579
Douglas Gregore48319a2009-11-09 17:16:50 +00001580 // Patch in the result type we were given, which may have been computed
1581 // when the initial InitListExpr was built.
1582 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1583 ILE->setType(ResultTy);
1584 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001585 }
Mike Stump1eb44332009-09-09 15:08:12 +00001586
Douglas Gregorb98b1992009-08-11 05:31:07 +00001587 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001588 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001589 /// By default, performs semantic analysis to build the new expression.
1590 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001591 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001592 MultiExprArg ArrayExprs,
1593 SourceLocation EqualOrColonLoc,
1594 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001595 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001596 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001597 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001598 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001599 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001600 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001601
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 ArrayExprs.release();
1603 return move(Result);
1604 }
Mike Stump1eb44332009-09-09 15:08:12 +00001605
Douglas Gregorb98b1992009-08-11 05:31:07 +00001606 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001607 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001608 /// By default, builds the implicit value initialization without performing
1609 /// any semantic analysis. Subclasses may override this routine to provide
1610 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001611 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001612 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1613 }
Mike Stump1eb44332009-09-09 15:08:12 +00001614
Douglas Gregorb98b1992009-08-11 05:31:07 +00001615 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001616 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001617 /// By default, performs semantic analysis to build the new expression.
1618 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001619 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001620 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001621 SourceLocation RParenLoc) {
1622 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001623 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001624 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001625 }
1626
1627 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001628 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001629 /// By default, performs semantic analysis to build the new expression.
1630 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001631 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001632 MultiExprArg SubExprs,
1633 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001634 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001635 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001636 }
Mike Stump1eb44332009-09-09 15:08:12 +00001637
Douglas Gregorb98b1992009-08-11 05:31:07 +00001638 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001639 ///
1640 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001641 /// rather than attempting to map the label statement itself.
1642 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001643 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001644 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001645 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001646 }
Mike Stump1eb44332009-09-09 15:08:12 +00001647
Douglas Gregorb98b1992009-08-11 05:31:07 +00001648 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001649 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001650 /// By default, performs semantic analysis to build the new expression.
1651 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001652 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001653 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001654 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001655 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001656 }
Mike Stump1eb44332009-09-09 15:08:12 +00001657
Douglas Gregorb98b1992009-08-11 05:31:07 +00001658 /// \brief Build a new __builtin_choose_expr expression.
1659 ///
1660 /// By default, performs semantic analysis to build the new expression.
1661 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001662 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001663 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001664 SourceLocation RParenLoc) {
1665 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001666 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001667 RParenLoc);
1668 }
Mike Stump1eb44332009-09-09 15:08:12 +00001669
Peter Collingbournef111d932011-04-15 00:35:48 +00001670 /// \brief Build a new generic selection expression.
1671 ///
1672 /// By default, performs semantic analysis to build the new expression.
1673 /// Subclasses may override this routine to provide different behavior.
1674 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1675 SourceLocation DefaultLoc,
1676 SourceLocation RParenLoc,
1677 Expr *ControllingExpr,
1678 TypeSourceInfo **Types,
1679 Expr **Exprs,
1680 unsigned NumAssocs) {
1681 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1682 ControllingExpr, Types, Exprs,
1683 NumAssocs);
1684 }
1685
Douglas Gregorb98b1992009-08-11 05:31:07 +00001686 /// \brief Build a new overloaded operator call expression.
1687 ///
1688 /// By default, performs semantic analysis to build the new expression.
1689 /// The semantic analysis provides the behavior of template instantiation,
1690 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001691 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001692 /// argument-dependent lookup, etc. Subclasses may override this routine to
1693 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001694 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001695 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001696 Expr *Callee,
1697 Expr *First,
1698 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001699
1700 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001701 /// reinterpret_cast.
1702 ///
1703 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001704 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001705 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001706 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001707 Stmt::StmtClass Class,
1708 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001709 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 SourceLocation RAngleLoc,
1711 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001712 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001713 SourceLocation RParenLoc) {
1714 switch (Class) {
1715 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001716 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001717 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001718 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001719
1720 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001721 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001722 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001723 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001724
Douglas Gregorb98b1992009-08-11 05:31:07 +00001725 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001726 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001727 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001728 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001729 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001730
Douglas Gregorb98b1992009-08-11 05:31:07 +00001731 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001732 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001733 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001734 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001735
Douglas Gregorb98b1992009-08-11 05:31:07 +00001736 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001737 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001738 }
Mike Stump1eb44332009-09-09 15:08:12 +00001739
John McCallf312b1e2010-08-26 23:41:50 +00001740 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001741 }
Mike Stump1eb44332009-09-09 15:08:12 +00001742
Douglas Gregorb98b1992009-08-11 05:31:07 +00001743 /// \brief Build a new C++ static_cast expression.
1744 ///
1745 /// By default, performs semantic analysis to build the new expression.
1746 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001747 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001748 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001749 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001750 SourceLocation RAngleLoc,
1751 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001752 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001753 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001754 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001755 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001756 SourceRange(LAngleLoc, RAngleLoc),
1757 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001758 }
1759
1760 /// \brief Build a new C++ dynamic_cast expression.
1761 ///
1762 /// By default, performs semantic analysis to build the new expression.
1763 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001764 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001765 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001766 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001767 SourceLocation RAngleLoc,
1768 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001769 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001770 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001771 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001772 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001773 SourceRange(LAngleLoc, RAngleLoc),
1774 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001775 }
1776
1777 /// \brief Build a new C++ reinterpret_cast expression.
1778 ///
1779 /// By default, performs semantic analysis to build the new expression.
1780 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001781 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001782 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001783 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001784 SourceLocation RAngleLoc,
1785 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001786 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001787 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001788 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001789 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001790 SourceRange(LAngleLoc, RAngleLoc),
1791 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001792 }
1793
1794 /// \brief Build a new C++ const_cast expression.
1795 ///
1796 /// By default, performs semantic analysis to build the new expression.
1797 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001798 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001799 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001800 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001801 SourceLocation RAngleLoc,
1802 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001803 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001804 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001805 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001806 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001807 SourceRange(LAngleLoc, RAngleLoc),
1808 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001809 }
Mike Stump1eb44332009-09-09 15:08:12 +00001810
Douglas Gregorb98b1992009-08-11 05:31:07 +00001811 /// \brief Build a new C++ functional-style cast expression.
1812 ///
1813 /// By default, performs semantic analysis to build the new expression.
1814 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001815 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1816 SourceLocation LParenLoc,
1817 Expr *Sub,
1818 SourceLocation RParenLoc) {
1819 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001820 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001821 RParenLoc);
1822 }
Mike Stump1eb44332009-09-09 15:08:12 +00001823
Douglas Gregorb98b1992009-08-11 05:31:07 +00001824 /// \brief Build a new C++ typeid(type) expression.
1825 ///
1826 /// By default, performs semantic analysis to build the new expression.
1827 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001828 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001829 SourceLocation TypeidLoc,
1830 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001831 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001832 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001833 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001834 }
Mike Stump1eb44332009-09-09 15:08:12 +00001835
Francois Pichet01b7c302010-09-08 12:20:18 +00001836
Douglas Gregorb98b1992009-08-11 05:31:07 +00001837 /// \brief Build a new C++ typeid(expr) expression.
1838 ///
1839 /// By default, performs semantic analysis to build the new expression.
1840 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001841 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001842 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001843 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001844 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001845 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001846 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001847 }
1848
Francois Pichet01b7c302010-09-08 12:20:18 +00001849 /// \brief Build a new C++ __uuidof(type) expression.
1850 ///
1851 /// By default, performs semantic analysis to build the new expression.
1852 /// Subclasses may override this routine to provide different behavior.
1853 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1854 SourceLocation TypeidLoc,
1855 TypeSourceInfo *Operand,
1856 SourceLocation RParenLoc) {
1857 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1858 RParenLoc);
1859 }
1860
1861 /// \brief Build a new C++ __uuidof(expr) expression.
1862 ///
1863 /// By default, performs semantic analysis to build the new expression.
1864 /// Subclasses may override this routine to provide different behavior.
1865 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1866 SourceLocation TypeidLoc,
1867 Expr *Operand,
1868 SourceLocation RParenLoc) {
1869 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1870 RParenLoc);
1871 }
1872
Douglas Gregorb98b1992009-08-11 05:31:07 +00001873 /// \brief Build a new C++ "this" expression.
1874 ///
1875 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001876 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001877 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001878 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001879 QualType ThisType,
1880 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001881 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001882 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1883 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001884 }
1885
1886 /// \brief Build a new C++ throw expression.
1887 ///
1888 /// By default, performs semantic analysis to build the new expression.
1889 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001890 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1891 bool IsThrownVariableInScope) {
1892 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001893 }
1894
1895 /// \brief Build a new C++ default-argument expression.
1896 ///
1897 /// By default, builds a new default-argument expression, which does not
1898 /// require any semantic analysis. Subclasses may override this routine to
1899 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001900 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001901 ParmVarDecl *Param) {
1902 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1903 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001904 }
1905
1906 /// \brief Build a new C++ zero-initialization expression.
1907 ///
1908 /// By default, performs semantic analysis to build the new expression.
1909 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001910 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1911 SourceLocation LParenLoc,
1912 SourceLocation RParenLoc) {
1913 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001914 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001915 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001916 }
Mike Stump1eb44332009-09-09 15:08:12 +00001917
Douglas Gregorb98b1992009-08-11 05:31:07 +00001918 /// \brief Build a new C++ "new" expression.
1919 ///
1920 /// By default, performs semantic analysis to build the new expression.
1921 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001922 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001923 bool UseGlobal,
1924 SourceLocation PlacementLParen,
1925 MultiExprArg PlacementArgs,
1926 SourceLocation PlacementRParen,
1927 SourceRange TypeIdParens,
1928 QualType AllocatedType,
1929 TypeSourceInfo *AllocatedTypeInfo,
1930 Expr *ArraySize,
1931 SourceLocation ConstructorLParen,
1932 MultiExprArg ConstructorArgs,
1933 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001934 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001935 PlacementLParen,
1936 move(PlacementArgs),
1937 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001938 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001939 AllocatedType,
1940 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001941 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001942 ConstructorLParen,
1943 move(ConstructorArgs),
1944 ConstructorRParen);
1945 }
Mike Stump1eb44332009-09-09 15:08:12 +00001946
Douglas Gregorb98b1992009-08-11 05:31:07 +00001947 /// \brief Build a new C++ "delete" expression.
1948 ///
1949 /// By default, performs semantic analysis to build the new expression.
1950 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001951 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001952 bool IsGlobalDelete,
1953 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001954 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001955 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001956 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001957 }
Mike Stump1eb44332009-09-09 15:08:12 +00001958
Douglas Gregorb98b1992009-08-11 05:31:07 +00001959 /// \brief Build a new unary type trait expression.
1960 ///
1961 /// By default, performs semantic analysis to build the new expression.
1962 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001963 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001964 SourceLocation StartLoc,
1965 TypeSourceInfo *T,
1966 SourceLocation RParenLoc) {
1967 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001968 }
1969
Francois Pichet6ad6f282010-12-07 00:08:36 +00001970 /// \brief Build a new binary type trait expression.
1971 ///
1972 /// By default, performs semantic analysis to build the new expression.
1973 /// Subclasses may override this routine to provide different behavior.
1974 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1975 SourceLocation StartLoc,
1976 TypeSourceInfo *LhsT,
1977 TypeSourceInfo *RhsT,
1978 SourceLocation RParenLoc) {
1979 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1980 }
1981
John Wiegley21ff2e52011-04-28 00:16:57 +00001982 /// \brief Build a new array type trait expression.
1983 ///
1984 /// By default, performs semantic analysis to build the new expression.
1985 /// Subclasses may override this routine to provide different behavior.
1986 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
1987 SourceLocation StartLoc,
1988 TypeSourceInfo *TSInfo,
1989 Expr *DimExpr,
1990 SourceLocation RParenLoc) {
1991 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
1992 }
1993
John Wiegley55262202011-04-25 06:54:41 +00001994 /// \brief Build a new expression trait expression.
1995 ///
1996 /// By default, performs semantic analysis to build the new expression.
1997 /// Subclasses may override this routine to provide different behavior.
1998 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
1999 SourceLocation StartLoc,
2000 Expr *Queried,
2001 SourceLocation RParenLoc) {
2002 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2003 }
2004
Mike Stump1eb44332009-09-09 15:08:12 +00002005 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002006 /// expression.
2007 ///
2008 /// By default, performs semantic analysis to build the new expression.
2009 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002010 ExprResult RebuildDependentScopeDeclRefExpr(
2011 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002012 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002013 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002014 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002015 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002016
2017 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00002018 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002019 *TemplateArgs);
2020
Abramo Bagnara25777432010-08-11 22:01:17 +00002021 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002022 }
2023
2024 /// \brief Build a new template-id expression.
2025 ///
2026 /// By default, performs semantic analysis to build the new expression.
2027 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002028 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00002029 LookupResult &R,
2030 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00002031 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00002032 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002033 }
2034
2035 /// \brief Build a new object-construction expression.
2036 ///
2037 /// By default, performs semantic analysis to build the new expression.
2038 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002039 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002040 SourceLocation Loc,
2041 CXXConstructorDecl *Constructor,
2042 bool IsElidable,
2043 MultiExprArg Args,
2044 bool HadMultipleCandidates,
2045 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002046 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002047 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00002048 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00002049 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002050 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002051 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002052
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002053 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002054 move_arg(ConvertedArgs),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002055 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002056 RequiresZeroInit, ConstructKind,
2057 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002058 }
2059
2060 /// \brief Build a new object-construction expression.
2061 ///
2062 /// By default, performs semantic analysis to build the new expression.
2063 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002064 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2065 SourceLocation LParenLoc,
2066 MultiExprArg Args,
2067 SourceLocation RParenLoc) {
2068 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002069 LParenLoc,
2070 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002071 RParenLoc);
2072 }
2073
2074 /// \brief Build a new object-construction expression.
2075 ///
2076 /// By default, performs semantic analysis to build the new expression.
2077 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002078 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2079 SourceLocation LParenLoc,
2080 MultiExprArg Args,
2081 SourceLocation RParenLoc) {
2082 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002083 LParenLoc,
2084 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002085 RParenLoc);
2086 }
Mike Stump1eb44332009-09-09 15:08:12 +00002087
Douglas Gregorb98b1992009-08-11 05:31:07 +00002088 /// \brief Build a new member reference expression.
2089 ///
2090 /// By default, performs semantic analysis to build the new expression.
2091 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002092 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002093 QualType BaseType,
2094 bool IsArrow,
2095 SourceLocation OperatorLoc,
2096 NestedNameSpecifierLoc QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00002097 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002098 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002099 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002100 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002101 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002102
John McCall9ae2f072010-08-23 23:25:46 +00002103 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002104 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00002105 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002106 MemberNameInfo,
2107 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002108 }
2109
John McCall129e2df2009-11-30 22:42:35 +00002110 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002111 ///
2112 /// By default, performs semantic analysis to build the new expression.
2113 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002114 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00002115 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00002116 SourceLocation OperatorLoc,
2117 bool IsArrow,
Douglas Gregor4c9be892011-02-28 20:01:57 +00002118 NestedNameSpecifierLoc QualifierLoc,
John McCallc2233c52010-01-15 08:34:02 +00002119 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00002120 LookupResult &R,
2121 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002122 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002123 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002124
John McCall9ae2f072010-08-23 23:25:46 +00002125 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002126 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00002127 SS, FirstQualifierInScope,
2128 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002129 }
Mike Stump1eb44332009-09-09 15:08:12 +00002130
Sebastian Redl2e156222010-09-10 20:55:43 +00002131 /// \brief Build a new noexcept expression.
2132 ///
2133 /// By default, performs semantic analysis to build the new expression.
2134 /// Subclasses may override this routine to provide different behavior.
2135 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2136 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2137 }
2138
Douglas Gregoree8aff02011-01-04 17:33:58 +00002139 /// \brief Build a new expression to compute the length of a parameter pack.
2140 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2141 SourceLocation PackLoc,
2142 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002143 llvm::Optional<unsigned> Length) {
2144 if (Length)
2145 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2146 OperatorLoc, Pack, PackLoc,
2147 RParenLoc, *Length);
2148
Douglas Gregoree8aff02011-01-04 17:33:58 +00002149 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2150 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002151 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002152 }
2153
Douglas Gregorb98b1992009-08-11 05:31:07 +00002154 /// \brief Build a new Objective-C @encode expression.
2155 ///
2156 /// By default, performs semantic analysis to build the new expression.
2157 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002158 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002159 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002160 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002161 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002162 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002163 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002164
Douglas Gregor92e986e2010-04-22 16:44:27 +00002165 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002166 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002167 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002168 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002169 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002170 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002171 MultiExprArg Args,
2172 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002173 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2174 ReceiverTypeInfo->getType(),
2175 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002176 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002177 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002178 }
2179
2180 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002181 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002182 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002183 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002184 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002185 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002186 MultiExprArg Args,
2187 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002188 return SemaRef.BuildInstanceMessage(Receiver,
2189 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002190 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002191 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002192 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002193 }
2194
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002195 /// \brief Build a new Objective-C ivar reference expression.
2196 ///
2197 /// By default, performs semantic analysis to build the new expression.
2198 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002199 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002200 SourceLocation IvarLoc,
2201 bool IsArrow, bool IsFreeIvar) {
2202 // FIXME: We lose track of the IsFreeIvar bit.
2203 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002204 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002205 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2206 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002207 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002208 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002209 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002210 false);
John Wiegley429bb272011-04-08 18:41:53 +00002211 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002212 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002213
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002214 if (Result.get())
2215 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002216
John Wiegley429bb272011-04-08 18:41:53 +00002217 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002218 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002219 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002220 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002221 /*TemplateArgs=*/0);
2222 }
Douglas Gregore3303542010-04-26 20:47:02 +00002223
2224 /// \brief Build a new Objective-C property reference expression.
2225 ///
2226 /// By default, performs semantic analysis to build the new expression.
2227 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002228 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00002229 ObjCPropertyDecl *Property,
2230 SourceLocation PropertyLoc) {
2231 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002232 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002233 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2234 Sema::LookupMemberName);
2235 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002236 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002237 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002238 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002239 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002240 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002241
Douglas Gregore3303542010-04-26 20:47:02 +00002242 if (Result.get())
2243 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002244
John Wiegley429bb272011-04-08 18:41:53 +00002245 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002246 /*FIXME:*/PropertyLoc, IsArrow,
2247 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00002248 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002249 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002250 /*TemplateArgs=*/0);
2251 }
Sean Huntc3021132010-05-05 15:23:54 +00002252
John McCall12f78a62010-12-02 01:19:52 +00002253 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002254 ///
2255 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002256 /// Subclasses may override this routine to provide different behavior.
2257 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2258 ObjCMethodDecl *Getter,
2259 ObjCMethodDecl *Setter,
2260 SourceLocation PropertyLoc) {
2261 // Since these expressions can only be value-dependent, we do not
2262 // need to perform semantic analysis again.
2263 return Owned(
2264 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2265 VK_LValue, OK_ObjCProperty,
2266 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002267 }
2268
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002269 /// \brief Build a new Objective-C "isa" expression.
2270 ///
2271 /// By default, performs semantic analysis to build the new expression.
2272 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002273 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002274 bool IsArrow) {
2275 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002276 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002277 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2278 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002279 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002280 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002281 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002282 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002283 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002284
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002285 if (Result.get())
2286 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002287
John Wiegley429bb272011-04-08 18:41:53 +00002288 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002289 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002290 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002291 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002292 /*TemplateArgs=*/0);
2293 }
Sean Huntc3021132010-05-05 15:23:54 +00002294
Douglas Gregorb98b1992009-08-11 05:31:07 +00002295 /// \brief Build a new shuffle vector expression.
2296 ///
2297 /// By default, performs semantic analysis to build the new expression.
2298 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002299 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002300 MultiExprArg SubExprs,
2301 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002302 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002303 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002304 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2305 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2306 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2307 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002308
Douglas Gregorb98b1992009-08-11 05:31:07 +00002309 // Build a reference to the __builtin_shufflevector builtin
2310 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002311 ExprResult Callee
2312 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2313 VK_LValue, BuiltinLoc));
2314 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2315 if (Callee.isInvalid())
2316 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002317
2318 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002319 unsigned NumSubExprs = SubExprs.size();
2320 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002321 ExprResult TheCall = SemaRef.Owned(
2322 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002323 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002324 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002325 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002326 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002327
Douglas Gregorb98b1992009-08-11 05:31:07 +00002328 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002329 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002330 }
John McCall43fed0d2010-11-12 08:19:04 +00002331
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002332 /// \brief Build a new template argument pack expansion.
2333 ///
2334 /// By default, performs semantic analysis to build a new pack expansion
2335 /// for a template argument. Subclasses may override this routine to provide
2336 /// different behavior.
2337 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002338 SourceLocation EllipsisLoc,
2339 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002340 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002341 case TemplateArgument::Expression: {
2342 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002343 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2344 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002345 if (Result.isInvalid())
2346 return TemplateArgumentLoc();
2347
2348 return TemplateArgumentLoc(Result.get(), Result.get());
2349 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002350
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002351 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002352 return TemplateArgumentLoc(TemplateArgument(
2353 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002354 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002355 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002356 Pattern.getTemplateNameLoc(),
2357 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002358
2359 case TemplateArgument::Null:
2360 case TemplateArgument::Integral:
2361 case TemplateArgument::Declaration:
2362 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002363 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002364 llvm_unreachable("Pack expansion pattern has no parameter packs");
2365
2366 case TemplateArgument::Type:
2367 if (TypeSourceInfo *Expansion
2368 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002369 EllipsisLoc,
2370 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002371 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2372 Expansion);
2373 break;
2374 }
2375
2376 return TemplateArgumentLoc();
2377 }
2378
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002379 /// \brief Build a new expression pack expansion.
2380 ///
2381 /// By default, performs semantic analysis to build a new pack expansion
2382 /// for an expression. Subclasses may override this routine to provide
2383 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002384 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2385 llvm::Optional<unsigned> NumExpansions) {
2386 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002387 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002388
2389 /// \brief Build a new atomic operation expression.
2390 ///
2391 /// By default, performs semantic analysis to build the new expression.
2392 /// Subclasses may override this routine to provide different behavior.
2393 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2394 MultiExprArg SubExprs,
2395 QualType RetTy,
2396 AtomicExpr::AtomicOp Op,
2397 SourceLocation RParenLoc) {
2398 // Just create the expression; there is not any interesting semantic
2399 // analysis here because we can't actually build an AtomicExpr until
2400 // we are sure it is semantically sound.
2401 unsigned NumSubExprs = SubExprs.size();
2402 Expr **Subs = (Expr **)SubExprs.release();
2403 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2404 NumSubExprs, RetTy, Op,
2405 RParenLoc);
2406 }
2407
John McCall43fed0d2010-11-12 08:19:04 +00002408private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002409 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2410 QualType ObjectType,
2411 NamedDecl *FirstQualifierInScope,
2412 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002413
2414 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2415 QualType ObjectType,
2416 NamedDecl *FirstQualifierInScope,
2417 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002418};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002419
Douglas Gregor43959a92009-08-20 07:17:43 +00002420template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002421StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002422 if (!S)
2423 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002424
Douglas Gregor43959a92009-08-20 07:17:43 +00002425 switch (S->getStmtClass()) {
2426 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002427
Douglas Gregor43959a92009-08-20 07:17:43 +00002428 // Transform individual statement nodes
2429#define STMT(Node, Parent) \
2430 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002431#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002432#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002433#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002434
Douglas Gregor43959a92009-08-20 07:17:43 +00002435 // Transform expressions by calling TransformExpr.
2436#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002437#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002438#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002439#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002440 {
John McCall60d7b3a2010-08-24 06:29:42 +00002441 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002442 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002443 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002444
John McCall9ae2f072010-08-23 23:25:46 +00002445 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002446 }
Mike Stump1eb44332009-09-09 15:08:12 +00002447 }
2448
John McCall3fa5cae2010-10-26 07:05:15 +00002449 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002450}
Mike Stump1eb44332009-09-09 15:08:12 +00002451
2452
Douglas Gregor670444e2009-08-04 22:27:00 +00002453template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002454ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002455 if (!E)
2456 return SemaRef.Owned(E);
2457
2458 switch (E->getStmtClass()) {
2459 case Stmt::NoStmtClass: break;
2460#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002461#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002462#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002463 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002464#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002465 }
2466
John McCall3fa5cae2010-10-26 07:05:15 +00002467 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002468}
2469
2470template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002471bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2472 unsigned NumInputs,
2473 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002474 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002475 bool *ArgChanged) {
2476 for (unsigned I = 0; I != NumInputs; ++I) {
2477 // If requested, drop call arguments that need to be dropped.
2478 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2479 if (ArgChanged)
2480 *ArgChanged = true;
2481
2482 break;
2483 }
2484
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002485 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2486 Expr *Pattern = Expansion->getPattern();
2487
Chris Lattner686775d2011-07-20 06:58:45 +00002488 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002489 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2490 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2491
2492 // Determine whether the set of unexpanded parameter packs can and should
2493 // be expanded.
2494 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002495 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002496 llvm::Optional<unsigned> OrigNumExpansions
2497 = Expansion->getNumExpansions();
2498 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002499 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2500 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002501 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002502 Expand, RetainExpansion,
2503 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002504 return true;
2505
2506 if (!Expand) {
2507 // The transform has determined that we should perform a simple
2508 // transformation on the pack expansion, producing another pack
2509 // expansion.
2510 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2511 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2512 if (OutPattern.isInvalid())
2513 return true;
2514
2515 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002516 Expansion->getEllipsisLoc(),
2517 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002518 if (Out.isInvalid())
2519 return true;
2520
2521 if (ArgChanged)
2522 *ArgChanged = true;
2523 Outputs.push_back(Out.get());
2524 continue;
2525 }
John McCallc8fc90a2011-07-06 07:30:07 +00002526
2527 // Record right away that the argument was changed. This needs
2528 // to happen even if the array expands to nothing.
2529 if (ArgChanged) *ArgChanged = true;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002530
2531 // The transform has determined that we should perform an elementwise
2532 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002533 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002534 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2535 ExprResult Out = getDerived().TransformExpr(Pattern);
2536 if (Out.isInvalid())
2537 return true;
2538
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002539 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002540 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2541 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002542 if (Out.isInvalid())
2543 return true;
2544 }
2545
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002546 Outputs.push_back(Out.get());
2547 }
2548
2549 continue;
2550 }
2551
Douglas Gregoraa165f82011-01-03 19:04:46 +00002552 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2553 if (Result.isInvalid())
2554 return true;
2555
2556 if (Result.get() != Inputs[I] && ArgChanged)
2557 *ArgChanged = true;
2558
2559 Outputs.push_back(Result.get());
2560 }
2561
2562 return false;
2563}
2564
2565template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002566NestedNameSpecifierLoc
2567TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2568 NestedNameSpecifierLoc NNS,
2569 QualType ObjectType,
2570 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002571 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002572 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2573 Qualifier = Qualifier.getPrefix())
2574 Qualifiers.push_back(Qualifier);
2575
2576 CXXScopeSpec SS;
2577 while (!Qualifiers.empty()) {
2578 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2579 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2580
2581 switch (QNNS->getKind()) {
2582 case NestedNameSpecifier::Identifier:
2583 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2584 *QNNS->getAsIdentifier(),
2585 Q.getLocalBeginLoc(),
2586 Q.getLocalEndLoc(),
2587 ObjectType, false, SS,
2588 FirstQualifierInScope, false))
2589 return NestedNameSpecifierLoc();
2590
2591 break;
2592
2593 case NestedNameSpecifier::Namespace: {
2594 NamespaceDecl *NS
2595 = cast_or_null<NamespaceDecl>(
2596 getDerived().TransformDecl(
2597 Q.getLocalBeginLoc(),
2598 QNNS->getAsNamespace()));
2599 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2600 break;
2601 }
2602
2603 case NestedNameSpecifier::NamespaceAlias: {
2604 NamespaceAliasDecl *Alias
2605 = cast_or_null<NamespaceAliasDecl>(
2606 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2607 QNNS->getAsNamespaceAlias()));
2608 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2609 Q.getLocalEndLoc());
2610 break;
2611 }
2612
2613 case NestedNameSpecifier::Global:
2614 // There is no meaningful transformation that one could perform on the
2615 // global scope.
2616 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2617 break;
2618
2619 case NestedNameSpecifier::TypeSpecWithTemplate:
2620 case NestedNameSpecifier::TypeSpec: {
2621 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2622 FirstQualifierInScope, SS);
2623
2624 if (!TL)
2625 return NestedNameSpecifierLoc();
2626
2627 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2628 (SemaRef.getLangOptions().CPlusPlus0x &&
2629 TL.getType()->isEnumeralType())) {
2630 assert(!TL.getType().hasLocalQualifiers() &&
2631 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002632 if (TL.getType()->isEnumeralType())
2633 SemaRef.Diag(TL.getBeginLoc(),
2634 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002635 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2636 Q.getLocalEndLoc());
2637 break;
2638 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002639 // If the nested-name-specifier is an invalid type def, don't emit an
2640 // error because a previous error should have already been emitted.
2641 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2642 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2643 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2644 << TL.getType() << SS.getRange();
2645 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002646 return NestedNameSpecifierLoc();
2647 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002648 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002649
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002650 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002651 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002652 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002653 }
2654
2655 // Don't rebuild the nested-name-specifier if we don't have to.
2656 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2657 !getDerived().AlwaysRebuild())
2658 return NNS;
2659
2660 // If we can re-use the source-location data from the original
2661 // nested-name-specifier, do so.
2662 if (SS.location_size() == NNS.getDataLength() &&
2663 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2664 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2665
2666 // Allocate new nested-name-specifier location information.
2667 return SS.getWithLocInContext(SemaRef.Context);
2668}
2669
2670template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002671DeclarationNameInfo
2672TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002673::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002674 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002675 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002676 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002677
2678 switch (Name.getNameKind()) {
2679 case DeclarationName::Identifier:
2680 case DeclarationName::ObjCZeroArgSelector:
2681 case DeclarationName::ObjCOneArgSelector:
2682 case DeclarationName::ObjCMultiArgSelector:
2683 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002684 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002685 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002686 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002687
Douglas Gregor81499bb2009-09-03 22:13:48 +00002688 case DeclarationName::CXXConstructorName:
2689 case DeclarationName::CXXDestructorName:
2690 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002691 TypeSourceInfo *NewTInfo;
2692 CanQualType NewCanTy;
2693 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002694 NewTInfo = getDerived().TransformType(OldTInfo);
2695 if (!NewTInfo)
2696 return DeclarationNameInfo();
2697 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002698 }
2699 else {
2700 NewTInfo = 0;
2701 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002702 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002703 if (NewT.isNull())
2704 return DeclarationNameInfo();
2705 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2706 }
Mike Stump1eb44332009-09-09 15:08:12 +00002707
Abramo Bagnara25777432010-08-11 22:01:17 +00002708 DeclarationName NewName
2709 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2710 NewCanTy);
2711 DeclarationNameInfo NewNameInfo(NameInfo);
2712 NewNameInfo.setName(NewName);
2713 NewNameInfo.setNamedTypeInfo(NewTInfo);
2714 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002715 }
Mike Stump1eb44332009-09-09 15:08:12 +00002716 }
2717
David Blaikieb219cfc2011-09-23 05:06:16 +00002718 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002719}
2720
2721template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002722TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002723TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2724 TemplateName Name,
2725 SourceLocation NameLoc,
2726 QualType ObjectType,
2727 NamedDecl *FirstQualifierInScope) {
2728 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2729 TemplateDecl *Template = QTN->getTemplateDecl();
2730 assert(Template && "qualified template name must refer to a template");
2731
2732 TemplateDecl *TransTemplate
2733 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2734 Template));
2735 if (!TransTemplate)
2736 return TemplateName();
2737
2738 if (!getDerived().AlwaysRebuild() &&
2739 SS.getScopeRep() == QTN->getQualifier() &&
2740 TransTemplate == Template)
2741 return Name;
2742
2743 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2744 TransTemplate);
2745 }
2746
2747 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2748 if (SS.getScopeRep()) {
2749 // These apply to the scope specifier, not the template.
2750 ObjectType = QualType();
2751 FirstQualifierInScope = 0;
2752 }
2753
2754 if (!getDerived().AlwaysRebuild() &&
2755 SS.getScopeRep() == DTN->getQualifier() &&
2756 ObjectType.isNull())
2757 return Name;
2758
2759 if (DTN->isIdentifier()) {
2760 return getDerived().RebuildTemplateName(SS,
2761 *DTN->getIdentifier(),
2762 NameLoc,
2763 ObjectType,
2764 FirstQualifierInScope);
2765 }
2766
2767 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2768 ObjectType);
2769 }
2770
2771 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2772 TemplateDecl *TransTemplate
2773 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2774 Template));
2775 if (!TransTemplate)
2776 return TemplateName();
2777
2778 if (!getDerived().AlwaysRebuild() &&
2779 TransTemplate == Template)
2780 return Name;
2781
2782 return TemplateName(TransTemplate);
2783 }
2784
2785 if (SubstTemplateTemplateParmPackStorage *SubstPack
2786 = Name.getAsSubstTemplateTemplateParmPack()) {
2787 TemplateTemplateParmDecl *TransParam
2788 = cast_or_null<TemplateTemplateParmDecl>(
2789 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2790 if (!TransParam)
2791 return TemplateName();
2792
2793 if (!getDerived().AlwaysRebuild() &&
2794 TransParam == SubstPack->getParameterPack())
2795 return Name;
2796
2797 return getDerived().RebuildTemplateName(TransParam,
2798 SubstPack->getArgumentPack());
2799 }
2800
2801 // These should be getting filtered out before they reach the AST.
2802 llvm_unreachable("overloaded function decl survived to here");
2803 return TemplateName();
2804}
2805
2806template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002807void TreeTransform<Derived>::InventTemplateArgumentLoc(
2808 const TemplateArgument &Arg,
2809 TemplateArgumentLoc &Output) {
2810 SourceLocation Loc = getDerived().getBaseLocation();
2811 switch (Arg.getKind()) {
2812 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002813 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002814 break;
2815
2816 case TemplateArgument::Type:
2817 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002818 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002819
John McCall833ca992009-10-29 08:12:44 +00002820 break;
2821
Douglas Gregor788cd062009-11-11 01:00:40 +00002822 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002823 case TemplateArgument::TemplateExpansion: {
2824 NestedNameSpecifierLocBuilder Builder;
2825 TemplateName Template = Arg.getAsTemplate();
2826 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2827 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2828 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2829 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2830
2831 if (Arg.getKind() == TemplateArgument::Template)
2832 Output = TemplateArgumentLoc(Arg,
2833 Builder.getWithLocInContext(SemaRef.Context),
2834 Loc);
2835 else
2836 Output = TemplateArgumentLoc(Arg,
2837 Builder.getWithLocInContext(SemaRef.Context),
2838 Loc, Loc);
2839
Douglas Gregor788cd062009-11-11 01:00:40 +00002840 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002841 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002842
John McCall833ca992009-10-29 08:12:44 +00002843 case TemplateArgument::Expression:
2844 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2845 break;
2846
2847 case TemplateArgument::Declaration:
2848 case TemplateArgument::Integral:
2849 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002850 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002851 break;
2852 }
2853}
2854
2855template<typename Derived>
2856bool TreeTransform<Derived>::TransformTemplateArgument(
2857 const TemplateArgumentLoc &Input,
2858 TemplateArgumentLoc &Output) {
2859 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002860 switch (Arg.getKind()) {
2861 case TemplateArgument::Null:
2862 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002863 Output = Input;
2864 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002865
Douglas Gregor670444e2009-08-04 22:27:00 +00002866 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002867 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002868 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002869 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002870
2871 DI = getDerived().TransformType(DI);
2872 if (!DI) return true;
2873
2874 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2875 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002876 }
Mike Stump1eb44332009-09-09 15:08:12 +00002877
Douglas Gregor670444e2009-08-04 22:27:00 +00002878 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002879 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002880 DeclarationName Name;
2881 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2882 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002883 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002884 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002885 if (!D) return true;
2886
John McCall828bff22009-10-29 18:45:58 +00002887 Expr *SourceExpr = Input.getSourceDeclExpression();
2888 if (SourceExpr) {
2889 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002890 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002891 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002892 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002893 }
2894
2895 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002896 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002897 }
Mike Stump1eb44332009-09-09 15:08:12 +00002898
Douglas Gregor788cd062009-11-11 01:00:40 +00002899 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002900 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2901 if (QualifierLoc) {
2902 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2903 if (!QualifierLoc)
2904 return true;
2905 }
2906
Douglas Gregor1d752d72011-03-02 18:46:51 +00002907 CXXScopeSpec SS;
2908 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00002909 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00002910 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2911 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00002912 if (Template.isNull())
2913 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002914
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002915 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00002916 Input.getTemplateNameLoc());
2917 return false;
2918 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002919
2920 case TemplateArgument::TemplateExpansion:
2921 llvm_unreachable("Caller should expand pack expansions");
2922
Douglas Gregor670444e2009-08-04 22:27:00 +00002923 case TemplateArgument::Expression: {
2924 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002925 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002926 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002927
John McCall833ca992009-10-29 08:12:44 +00002928 Expr *InputExpr = Input.getSourceExpression();
2929 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2930
Chris Lattner223de242011-04-25 20:37:58 +00002931 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall833ca992009-10-29 08:12:44 +00002932 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002933 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002934 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002935 }
Mike Stump1eb44332009-09-09 15:08:12 +00002936
Douglas Gregor670444e2009-08-04 22:27:00 +00002937 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00002938 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00002939 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002940 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002941 AEnd = Arg.pack_end();
2942 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002943
John McCall833ca992009-10-29 08:12:44 +00002944 // FIXME: preserve source information here when we start
2945 // caring about parameter packs.
2946
John McCall828bff22009-10-29 18:45:58 +00002947 TemplateArgumentLoc InputArg;
2948 TemplateArgumentLoc OutputArg;
2949 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2950 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002951 return true;
2952
John McCall828bff22009-10-29 18:45:58 +00002953 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002954 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002955
2956 TemplateArgument *TransformedArgsPtr
2957 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2958 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2959 TransformedArgsPtr);
2960 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2961 TransformedArgs.size()),
2962 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002963 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002964 }
2965 }
Mike Stump1eb44332009-09-09 15:08:12 +00002966
Douglas Gregor670444e2009-08-04 22:27:00 +00002967 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002968 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002969}
2970
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002971/// \brief Iterator adaptor that invents template argument location information
2972/// for each of the template arguments in its underlying iterator.
2973template<typename Derived, typename InputIterator>
2974class TemplateArgumentLocInventIterator {
2975 TreeTransform<Derived> &Self;
2976 InputIterator Iter;
2977
2978public:
2979 typedef TemplateArgumentLoc value_type;
2980 typedef TemplateArgumentLoc reference;
2981 typedef typename std::iterator_traits<InputIterator>::difference_type
2982 difference_type;
2983 typedef std::input_iterator_tag iterator_category;
2984
2985 class pointer {
2986 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002987
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002988 public:
2989 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2990
2991 const TemplateArgumentLoc *operator->() const { return &Arg; }
2992 };
2993
2994 TemplateArgumentLocInventIterator() { }
2995
2996 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2997 InputIterator Iter)
2998 : Self(Self), Iter(Iter) { }
2999
3000 TemplateArgumentLocInventIterator &operator++() {
3001 ++Iter;
3002 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003003 }
3004
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003005 TemplateArgumentLocInventIterator operator++(int) {
3006 TemplateArgumentLocInventIterator Old(*this);
3007 ++(*this);
3008 return Old;
3009 }
3010
3011 reference operator*() const {
3012 TemplateArgumentLoc Result;
3013 Self.InventTemplateArgumentLoc(*Iter, Result);
3014 return Result;
3015 }
3016
3017 pointer operator->() const { return pointer(**this); }
3018
3019 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3020 const TemplateArgumentLocInventIterator &Y) {
3021 return X.Iter == Y.Iter;
3022 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003023
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003024 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3025 const TemplateArgumentLocInventIterator &Y) {
3026 return X.Iter != Y.Iter;
3027 }
3028};
3029
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003030template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003031template<typename InputIterator>
3032bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3033 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003034 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003035 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003036 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003037 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003038
3039 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3040 // Unpack argument packs, which we translate them into separate
3041 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003042 // FIXME: We could do much better if we could guarantee that the
3043 // TemplateArgumentLocInfo for the pack expansion would be usable for
3044 // all of the template arguments in the argument pack.
3045 typedef TemplateArgumentLocInventIterator<Derived,
3046 TemplateArgument::pack_iterator>
3047 PackLocIterator;
3048 if (TransformTemplateArguments(PackLocIterator(*this,
3049 In.getArgument().pack_begin()),
3050 PackLocIterator(*this,
3051 In.getArgument().pack_end()),
3052 Outputs))
3053 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003054
3055 continue;
3056 }
3057
3058 if (In.getArgument().isPackExpansion()) {
3059 // We have a pack expansion, for which we will be substituting into
3060 // the pattern.
3061 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003062 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003063 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003064 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3065 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003066
Chris Lattner686775d2011-07-20 06:58:45 +00003067 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003068 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3069 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3070
3071 // Determine whether the set of unexpanded parameter packs can and should
3072 // be expanded.
3073 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003074 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003075 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003076 if (getDerived().TryExpandParameterPacks(Ellipsis,
3077 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003078 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003079 Expand,
3080 RetainExpansion,
3081 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003082 return true;
3083
3084 if (!Expand) {
3085 // The transform has determined that we should perform a simple
3086 // transformation on the pack expansion, producing another pack
3087 // expansion.
3088 TemplateArgumentLoc OutPattern;
3089 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3090 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3091 return true;
3092
Douglas Gregorcded4f62011-01-14 17:04:44 +00003093 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3094 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003095 if (Out.getArgument().isNull())
3096 return true;
3097
3098 Outputs.addArgument(Out);
3099 continue;
3100 }
3101
3102 // The transform has determined that we should perform an elementwise
3103 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003104 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003105 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3106
3107 if (getDerived().TransformTemplateArgument(Pattern, Out))
3108 return true;
3109
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003110 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003111 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3112 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003113 if (Out.getArgument().isNull())
3114 return true;
3115 }
3116
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003117 Outputs.addArgument(Out);
3118 }
3119
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003120 // If we're supposed to retain a pack expansion, do so by temporarily
3121 // forgetting the partially-substituted parameter pack.
3122 if (RetainExpansion) {
3123 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3124
3125 if (getDerived().TransformTemplateArgument(Pattern, Out))
3126 return true;
3127
Douglas Gregorcded4f62011-01-14 17:04:44 +00003128 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3129 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003130 if (Out.getArgument().isNull())
3131 return true;
3132
3133 Outputs.addArgument(Out);
3134 }
Douglas Gregord3731192011-01-10 07:32:04 +00003135
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003136 continue;
3137 }
3138
3139 // The simple case:
3140 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003141 return true;
3142
3143 Outputs.addArgument(Out);
3144 }
3145
3146 return false;
3147
3148}
3149
Douglas Gregor577f75a2009-08-04 16:50:30 +00003150//===----------------------------------------------------------------------===//
3151// Type transformation
3152//===----------------------------------------------------------------------===//
3153
3154template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003155QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003156 if (getDerived().AlreadyTransformed(T))
3157 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003158
John McCalla2becad2009-10-21 00:40:46 +00003159 // Temporary workaround. All of these transformations should
3160 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003161 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3162 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003163
John McCall43fed0d2010-11-12 08:19:04 +00003164 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003165
John McCalla2becad2009-10-21 00:40:46 +00003166 if (!NewDI)
3167 return QualType();
3168
3169 return NewDI->getType();
3170}
3171
3172template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003173TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00003174 if (getDerived().AlreadyTransformed(DI->getType()))
3175 return DI;
3176
3177 TypeLocBuilder TLB;
3178
3179 TypeLoc TL = DI->getTypeLoc();
3180 TLB.reserve(TL.getFullDataSize());
3181
John McCall43fed0d2010-11-12 08:19:04 +00003182 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003183 if (Result.isNull())
3184 return 0;
3185
John McCalla93c9342009-12-07 02:54:59 +00003186 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003187}
3188
3189template<typename Derived>
3190QualType
John McCall43fed0d2010-11-12 08:19:04 +00003191TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003192 switch (T.getTypeLocClass()) {
3193#define ABSTRACT_TYPELOC(CLASS, PARENT)
3194#define TYPELOC(CLASS, PARENT) \
3195 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003196 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003197#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003198 }
Mike Stump1eb44332009-09-09 15:08:12 +00003199
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003200 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003201 return QualType();
3202}
3203
3204/// FIXME: By default, this routine adds type qualifiers only to types
3205/// that can have qualifiers, and silently suppresses those qualifiers
3206/// that are not permitted (e.g., qualifiers on reference or function
3207/// types). This is the right thing for template instantiation, but
3208/// probably not for other clients.
3209template<typename Derived>
3210QualType
3211TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003212 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003213 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003214
John McCall43fed0d2010-11-12 08:19:04 +00003215 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003216 if (Result.isNull())
3217 return QualType();
3218
3219 // Silently suppress qualifiers if the result type can't be qualified.
3220 // FIXME: this is the right thing for template instantiation, but
3221 // probably not for other clients.
3222 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003223 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003224
John McCallf85e1932011-06-15 23:02:42 +00003225 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003226 // resulting type.
3227 if (Quals.hasObjCLifetime()) {
3228 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3229 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003230 else if (Result.getObjCLifetime()) {
Douglas Gregore559ca12011-06-17 22:11:49 +00003231 // Objective-C ARC:
3232 // A lifetime qualifier applied to a substituted template parameter
3233 // overrides the lifetime qualifier from the template argument.
3234 if (const SubstTemplateTypeParmType *SubstTypeParam
3235 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3236 QualType Replacement = SubstTypeParam->getReplacementType();
3237 Qualifiers Qs = Replacement.getQualifiers();
3238 Qs.removeObjCLifetime();
3239 Replacement
3240 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3241 Qs);
3242 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3243 SubstTypeParam->getReplacedParameter(),
3244 Replacement);
3245 TLB.TypeWasModifiedSafely(Result);
3246 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003247 // Otherwise, complain about the addition of a qualifier to an
3248 // already-qualified type.
3249 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003250 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003251 << Result << R;
3252
Douglas Gregore559ca12011-06-17 22:11:49 +00003253 Quals.removeObjCLifetime();
3254 }
3255 }
3256 }
John McCall28654742010-06-05 06:41:15 +00003257 if (!Quals.empty()) {
3258 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3259 TLB.push<QualifiedTypeLoc>(Result);
3260 // No location information to preserve.
3261 }
John McCalla2becad2009-10-21 00:40:46 +00003262
3263 return Result;
3264}
3265
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003266template<typename Derived>
3267TypeLoc
3268TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3269 QualType ObjectType,
3270 NamedDecl *UnqualLookup,
3271 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003272 QualType T = TL.getType();
3273 if (getDerived().AlreadyTransformed(T))
3274 return TL;
3275
3276 TypeLocBuilder TLB;
3277 QualType Result;
3278
3279 if (isa<TemplateSpecializationType>(T)) {
3280 TemplateSpecializationTypeLoc SpecTL
3281 = cast<TemplateSpecializationTypeLoc>(TL);
3282
3283 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003284 getDerived().TransformTemplateName(SS,
3285 SpecTL.getTypePtr()->getTemplateName(),
3286 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003287 ObjectType, UnqualLookup);
3288 if (Template.isNull())
3289 return TypeLoc();
3290
3291 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3292 Template);
3293 } else if (isa<DependentTemplateSpecializationType>(T)) {
3294 DependentTemplateSpecializationTypeLoc SpecTL
3295 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3296
Douglas Gregora88f09f2011-02-28 17:23:35 +00003297 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003298 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003299 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003300 SpecTL.getNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003301 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003302 if (Template.isNull())
3303 return TypeLoc();
3304
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003305 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003306 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003307 Template,
3308 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003309 } else {
3310 // Nothing special needs to be done for these.
3311 Result = getDerived().TransformType(TLB, TL);
3312 }
3313
3314 if (Result.isNull())
3315 return TypeLoc();
3316
3317 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3318}
3319
Douglas Gregorb71d8212011-03-02 18:32:08 +00003320template<typename Derived>
3321TypeSourceInfo *
3322TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3323 QualType ObjectType,
3324 NamedDecl *UnqualLookup,
3325 CXXScopeSpec &SS) {
3326 // FIXME: Painfully copy-paste from the above!
3327
3328 QualType T = TSInfo->getType();
3329 if (getDerived().AlreadyTransformed(T))
3330 return TSInfo;
3331
3332 TypeLocBuilder TLB;
3333 QualType Result;
3334
3335 TypeLoc TL = TSInfo->getTypeLoc();
3336 if (isa<TemplateSpecializationType>(T)) {
3337 TemplateSpecializationTypeLoc SpecTL
3338 = cast<TemplateSpecializationTypeLoc>(TL);
3339
3340 TemplateName Template
3341 = getDerived().TransformTemplateName(SS,
3342 SpecTL.getTypePtr()->getTemplateName(),
3343 SpecTL.getTemplateNameLoc(),
3344 ObjectType, UnqualLookup);
3345 if (Template.isNull())
3346 return 0;
3347
3348 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3349 Template);
3350 } else if (isa<DependentTemplateSpecializationType>(T)) {
3351 DependentTemplateSpecializationTypeLoc SpecTL
3352 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3353
3354 TemplateName Template
3355 = getDerived().RebuildTemplateName(SS,
3356 *SpecTL.getTypePtr()->getIdentifier(),
3357 SpecTL.getNameLoc(),
3358 ObjectType, UnqualLookup);
3359 if (Template.isNull())
3360 return 0;
3361
3362 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3363 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003364 Template,
3365 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003366 } else {
3367 // Nothing special needs to be done for these.
3368 Result = getDerived().TransformType(TLB, TL);
3369 }
3370
3371 if (Result.isNull())
3372 return 0;
3373
3374 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3375}
3376
John McCalla2becad2009-10-21 00:40:46 +00003377template <class TyLoc> static inline
3378QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3379 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3380 NewT.setNameLoc(T.getNameLoc());
3381 return T.getType();
3382}
3383
John McCalla2becad2009-10-21 00:40:46 +00003384template<typename Derived>
3385QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003386 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003387 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3388 NewT.setBuiltinLoc(T.getBuiltinLoc());
3389 if (T.needsExtraLocalData())
3390 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3391 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003392}
Mike Stump1eb44332009-09-09 15:08:12 +00003393
Douglas Gregor577f75a2009-08-04 16:50:30 +00003394template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003395QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003396 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003397 // FIXME: recurse?
3398 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003399}
Mike Stump1eb44332009-09-09 15:08:12 +00003400
Douglas Gregor577f75a2009-08-04 16:50:30 +00003401template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003402QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003403 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003404 QualType PointeeType
3405 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003406 if (PointeeType.isNull())
3407 return QualType();
3408
3409 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003410 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003411 // A dependent pointer type 'T *' has is being transformed such
3412 // that an Objective-C class type is being replaced for 'T'. The
3413 // resulting pointer type is an ObjCObjectPointerType, not a
3414 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003415 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003416
John McCallc12c5bb2010-05-15 11:32:37 +00003417 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3418 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003419 return Result;
3420 }
John McCall43fed0d2010-11-12 08:19:04 +00003421
Douglas Gregor92e986e2010-04-22 16:44:27 +00003422 if (getDerived().AlwaysRebuild() ||
3423 PointeeType != TL.getPointeeLoc().getType()) {
3424 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3425 if (Result.isNull())
3426 return QualType();
3427 }
John McCallf85e1932011-06-15 23:02:42 +00003428
3429 // Objective-C ARC can add lifetime qualifiers to the type that we're
3430 // pointing to.
3431 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3432
Douglas Gregor92e986e2010-04-22 16:44:27 +00003433 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3434 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003435 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003436}
Mike Stump1eb44332009-09-09 15:08:12 +00003437
3438template<typename Derived>
3439QualType
John McCalla2becad2009-10-21 00:40:46 +00003440TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003441 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003442 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003443 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3444 if (PointeeType.isNull())
3445 return QualType();
3446
3447 QualType Result = TL.getType();
3448 if (getDerived().AlwaysRebuild() ||
3449 PointeeType != TL.getPointeeLoc().getType()) {
3450 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003451 TL.getSigilLoc());
3452 if (Result.isNull())
3453 return QualType();
3454 }
3455
Douglas Gregor39968ad2010-04-22 16:50:51 +00003456 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003457 NewT.setSigilLoc(TL.getSigilLoc());
3458 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003459}
3460
John McCall85737a72009-10-30 00:06:24 +00003461/// Transforms a reference type. Note that somewhat paradoxically we
3462/// don't care whether the type itself is an l-value type or an r-value
3463/// type; we only care if the type was *written* as an l-value type
3464/// or an r-value type.
3465template<typename Derived>
3466QualType
3467TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003468 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003469 const ReferenceType *T = TL.getTypePtr();
3470
3471 // Note that this works with the pointee-as-written.
3472 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3473 if (PointeeType.isNull())
3474 return QualType();
3475
3476 QualType Result = TL.getType();
3477 if (getDerived().AlwaysRebuild() ||
3478 PointeeType != T->getPointeeTypeAsWritten()) {
3479 Result = getDerived().RebuildReferenceType(PointeeType,
3480 T->isSpelledAsLValue(),
3481 TL.getSigilLoc());
3482 if (Result.isNull())
3483 return QualType();
3484 }
3485
John McCallf85e1932011-06-15 23:02:42 +00003486 // Objective-C ARC can add lifetime qualifiers to the type that we're
3487 // referring to.
3488 TLB.TypeWasModifiedSafely(
3489 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3490
John McCall85737a72009-10-30 00:06:24 +00003491 // r-value references can be rebuilt as l-value references.
3492 ReferenceTypeLoc NewTL;
3493 if (isa<LValueReferenceType>(Result))
3494 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3495 else
3496 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3497 NewTL.setSigilLoc(TL.getSigilLoc());
3498
3499 return Result;
3500}
3501
Mike Stump1eb44332009-09-09 15:08:12 +00003502template<typename Derived>
3503QualType
John McCalla2becad2009-10-21 00:40:46 +00003504TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003505 LValueReferenceTypeLoc TL) {
3506 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003507}
3508
Mike Stump1eb44332009-09-09 15:08:12 +00003509template<typename Derived>
3510QualType
John McCalla2becad2009-10-21 00:40:46 +00003511TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003512 RValueReferenceTypeLoc TL) {
3513 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003514}
Mike Stump1eb44332009-09-09 15:08:12 +00003515
Douglas Gregor577f75a2009-08-04 16:50:30 +00003516template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003517QualType
John McCalla2becad2009-10-21 00:40:46 +00003518TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003519 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003520 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003521 if (PointeeType.isNull())
3522 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003523
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003524 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3525 TypeSourceInfo* NewClsTInfo = 0;
3526 if (OldClsTInfo) {
3527 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3528 if (!NewClsTInfo)
3529 return QualType();
3530 }
3531
3532 const MemberPointerType *T = TL.getTypePtr();
3533 QualType OldClsType = QualType(T->getClass(), 0);
3534 QualType NewClsType;
3535 if (NewClsTInfo)
3536 NewClsType = NewClsTInfo->getType();
3537 else {
3538 NewClsType = getDerived().TransformType(OldClsType);
3539 if (NewClsType.isNull())
3540 return QualType();
3541 }
Mike Stump1eb44332009-09-09 15:08:12 +00003542
John McCalla2becad2009-10-21 00:40:46 +00003543 QualType Result = TL.getType();
3544 if (getDerived().AlwaysRebuild() ||
3545 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003546 NewClsType != OldClsType) {
3547 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003548 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003549 if (Result.isNull())
3550 return QualType();
3551 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003552
John McCalla2becad2009-10-21 00:40:46 +00003553 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3554 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003555 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003556
3557 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003558}
3559
Mike Stump1eb44332009-09-09 15:08:12 +00003560template<typename Derived>
3561QualType
John McCalla2becad2009-10-21 00:40:46 +00003562TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003563 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003564 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003565 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003566 if (ElementType.isNull())
3567 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003568
John McCalla2becad2009-10-21 00:40:46 +00003569 QualType Result = TL.getType();
3570 if (getDerived().AlwaysRebuild() ||
3571 ElementType != T->getElementType()) {
3572 Result = getDerived().RebuildConstantArrayType(ElementType,
3573 T->getSizeModifier(),
3574 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003575 T->getIndexTypeCVRQualifiers(),
3576 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003577 if (Result.isNull())
3578 return QualType();
3579 }
Sean Huntc3021132010-05-05 15:23:54 +00003580
John McCalla2becad2009-10-21 00:40:46 +00003581 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3582 NewTL.setLBracketLoc(TL.getLBracketLoc());
3583 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003584
John McCalla2becad2009-10-21 00:40:46 +00003585 Expr *Size = TL.getSizeExpr();
3586 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00003587 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003588 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3589 }
3590 NewTL.setSizeExpr(Size);
3591
3592 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003593}
Mike Stump1eb44332009-09-09 15:08:12 +00003594
Douglas Gregor577f75a2009-08-04 16:50:30 +00003595template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003596QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003597 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003598 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003599 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003600 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003601 if (ElementType.isNull())
3602 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003603
John McCalla2becad2009-10-21 00:40:46 +00003604 QualType Result = TL.getType();
3605 if (getDerived().AlwaysRebuild() ||
3606 ElementType != T->getElementType()) {
3607 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003608 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003609 T->getIndexTypeCVRQualifiers(),
3610 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003611 if (Result.isNull())
3612 return QualType();
3613 }
Sean Huntc3021132010-05-05 15:23:54 +00003614
John McCalla2becad2009-10-21 00:40:46 +00003615 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3616 NewTL.setLBracketLoc(TL.getLBracketLoc());
3617 NewTL.setRBracketLoc(TL.getRBracketLoc());
3618 NewTL.setSizeExpr(0);
3619
3620 return Result;
3621}
3622
3623template<typename Derived>
3624QualType
3625TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003626 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003627 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003628 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3629 if (ElementType.isNull())
3630 return QualType();
3631
3632 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003633 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003634
John McCall60d7b3a2010-08-24 06:29:42 +00003635 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003636 = getDerived().TransformExpr(T->getSizeExpr());
3637 if (SizeResult.isInvalid())
3638 return QualType();
3639
John McCall9ae2f072010-08-23 23:25:46 +00003640 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003641
3642 QualType Result = TL.getType();
3643 if (getDerived().AlwaysRebuild() ||
3644 ElementType != T->getElementType() ||
3645 Size != T->getSizeExpr()) {
3646 Result = getDerived().RebuildVariableArrayType(ElementType,
3647 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003648 Size,
John McCalla2becad2009-10-21 00:40:46 +00003649 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003650 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003651 if (Result.isNull())
3652 return QualType();
3653 }
Sean Huntc3021132010-05-05 15:23:54 +00003654
John McCalla2becad2009-10-21 00:40:46 +00003655 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3656 NewTL.setLBracketLoc(TL.getLBracketLoc());
3657 NewTL.setRBracketLoc(TL.getRBracketLoc());
3658 NewTL.setSizeExpr(Size);
3659
3660 return Result;
3661}
3662
3663template<typename Derived>
3664QualType
3665TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003666 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003667 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003668 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3669 if (ElementType.isNull())
3670 return QualType();
3671
3672 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003673 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003674
John McCall3b657512011-01-19 10:06:00 +00003675 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3676 Expr *origSize = TL.getSizeExpr();
3677 if (!origSize) origSize = T->getSizeExpr();
3678
3679 ExprResult sizeResult
3680 = getDerived().TransformExpr(origSize);
3681 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003682 return QualType();
3683
John McCall3b657512011-01-19 10:06:00 +00003684 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003685
3686 QualType Result = TL.getType();
3687 if (getDerived().AlwaysRebuild() ||
3688 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003689 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003690 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3691 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003692 size,
John McCalla2becad2009-10-21 00:40:46 +00003693 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003694 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003695 if (Result.isNull())
3696 return QualType();
3697 }
John McCalla2becad2009-10-21 00:40:46 +00003698
3699 // We might have any sort of array type now, but fortunately they
3700 // all have the same location layout.
3701 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3702 NewTL.setLBracketLoc(TL.getLBracketLoc());
3703 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003704 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003705
3706 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003707}
Mike Stump1eb44332009-09-09 15:08:12 +00003708
3709template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003710QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003711 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003712 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003713 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003714
3715 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003716 QualType ElementType = getDerived().TransformType(T->getElementType());
3717 if (ElementType.isNull())
3718 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003719
Douglas Gregor670444e2009-08-04 22:27:00 +00003720 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003721 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003722
John McCall60d7b3a2010-08-24 06:29:42 +00003723 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003724 if (Size.isInvalid())
3725 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003726
John McCalla2becad2009-10-21 00:40:46 +00003727 QualType Result = TL.getType();
3728 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003729 ElementType != T->getElementType() ||
3730 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003731 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003732 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003733 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003734 if (Result.isNull())
3735 return QualType();
3736 }
John McCalla2becad2009-10-21 00:40:46 +00003737
3738 // Result might be dependent or not.
3739 if (isa<DependentSizedExtVectorType>(Result)) {
3740 DependentSizedExtVectorTypeLoc NewTL
3741 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3742 NewTL.setNameLoc(TL.getNameLoc());
3743 } else {
3744 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3745 NewTL.setNameLoc(TL.getNameLoc());
3746 }
3747
3748 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003749}
Mike Stump1eb44332009-09-09 15:08:12 +00003750
3751template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003752QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003753 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003754 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003755 QualType ElementType = getDerived().TransformType(T->getElementType());
3756 if (ElementType.isNull())
3757 return QualType();
3758
John McCalla2becad2009-10-21 00:40:46 +00003759 QualType Result = TL.getType();
3760 if (getDerived().AlwaysRebuild() ||
3761 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003762 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003763 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003764 if (Result.isNull())
3765 return QualType();
3766 }
Sean Huntc3021132010-05-05 15:23:54 +00003767
John McCalla2becad2009-10-21 00:40:46 +00003768 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3769 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003770
John McCalla2becad2009-10-21 00:40:46 +00003771 return Result;
3772}
3773
3774template<typename Derived>
3775QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003776 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003777 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003778 QualType ElementType = getDerived().TransformType(T->getElementType());
3779 if (ElementType.isNull())
3780 return QualType();
3781
3782 QualType Result = TL.getType();
3783 if (getDerived().AlwaysRebuild() ||
3784 ElementType != T->getElementType()) {
3785 Result = getDerived().RebuildExtVectorType(ElementType,
3786 T->getNumElements(),
3787 /*FIXME*/ SourceLocation());
3788 if (Result.isNull())
3789 return QualType();
3790 }
Sean Huntc3021132010-05-05 15:23:54 +00003791
John McCalla2becad2009-10-21 00:40:46 +00003792 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3793 NewTL.setNameLoc(TL.getNameLoc());
3794
3795 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003796}
Mike Stump1eb44332009-09-09 15:08:12 +00003797
3798template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003799ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003800TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003801 int indexAdjustment,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003802 llvm::Optional<unsigned> NumExpansions) {
John McCall21ef0fa2010-03-11 09:03:00 +00003803 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003804 TypeSourceInfo *NewDI = 0;
3805
3806 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3807 // If we're substituting into a pack expansion type and we know the
3808 TypeLoc OldTL = OldDI->getTypeLoc();
3809 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3810
3811 TypeLocBuilder TLB;
3812 TypeLoc NewTL = OldDI->getTypeLoc();
3813 TLB.reserve(NewTL.getFullDataSize());
3814
3815 QualType Result = getDerived().TransformType(TLB,
3816 OldExpansionTL.getPatternLoc());
3817 if (Result.isNull())
3818 return 0;
3819
3820 Result = RebuildPackExpansionType(Result,
3821 OldExpansionTL.getPatternLoc().getSourceRange(),
3822 OldExpansionTL.getEllipsisLoc(),
3823 NumExpansions);
3824 if (Result.isNull())
3825 return 0;
3826
3827 PackExpansionTypeLoc NewExpansionTL
3828 = TLB.push<PackExpansionTypeLoc>(Result);
3829 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3830 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3831 } else
3832 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003833 if (!NewDI)
3834 return 0;
3835
John McCallfb44de92011-05-01 22:35:37 +00003836 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003837 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003838
3839 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3840 OldParm->getDeclContext(),
3841 OldParm->getInnerLocStart(),
3842 OldParm->getLocation(),
3843 OldParm->getIdentifier(),
3844 NewDI->getType(),
3845 NewDI,
3846 OldParm->getStorageClass(),
3847 OldParm->getStorageClassAsWritten(),
3848 /* DefArg */ NULL);
3849 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3850 OldParm->getFunctionScopeIndex() + indexAdjustment);
3851 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003852}
3853
3854template<typename Derived>
3855bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003856 TransformFunctionTypeParams(SourceLocation Loc,
3857 ParmVarDecl **Params, unsigned NumParams,
3858 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003859 SmallVectorImpl<QualType> &OutParamTypes,
3860 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003861 int indexAdjustment = 0;
3862
Douglas Gregora009b592011-01-07 00:20:55 +00003863 for (unsigned i = 0; i != NumParams; ++i) {
3864 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003865 assert(OldParm->getFunctionScopeIndex() == i);
3866
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003867 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003868 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003869 if (OldParm->isParameterPack()) {
3870 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003871 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003872
Douglas Gregor603cfb42011-01-05 23:12:31 +00003873 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003874 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3875 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3876 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3877 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003878 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3879
Douglas Gregor603cfb42011-01-05 23:12:31 +00003880 // Determine whether we should expand the parameter packs.
3881 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003882 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003883 llvm::Optional<unsigned> OrigNumExpansions
3884 = ExpansionTL.getTypePtr()->getNumExpansions();
3885 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003886 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3887 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003888 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003889 ShouldExpand,
3890 RetainExpansion,
3891 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003892 return true;
3893 }
3894
3895 if (ShouldExpand) {
3896 // Expand the function parameter pack into multiple, separate
3897 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003898 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003899 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003900 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3901 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003902 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003903 indexAdjustment++,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003904 OrigNumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003905 if (!NewParm)
3906 return true;
3907
Douglas Gregora009b592011-01-07 00:20:55 +00003908 OutParamTypes.push_back(NewParm->getType());
3909 if (PVars)
3910 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003911 }
Douglas Gregord3731192011-01-10 07:32:04 +00003912
3913 // If we're supposed to retain a pack expansion, do so by temporarily
3914 // forgetting the partially-substituted parameter pack.
3915 if (RetainExpansion) {
3916 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3917 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003918 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003919 indexAdjustment++,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003920 OrigNumExpansions);
Douglas Gregord3731192011-01-10 07:32:04 +00003921 if (!NewParm)
3922 return true;
3923
3924 OutParamTypes.push_back(NewParm->getType());
3925 if (PVars)
3926 PVars->push_back(NewParm);
3927 }
3928
John McCallfb44de92011-05-01 22:35:37 +00003929 // The next parameter should have the same adjustment as the
3930 // last thing we pushed, but we post-incremented indexAdjustment
3931 // on every push. Also, if we push nothing, the adjustment should
3932 // go down by one.
3933 indexAdjustment--;
3934
Douglas Gregor603cfb42011-01-05 23:12:31 +00003935 // We're done with the pack expansion.
3936 continue;
3937 }
3938
3939 // We'll substitute the parameter now without expanding the pack
3940 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00003941 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3942 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003943 indexAdjustment,
Douglas Gregor406f98f2011-03-02 02:04:06 +00003944 NumExpansions);
3945 } else {
3946 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003947 indexAdjustment,
Douglas Gregor406f98f2011-03-02 02:04:06 +00003948 llvm::Optional<unsigned>());
Douglas Gregor603cfb42011-01-05 23:12:31 +00003949 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00003950
John McCall21ef0fa2010-03-11 09:03:00 +00003951 if (!NewParm)
3952 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003953
Douglas Gregora009b592011-01-07 00:20:55 +00003954 OutParamTypes.push_back(NewParm->getType());
3955 if (PVars)
3956 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003957 continue;
3958 }
John McCall21ef0fa2010-03-11 09:03:00 +00003959
3960 // Deal with the possibility that we don't have a parameter
3961 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00003962 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00003963 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003964 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003965 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003966 if (const PackExpansionType *Expansion
3967 = dyn_cast<PackExpansionType>(OldType)) {
3968 // We have a function parameter pack that may need to be expanded.
3969 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00003970 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003971 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3972
3973 // Determine whether we should expand the parameter packs.
3974 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003975 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00003976 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003977 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003978 ShouldExpand,
3979 RetainExpansion,
3980 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00003981 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003982 }
3983
3984 if (ShouldExpand) {
3985 // Expand the function parameter pack into multiple, separate
3986 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003987 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003988 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3989 QualType NewType = getDerived().TransformType(Pattern);
3990 if (NewType.isNull())
3991 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00003992
Douglas Gregora009b592011-01-07 00:20:55 +00003993 OutParamTypes.push_back(NewType);
3994 if (PVars)
3995 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003996 }
3997
3998 // We're done with the pack expansion.
3999 continue;
4000 }
4001
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004002 // If we're supposed to retain a pack expansion, do so by temporarily
4003 // forgetting the partially-substituted parameter pack.
4004 if (RetainExpansion) {
4005 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4006 QualType NewType = getDerived().TransformType(Pattern);
4007 if (NewType.isNull())
4008 return true;
4009
4010 OutParamTypes.push_back(NewType);
4011 if (PVars)
4012 PVars->push_back(0);
4013 }
Douglas Gregord3731192011-01-10 07:32:04 +00004014
Douglas Gregor603cfb42011-01-05 23:12:31 +00004015 // We'll substitute the parameter now without expanding the pack
4016 // expansion.
4017 OldType = Expansion->getPattern();
4018 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004019 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4020 NewType = getDerived().TransformType(OldType);
4021 } else {
4022 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004023 }
4024
Douglas Gregor603cfb42011-01-05 23:12:31 +00004025 if (NewType.isNull())
4026 return true;
4027
4028 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004029 NewType = getSema().Context.getPackExpansionType(NewType,
4030 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004031
Douglas Gregora009b592011-01-07 00:20:55 +00004032 OutParamTypes.push_back(NewType);
4033 if (PVars)
4034 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004035 }
4036
John McCallfb44de92011-05-01 22:35:37 +00004037#ifndef NDEBUG
4038 if (PVars) {
4039 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4040 if (ParmVarDecl *parm = (*PVars)[i])
4041 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004042 }
John McCallfb44de92011-05-01 22:35:37 +00004043#endif
4044
4045 return false;
4046}
John McCall21ef0fa2010-03-11 09:03:00 +00004047
4048template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004049QualType
John McCalla2becad2009-10-21 00:40:46 +00004050TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004051 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004052 // Transform the parameters and return type.
4053 //
4054 // We instantiate in source order, with the return type first followed by
4055 // the parameters, because users tend to expect this (even if they shouldn't
4056 // rely on it!).
4057 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00004058 // When the function has a trailing return type, we instantiate the
4059 // parameters before the return type, since the return type can then refer
4060 // to the parameters themselves (via decltype, sizeof, etc.).
4061 //
Chris Lattner686775d2011-07-20 06:58:45 +00004062 SmallVector<QualType, 4> ParamTypes;
4063 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004064 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004065
Douglas Gregordab60ad2010-10-01 18:44:50 +00004066 QualType ResultType;
4067
4068 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00004069 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4070 TL.getParmArray(),
4071 TL.getNumArgs(),
4072 TL.getTypePtr()->arg_type_begin(),
4073 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004074 return QualType();
4075
4076 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4077 if (ResultType.isNull())
4078 return QualType();
4079 }
4080 else {
4081 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4082 if (ResultType.isNull())
4083 return QualType();
4084
Douglas Gregora009b592011-01-07 00:20:55 +00004085 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4086 TL.getParmArray(),
4087 TL.getNumArgs(),
4088 TL.getTypePtr()->arg_type_begin(),
4089 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004090 return QualType();
4091 }
4092
John McCalla2becad2009-10-21 00:40:46 +00004093 QualType Result = TL.getType();
4094 if (getDerived().AlwaysRebuild() ||
4095 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004096 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004097 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4098 Result = getDerived().RebuildFunctionProtoType(ResultType,
4099 ParamTypes.data(),
4100 ParamTypes.size(),
4101 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004102 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004103 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004104 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004105 if (Result.isNull())
4106 return QualType();
4107 }
Mike Stump1eb44332009-09-09 15:08:12 +00004108
John McCalla2becad2009-10-21 00:40:46 +00004109 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004110 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4111 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004112 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004113 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4114 NewTL.setArg(i, ParamDecls[i]);
4115
4116 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004117}
Mike Stump1eb44332009-09-09 15:08:12 +00004118
Douglas Gregor577f75a2009-08-04 16:50:30 +00004119template<typename Derived>
4120QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004121 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004122 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004123 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004124 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4125 if (ResultType.isNull())
4126 return QualType();
4127
4128 QualType Result = TL.getType();
4129 if (getDerived().AlwaysRebuild() ||
4130 ResultType != T->getResultType())
4131 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4132
4133 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004134 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4135 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004136 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004137
4138 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004139}
Mike Stump1eb44332009-09-09 15:08:12 +00004140
John McCalled976492009-12-04 22:46:56 +00004141template<typename Derived> QualType
4142TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004143 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004144 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004145 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004146 if (!D)
4147 return QualType();
4148
4149 QualType Result = TL.getType();
4150 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4151 Result = getDerived().RebuildUnresolvedUsingType(D);
4152 if (Result.isNull())
4153 return QualType();
4154 }
4155
4156 // We might get an arbitrary type spec type back. We should at
4157 // least always get a type spec type, though.
4158 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4159 NewTL.setNameLoc(TL.getNameLoc());
4160
4161 return Result;
4162}
4163
Douglas Gregor577f75a2009-08-04 16:50:30 +00004164template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004165QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004166 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004167 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004168 TypedefNameDecl *Typedef
4169 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4170 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004171 if (!Typedef)
4172 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004173
John McCalla2becad2009-10-21 00:40:46 +00004174 QualType Result = TL.getType();
4175 if (getDerived().AlwaysRebuild() ||
4176 Typedef != T->getDecl()) {
4177 Result = getDerived().RebuildTypedefType(Typedef);
4178 if (Result.isNull())
4179 return QualType();
4180 }
Mike Stump1eb44332009-09-09 15:08:12 +00004181
John McCalla2becad2009-10-21 00:40:46 +00004182 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4183 NewTL.setNameLoc(TL.getNameLoc());
4184
4185 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004186}
Mike Stump1eb44332009-09-09 15:08:12 +00004187
Douglas Gregor577f75a2009-08-04 16:50:30 +00004188template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004189QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004190 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004191 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004192 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004193
John McCall60d7b3a2010-08-24 06:29:42 +00004194 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004195 if (E.isInvalid())
4196 return QualType();
4197
John McCalla2becad2009-10-21 00:40:46 +00004198 QualType Result = TL.getType();
4199 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004200 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004201 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004202 if (Result.isNull())
4203 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004204 }
John McCalla2becad2009-10-21 00:40:46 +00004205 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004206
John McCalla2becad2009-10-21 00:40:46 +00004207 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004208 NewTL.setTypeofLoc(TL.getTypeofLoc());
4209 NewTL.setLParenLoc(TL.getLParenLoc());
4210 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004211
4212 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004213}
Mike Stump1eb44332009-09-09 15:08:12 +00004214
4215template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004216QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004217 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004218 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4219 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4220 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004221 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004222
John McCalla2becad2009-10-21 00:40:46 +00004223 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004224 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4225 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004226 if (Result.isNull())
4227 return QualType();
4228 }
Mike Stump1eb44332009-09-09 15:08:12 +00004229
John McCalla2becad2009-10-21 00:40:46 +00004230 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004231 NewTL.setTypeofLoc(TL.getTypeofLoc());
4232 NewTL.setLParenLoc(TL.getLParenLoc());
4233 NewTL.setRParenLoc(TL.getRParenLoc());
4234 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004235
4236 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004237}
Mike Stump1eb44332009-09-09 15:08:12 +00004238
4239template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004240QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004241 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004242 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004243
Douglas Gregor670444e2009-08-04 22:27:00 +00004244 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004245 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004246
John McCall60d7b3a2010-08-24 06:29:42 +00004247 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004248 if (E.isInvalid())
4249 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004250
John McCalla2becad2009-10-21 00:40:46 +00004251 QualType Result = TL.getType();
4252 if (getDerived().AlwaysRebuild() ||
4253 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004254 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004255 if (Result.isNull())
4256 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004257 }
John McCalla2becad2009-10-21 00:40:46 +00004258 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004259
John McCalla2becad2009-10-21 00:40:46 +00004260 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4261 NewTL.setNameLoc(TL.getNameLoc());
4262
4263 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004264}
4265
4266template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004267QualType TreeTransform<Derived>::TransformUnaryTransformType(
4268 TypeLocBuilder &TLB,
4269 UnaryTransformTypeLoc TL) {
4270 QualType Result = TL.getType();
4271 if (Result->isDependentType()) {
4272 const UnaryTransformType *T = TL.getTypePtr();
4273 QualType NewBase =
4274 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4275 Result = getDerived().RebuildUnaryTransformType(NewBase,
4276 T->getUTTKind(),
4277 TL.getKWLoc());
4278 if (Result.isNull())
4279 return QualType();
4280 }
4281
4282 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4283 NewTL.setKWLoc(TL.getKWLoc());
4284 NewTL.setParensRange(TL.getParensRange());
4285 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4286 return Result;
4287}
4288
4289template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004290QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4291 AutoTypeLoc TL) {
4292 const AutoType *T = TL.getTypePtr();
4293 QualType OldDeduced = T->getDeducedType();
4294 QualType NewDeduced;
4295 if (!OldDeduced.isNull()) {
4296 NewDeduced = getDerived().TransformType(OldDeduced);
4297 if (NewDeduced.isNull())
4298 return QualType();
4299 }
4300
4301 QualType Result = TL.getType();
4302 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4303 Result = getDerived().RebuildAutoType(NewDeduced);
4304 if (Result.isNull())
4305 return QualType();
4306 }
4307
4308 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4309 NewTL.setNameLoc(TL.getNameLoc());
4310
4311 return Result;
4312}
4313
4314template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004315QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004316 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004317 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004318 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004319 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4320 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004321 if (!Record)
4322 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004323
John McCalla2becad2009-10-21 00:40:46 +00004324 QualType Result = TL.getType();
4325 if (getDerived().AlwaysRebuild() ||
4326 Record != T->getDecl()) {
4327 Result = getDerived().RebuildRecordType(Record);
4328 if (Result.isNull())
4329 return QualType();
4330 }
Mike Stump1eb44332009-09-09 15:08:12 +00004331
John McCalla2becad2009-10-21 00:40:46 +00004332 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4333 NewTL.setNameLoc(TL.getNameLoc());
4334
4335 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004336}
Mike Stump1eb44332009-09-09 15:08:12 +00004337
4338template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004339QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004340 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004341 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004342 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004343 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4344 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004345 if (!Enum)
4346 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004347
John McCalla2becad2009-10-21 00:40:46 +00004348 QualType Result = TL.getType();
4349 if (getDerived().AlwaysRebuild() ||
4350 Enum != T->getDecl()) {
4351 Result = getDerived().RebuildEnumType(Enum);
4352 if (Result.isNull())
4353 return QualType();
4354 }
Mike Stump1eb44332009-09-09 15:08:12 +00004355
John McCalla2becad2009-10-21 00:40:46 +00004356 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4357 NewTL.setNameLoc(TL.getNameLoc());
4358
4359 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004360}
John McCall7da24312009-09-05 00:15:47 +00004361
John McCall3cb0ebd2010-03-10 03:28:59 +00004362template<typename Derived>
4363QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4364 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004365 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004366 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4367 TL.getTypePtr()->getDecl());
4368 if (!D) return QualType();
4369
4370 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4371 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4372 return T;
4373}
4374
Douglas Gregor577f75a2009-08-04 16:50:30 +00004375template<typename Derived>
4376QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004377 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004378 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004379 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004380}
4381
Mike Stump1eb44332009-09-09 15:08:12 +00004382template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004383QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004384 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004385 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004386 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4387
4388 // Substitute into the replacement type, which itself might involve something
4389 // that needs to be transformed. This only tends to occur with default
4390 // template arguments of template template parameters.
4391 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4392 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4393 if (Replacement.isNull())
4394 return QualType();
4395
4396 // Always canonicalize the replacement type.
4397 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4398 QualType Result
4399 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4400 Replacement);
4401
4402 // Propagate type-source information.
4403 SubstTemplateTypeParmTypeLoc NewTL
4404 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4405 NewTL.setNameLoc(TL.getNameLoc());
4406 return Result;
4407
John McCall49a832b2009-10-18 09:09:24 +00004408}
4409
4410template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004411QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4412 TypeLocBuilder &TLB,
4413 SubstTemplateTypeParmPackTypeLoc TL) {
4414 return TransformTypeSpecType(TLB, TL);
4415}
4416
4417template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004418QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004419 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004420 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004421 const TemplateSpecializationType *T = TL.getTypePtr();
4422
Douglas Gregor1d752d72011-03-02 18:46:51 +00004423 // The nested-name-specifier never matters in a TemplateSpecializationType,
4424 // because we can't have a dependent nested-name-specifier anyway.
4425 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004426 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004427 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4428 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004429 if (Template.isNull())
4430 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004431
John McCall43fed0d2010-11-12 08:19:04 +00004432 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4433}
4434
Eli Friedmanb001de72011-10-06 23:00:33 +00004435template<typename Derived>
4436QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4437 AtomicTypeLoc TL) {
4438 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4439 if (ValueType.isNull())
4440 return QualType();
4441
4442 QualType Result = TL.getType();
4443 if (getDerived().AlwaysRebuild() ||
4444 ValueType != TL.getValueLoc().getType()) {
4445 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4446 if (Result.isNull())
4447 return QualType();
4448 }
4449
4450 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4451 NewTL.setKWLoc(TL.getKWLoc());
4452 NewTL.setLParenLoc(TL.getLParenLoc());
4453 NewTL.setRParenLoc(TL.getRParenLoc());
4454
4455 return Result;
4456}
4457
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004458namespace {
4459 /// \brief Simple iterator that traverses the template arguments in a
4460 /// container that provides a \c getArgLoc() member function.
4461 ///
4462 /// This iterator is intended to be used with the iterator form of
4463 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4464 template<typename ArgLocContainer>
4465 class TemplateArgumentLocContainerIterator {
4466 ArgLocContainer *Container;
4467 unsigned Index;
4468
4469 public:
4470 typedef TemplateArgumentLoc value_type;
4471 typedef TemplateArgumentLoc reference;
4472 typedef int difference_type;
4473 typedef std::input_iterator_tag iterator_category;
4474
4475 class pointer {
4476 TemplateArgumentLoc Arg;
4477
4478 public:
4479 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4480
4481 const TemplateArgumentLoc *operator->() const {
4482 return &Arg;
4483 }
4484 };
4485
4486
4487 TemplateArgumentLocContainerIterator() {}
4488
4489 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4490 unsigned Index)
4491 : Container(&Container), Index(Index) { }
4492
4493 TemplateArgumentLocContainerIterator &operator++() {
4494 ++Index;
4495 return *this;
4496 }
4497
4498 TemplateArgumentLocContainerIterator operator++(int) {
4499 TemplateArgumentLocContainerIterator Old(*this);
4500 ++(*this);
4501 return Old;
4502 }
4503
4504 TemplateArgumentLoc operator*() const {
4505 return Container->getArgLoc(Index);
4506 }
4507
4508 pointer operator->() const {
4509 return pointer(Container->getArgLoc(Index));
4510 }
4511
4512 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004513 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004514 return X.Container == Y.Container && X.Index == Y.Index;
4515 }
4516
4517 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004518 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004519 return !(X == Y);
4520 }
4521 };
4522}
4523
4524
John McCall43fed0d2010-11-12 08:19:04 +00004525template <typename Derived>
4526QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4527 TypeLocBuilder &TLB,
4528 TemplateSpecializationTypeLoc TL,
4529 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004530 TemplateArgumentListInfo NewTemplateArgs;
4531 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4532 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004533 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4534 ArgIterator;
4535 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4536 ArgIterator(TL, TL.getNumArgs()),
4537 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004538 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004539
John McCall833ca992009-10-29 08:12:44 +00004540 // FIXME: maybe don't rebuild if all the template arguments are the same.
4541
4542 QualType Result =
4543 getDerived().RebuildTemplateSpecializationType(Template,
4544 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004545 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004546
4547 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004548 // Specializations of template template parameters are represented as
4549 // TemplateSpecializationTypes, and substitution of type alias templates
4550 // within a dependent context can transform them into
4551 // DependentTemplateSpecializationTypes.
4552 if (isa<DependentTemplateSpecializationType>(Result)) {
4553 DependentTemplateSpecializationTypeLoc NewTL
4554 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4555 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4556 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4557 NewTL.setNameLoc(TL.getTemplateNameLoc());
4558 NewTL.setLAngleLoc(TL.getLAngleLoc());
4559 NewTL.setRAngleLoc(TL.getRAngleLoc());
4560 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4561 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4562 return Result;
4563 }
4564
John McCall833ca992009-10-29 08:12:44 +00004565 TemplateSpecializationTypeLoc NewTL
4566 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4567 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4568 NewTL.setLAngleLoc(TL.getLAngleLoc());
4569 NewTL.setRAngleLoc(TL.getRAngleLoc());
4570 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4571 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004572 }
Mike Stump1eb44332009-09-09 15:08:12 +00004573
John McCall833ca992009-10-29 08:12:44 +00004574 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004575}
Mike Stump1eb44332009-09-09 15:08:12 +00004576
Douglas Gregora88f09f2011-02-28 17:23:35 +00004577template <typename Derived>
4578QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4579 TypeLocBuilder &TLB,
4580 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004581 TemplateName Template,
4582 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004583 TemplateArgumentListInfo NewTemplateArgs;
4584 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4585 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4586 typedef TemplateArgumentLocContainerIterator<
4587 DependentTemplateSpecializationTypeLoc> ArgIterator;
4588 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4589 ArgIterator(TL, TL.getNumArgs()),
4590 NewTemplateArgs))
4591 return QualType();
4592
4593 // FIXME: maybe don't rebuild if all the template arguments are the same.
4594
4595 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4596 QualType Result
4597 = getSema().Context.getDependentTemplateSpecializationType(
4598 TL.getTypePtr()->getKeyword(),
4599 DTN->getQualifier(),
4600 DTN->getIdentifier(),
4601 NewTemplateArgs);
4602
4603 DependentTemplateSpecializationTypeLoc NewTL
4604 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4605 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004606
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004607 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregora88f09f2011-02-28 17:23:35 +00004608 NewTL.setNameLoc(TL.getNameLoc());
4609 NewTL.setLAngleLoc(TL.getLAngleLoc());
4610 NewTL.setRAngleLoc(TL.getRAngleLoc());
4611 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4612 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4613 return Result;
4614 }
4615
4616 QualType Result
4617 = getDerived().RebuildTemplateSpecializationType(Template,
4618 TL.getNameLoc(),
4619 NewTemplateArgs);
4620
4621 if (!Result.isNull()) {
4622 /// FIXME: Wrap this in an elaborated-type-specifier?
4623 TemplateSpecializationTypeLoc NewTL
4624 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4625 NewTL.setTemplateNameLoc(TL.getNameLoc());
4626 NewTL.setLAngleLoc(TL.getLAngleLoc());
4627 NewTL.setRAngleLoc(TL.getRAngleLoc());
4628 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4629 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4630 }
4631
4632 return Result;
4633}
4634
Mike Stump1eb44332009-09-09 15:08:12 +00004635template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004636QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004637TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004638 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004639 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004640
Douglas Gregor9e876872011-03-01 18:12:44 +00004641 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004642 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004643 if (TL.getQualifierLoc()) {
4644 QualifierLoc
4645 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4646 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004647 return QualType();
4648 }
Mike Stump1eb44332009-09-09 15:08:12 +00004649
John McCall43fed0d2010-11-12 08:19:04 +00004650 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4651 if (NamedT.isNull())
4652 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004653
Richard Smith3e4c6c42011-05-05 21:57:07 +00004654 // C++0x [dcl.type.elab]p2:
4655 // If the identifier resolves to a typedef-name or the simple-template-id
4656 // resolves to an alias template specialization, the
4657 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004658 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4659 if (const TemplateSpecializationType *TST =
4660 NamedT->getAs<TemplateSpecializationType>()) {
4661 TemplateName Template = TST->getTemplateName();
4662 if (TypeAliasTemplateDecl *TAT =
4663 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4664 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4665 diag::err_tag_reference_non_tag) << 4;
4666 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4667 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004668 }
4669 }
4670
John McCalla2becad2009-10-21 00:40:46 +00004671 QualType Result = TL.getType();
4672 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004673 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004674 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00004675 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004676 T->getKeyword(),
4677 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004678 if (Result.isNull())
4679 return QualType();
4680 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004681
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004682 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004683 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004684 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004685 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004686}
Mike Stump1eb44332009-09-09 15:08:12 +00004687
4688template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004689QualType TreeTransform<Derived>::TransformAttributedType(
4690 TypeLocBuilder &TLB,
4691 AttributedTypeLoc TL) {
4692 const AttributedType *oldType = TL.getTypePtr();
4693 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4694 if (modifiedType.isNull())
4695 return QualType();
4696
4697 QualType result = TL.getType();
4698
4699 // FIXME: dependent operand expressions?
4700 if (getDerived().AlwaysRebuild() ||
4701 modifiedType != oldType->getModifiedType()) {
4702 // TODO: this is really lame; we should really be rebuilding the
4703 // equivalent type from first principles.
4704 QualType equivalentType
4705 = getDerived().TransformType(oldType->getEquivalentType());
4706 if (equivalentType.isNull())
4707 return QualType();
4708 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4709 modifiedType,
4710 equivalentType);
4711 }
4712
4713 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4714 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4715 if (TL.hasAttrOperand())
4716 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4717 if (TL.hasAttrExprOperand())
4718 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4719 else if (TL.hasAttrEnumOperand())
4720 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4721
4722 return result;
4723}
4724
4725template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004726QualType
4727TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4728 ParenTypeLoc TL) {
4729 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4730 if (Inner.isNull())
4731 return QualType();
4732
4733 QualType Result = TL.getType();
4734 if (getDerived().AlwaysRebuild() ||
4735 Inner != TL.getInnerLoc().getType()) {
4736 Result = getDerived().RebuildParenType(Inner);
4737 if (Result.isNull())
4738 return QualType();
4739 }
4740
4741 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4742 NewTL.setLParenLoc(TL.getLParenLoc());
4743 NewTL.setRParenLoc(TL.getRParenLoc());
4744 return Result;
4745}
4746
4747template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004748QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004749 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004750 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004751
Douglas Gregor2494dd02011-03-01 01:34:45 +00004752 NestedNameSpecifierLoc QualifierLoc
4753 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4754 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004755 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004756
John McCall33500952010-06-11 00:33:02 +00004757 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004758 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCall33500952010-06-11 00:33:02 +00004759 TL.getKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004760 QualifierLoc,
4761 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004762 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004763 if (Result.isNull())
4764 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004765
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004766 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4767 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004768 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4769
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004770 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4771 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004772 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004773 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004774 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4775 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004776 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004777 NewTL.setNameLoc(TL.getNameLoc());
4778 }
John McCalla2becad2009-10-21 00:40:46 +00004779 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004780}
Mike Stump1eb44332009-09-09 15:08:12 +00004781
Douglas Gregor577f75a2009-08-04 16:50:30 +00004782template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004783QualType TreeTransform<Derived>::
4784 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004785 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004786 NestedNameSpecifierLoc QualifierLoc;
4787 if (TL.getQualifierLoc()) {
4788 QualifierLoc
4789 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4790 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004791 return QualType();
4792 }
4793
John McCall43fed0d2010-11-12 08:19:04 +00004794 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004795 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004796}
4797
4798template<typename Derived>
4799QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004800TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4801 DependentTemplateSpecializationTypeLoc TL,
4802 NestedNameSpecifierLoc QualifierLoc) {
4803 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4804
4805 TemplateArgumentListInfo NewTemplateArgs;
4806 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4807 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4808
4809 typedef TemplateArgumentLocContainerIterator<
4810 DependentTemplateSpecializationTypeLoc> ArgIterator;
4811 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4812 ArgIterator(TL, TL.getNumArgs()),
4813 NewTemplateArgs))
4814 return QualType();
4815
4816 QualType Result
4817 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4818 QualifierLoc,
4819 T->getIdentifier(),
4820 TL.getNameLoc(),
4821 NewTemplateArgs);
4822 if (Result.isNull())
4823 return QualType();
4824
4825 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4826 QualType NamedT = ElabT->getNamedType();
4827
4828 // Copy information relevant to the template specialization.
4829 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004830 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004831 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004832 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4833 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004834 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004835 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004836
4837 // Copy information relevant to the elaborated type.
4838 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4839 NewTL.setKeywordLoc(TL.getKeywordLoc());
4840 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004841 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4842 DependentTemplateSpecializationTypeLoc SpecTL
4843 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor944cdae2011-03-07 15:13:34 +00004844 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004845 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004846 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004847 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4848 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004849 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004850 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004851 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004852 TemplateSpecializationTypeLoc SpecTL
4853 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004854 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004855 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4856 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004857 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004858 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004859 }
4860 return Result;
4861}
4862
4863template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004864QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4865 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004866 QualType Pattern
4867 = getDerived().TransformType(TLB, TL.getPatternLoc());
4868 if (Pattern.isNull())
4869 return QualType();
4870
4871 QualType Result = TL.getType();
4872 if (getDerived().AlwaysRebuild() ||
4873 Pattern != TL.getPatternLoc().getType()) {
4874 Result = getDerived().RebuildPackExpansionType(Pattern,
4875 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004876 TL.getEllipsisLoc(),
4877 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004878 if (Result.isNull())
4879 return QualType();
4880 }
4881
4882 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4883 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4884 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004885}
4886
4887template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004888QualType
4889TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004890 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004891 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004892 TLB.pushFullCopy(TL);
4893 return TL.getType();
4894}
4895
4896template<typename Derived>
4897QualType
4898TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004899 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004900 // ObjCObjectType is never dependent.
4901 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004902 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004903}
Mike Stump1eb44332009-09-09 15:08:12 +00004904
4905template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004906QualType
4907TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004908 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004909 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004910 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004911 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004912}
4913
Douglas Gregor577f75a2009-08-04 16:50:30 +00004914//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004915// Statement transformation
4916//===----------------------------------------------------------------------===//
4917template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004918StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004919TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004920 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004921}
4922
4923template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004924StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004925TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4926 return getDerived().TransformCompoundStmt(S, false);
4927}
4928
4929template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004930StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004931TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004932 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004933 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004934 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004935 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004936 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4937 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004938 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004939 if (Result.isInvalid()) {
4940 // Immediately fail if this was a DeclStmt, since it's very
4941 // likely that this will cause problems for future statements.
4942 if (isa<DeclStmt>(*B))
4943 return StmtError();
4944
4945 // Otherwise, just keep processing substatements and fail later.
4946 SubStmtInvalid = true;
4947 continue;
4948 }
Mike Stump1eb44332009-09-09 15:08:12 +00004949
Douglas Gregor43959a92009-08-20 07:17:43 +00004950 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4951 Statements.push_back(Result.takeAs<Stmt>());
4952 }
Mike Stump1eb44332009-09-09 15:08:12 +00004953
John McCall7114cba2010-08-27 19:56:05 +00004954 if (SubStmtInvalid)
4955 return StmtError();
4956
Douglas Gregor43959a92009-08-20 07:17:43 +00004957 if (!getDerived().AlwaysRebuild() &&
4958 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004959 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004960
4961 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4962 move_arg(Statements),
4963 S->getRBracLoc(),
4964 IsStmtExpr);
4965}
Mike Stump1eb44332009-09-09 15:08:12 +00004966
Douglas Gregor43959a92009-08-20 07:17:43 +00004967template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004968StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004969TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004970 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00004971 {
4972 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00004973 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004974
Eli Friedman264c1f82009-11-19 03:14:00 +00004975 // Transform the left-hand case value.
4976 LHS = getDerived().TransformExpr(S->getLHS());
4977 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004978 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004979
Eli Friedman264c1f82009-11-19 03:14:00 +00004980 // Transform the right-hand case value (for the GNU case-range extension).
4981 RHS = getDerived().TransformExpr(S->getRHS());
4982 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004983 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00004984 }
Mike Stump1eb44332009-09-09 15:08:12 +00004985
Douglas Gregor43959a92009-08-20 07:17:43 +00004986 // Build the case statement.
4987 // Case statements are always rebuilt so that they will attached to their
4988 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004989 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004990 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004991 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004992 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004993 S->getColonLoc());
4994 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004995 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004996
Douglas Gregor43959a92009-08-20 07:17:43 +00004997 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00004998 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004999 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005000 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005001
Douglas Gregor43959a92009-08-20 07:17:43 +00005002 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005003 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005004}
5005
5006template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005007StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005008TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005009 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005010 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005011 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005012 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005013
Douglas Gregor43959a92009-08-20 07:17:43 +00005014 // Default statements are always rebuilt
5015 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005016 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005017}
Mike Stump1eb44332009-09-09 15:08:12 +00005018
Douglas Gregor43959a92009-08-20 07:17:43 +00005019template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005020StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005021TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005022 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005023 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005024 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005025
Chris Lattner57ad3782011-02-17 20:34:02 +00005026 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5027 S->getDecl());
5028 if (!LD)
5029 return StmtError();
5030
5031
Douglas Gregor43959a92009-08-20 07:17:43 +00005032 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005033 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005034 cast<LabelDecl>(LD), SourceLocation(),
5035 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005036}
Mike Stump1eb44332009-09-09 15:08:12 +00005037
Douglas Gregor43959a92009-08-20 07:17:43 +00005038template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005039StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005040TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005041 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005042 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005043 VarDecl *ConditionVar = 0;
5044 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005045 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005046 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005047 getDerived().TransformDefinition(
5048 S->getConditionVariable()->getLocation(),
5049 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005050 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005051 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005052 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005053 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005054
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005055 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005056 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005057
5058 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005059 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005060 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5061 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005062 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005063 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005064
John McCall9ae2f072010-08-23 23:25:46 +00005065 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005066 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005067 }
Sean Huntc3021132010-05-05 15:23:54 +00005068
John McCall9ae2f072010-08-23 23:25:46 +00005069 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5070 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005071 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005072
Douglas Gregor43959a92009-08-20 07:17:43 +00005073 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005074 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005075 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005076 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005077
Douglas Gregor43959a92009-08-20 07:17:43 +00005078 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005079 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005080 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005081 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005082
Douglas Gregor43959a92009-08-20 07:17:43 +00005083 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005084 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005085 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005086 Then.get() == S->getThen() &&
5087 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005088 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005089
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005090 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005091 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005092 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005093}
5094
5095template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005096StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005097TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005098 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005099 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005100 VarDecl *ConditionVar = 0;
5101 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005102 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005103 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005104 getDerived().TransformDefinition(
5105 S->getConditionVariable()->getLocation(),
5106 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005107 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005108 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005109 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005110 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005111
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005112 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005113 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005114 }
Mike Stump1eb44332009-09-09 15:08:12 +00005115
Douglas Gregor43959a92009-08-20 07:17:43 +00005116 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005117 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005118 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005119 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005120 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005121 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005122
Douglas Gregor43959a92009-08-20 07:17:43 +00005123 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005124 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005125 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005126 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005127
Douglas Gregor43959a92009-08-20 07:17:43 +00005128 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005129 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5130 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005131}
Mike Stump1eb44332009-09-09 15:08:12 +00005132
Douglas Gregor43959a92009-08-20 07:17:43 +00005133template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005134StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005135TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005136 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005137 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005138 VarDecl *ConditionVar = 0;
5139 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005140 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005141 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005142 getDerived().TransformDefinition(
5143 S->getConditionVariable()->getLocation(),
5144 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005145 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005146 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005147 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005148 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005149
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005150 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005151 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005152
5153 if (S->getCond()) {
5154 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005155 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5156 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005157 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005158 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005159 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005160 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005161 }
Mike Stump1eb44332009-09-09 15:08:12 +00005162
John McCall9ae2f072010-08-23 23:25:46 +00005163 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5164 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005165 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005166
Douglas Gregor43959a92009-08-20 07:17:43 +00005167 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005168 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005169 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005170 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005171
Douglas Gregor43959a92009-08-20 07:17:43 +00005172 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005173 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005174 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005175 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005176 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005177
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005178 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005179 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005180}
Mike Stump1eb44332009-09-09 15:08:12 +00005181
Douglas Gregor43959a92009-08-20 07:17:43 +00005182template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005183StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005184TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005185 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005186 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005187 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005188 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005189
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005190 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005191 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005192 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005193 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005194
Douglas Gregor43959a92009-08-20 07:17:43 +00005195 if (!getDerived().AlwaysRebuild() &&
5196 Cond.get() == S->getCond() &&
5197 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005198 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005199
John McCall9ae2f072010-08-23 23:25:46 +00005200 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5201 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005202 S->getRParenLoc());
5203}
Mike Stump1eb44332009-09-09 15:08:12 +00005204
Douglas Gregor43959a92009-08-20 07:17:43 +00005205template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005206StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005207TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005208 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005209 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005210 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005211 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005212
Douglas Gregor43959a92009-08-20 07:17:43 +00005213 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005214 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005215 VarDecl *ConditionVar = 0;
5216 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005217 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005218 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005219 getDerived().TransformDefinition(
5220 S->getConditionVariable()->getLocation(),
5221 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005222 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005223 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005224 } else {
5225 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005226
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005227 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005228 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005229
5230 if (S->getCond()) {
5231 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005232 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5233 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005234 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005235 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005236
John McCall9ae2f072010-08-23 23:25:46 +00005237 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005238 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005239 }
Mike Stump1eb44332009-09-09 15:08:12 +00005240
John McCall9ae2f072010-08-23 23:25:46 +00005241 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5242 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005243 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005244
Douglas Gregor43959a92009-08-20 07:17:43 +00005245 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005246 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005247 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005248 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005249
John McCall9ae2f072010-08-23 23:25:46 +00005250 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5251 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005252 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005253
Douglas Gregor43959a92009-08-20 07:17:43 +00005254 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005255 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005256 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005257 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005258
Douglas Gregor43959a92009-08-20 07:17:43 +00005259 if (!getDerived().AlwaysRebuild() &&
5260 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005261 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005262 Inc.get() == S->getInc() &&
5263 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005264 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005265
Douglas Gregor43959a92009-08-20 07:17:43 +00005266 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005267 Init.get(), FullCond, ConditionVar,
5268 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005269}
5270
5271template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005272StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005273TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005274 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5275 S->getLabel());
5276 if (!LD)
5277 return StmtError();
5278
Douglas Gregor43959a92009-08-20 07:17:43 +00005279 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005280 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005281 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005282}
5283
5284template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005285StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005286TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005287 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005288 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005289 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005290
Douglas Gregor43959a92009-08-20 07:17:43 +00005291 if (!getDerived().AlwaysRebuild() &&
5292 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005293 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005294
5295 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005296 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005297}
5298
5299template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005300StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005301TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005302 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005303}
Mike Stump1eb44332009-09-09 15:08:12 +00005304
Douglas Gregor43959a92009-08-20 07:17:43 +00005305template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005306StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005307TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005308 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005309}
Mike Stump1eb44332009-09-09 15:08:12 +00005310
Douglas Gregor43959a92009-08-20 07:17:43 +00005311template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005312StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005313TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005314 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005315 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005316 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005317
Mike Stump1eb44332009-09-09 15:08:12 +00005318 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005319 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005320 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005321}
Mike Stump1eb44332009-09-09 15:08:12 +00005322
Douglas Gregor43959a92009-08-20 07:17:43 +00005323template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005324StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005325TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005326 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005327 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005328 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5329 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005330 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5331 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005332 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005333 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005334
Douglas Gregor43959a92009-08-20 07:17:43 +00005335 if (Transformed != *D)
5336 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005337
Douglas Gregor43959a92009-08-20 07:17:43 +00005338 Decls.push_back(Transformed);
5339 }
Mike Stump1eb44332009-09-09 15:08:12 +00005340
Douglas Gregor43959a92009-08-20 07:17:43 +00005341 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005342 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005343
5344 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005345 S->getStartLoc(), S->getEndLoc());
5346}
Mike Stump1eb44332009-09-09 15:08:12 +00005347
Douglas Gregor43959a92009-08-20 07:17:43 +00005348template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005349StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005350TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005351
John McCallca0408f2010-08-23 06:44:23 +00005352 ASTOwningVector<Expr*> Constraints(getSema());
5353 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005354 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005355
John McCall60d7b3a2010-08-24 06:29:42 +00005356 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005357 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005358
5359 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005360
Anders Carlsson703e3942010-01-24 05:50:09 +00005361 // Go through the outputs.
5362 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005363 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005364
Anders Carlsson703e3942010-01-24 05:50:09 +00005365 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005366 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005367
Anders Carlsson703e3942010-01-24 05:50:09 +00005368 // Transform the output expr.
5369 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005370 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005371 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005372 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005373
Anders Carlsson703e3942010-01-24 05:50:09 +00005374 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005375
John McCall9ae2f072010-08-23 23:25:46 +00005376 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005377 }
Sean Huntc3021132010-05-05 15:23:54 +00005378
Anders Carlsson703e3942010-01-24 05:50:09 +00005379 // Go through the inputs.
5380 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005381 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005382
Anders Carlsson703e3942010-01-24 05:50:09 +00005383 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005384 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005385
Anders Carlsson703e3942010-01-24 05:50:09 +00005386 // Transform the input expr.
5387 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005388 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005389 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005390 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005391
Anders Carlsson703e3942010-01-24 05:50:09 +00005392 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005393
John McCall9ae2f072010-08-23 23:25:46 +00005394 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005395 }
Sean Huntc3021132010-05-05 15:23:54 +00005396
Anders Carlsson703e3942010-01-24 05:50:09 +00005397 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005398 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005399
5400 // Go through the clobbers.
5401 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005402 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005403
5404 // No need to transform the asm string literal.
5405 AsmString = SemaRef.Owned(S->getAsmString());
5406
5407 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5408 S->isSimple(),
5409 S->isVolatile(),
5410 S->getNumOutputs(),
5411 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005412 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005413 move_arg(Constraints),
5414 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005415 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005416 move_arg(Clobbers),
5417 S->getRParenLoc(),
5418 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005419}
5420
5421
5422template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005423StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005424TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005425 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005426 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005427 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005428 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005429
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005430 // Transform the @catch statements (if present).
5431 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005432 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005433 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005434 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005435 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005436 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005437 if (Catch.get() != S->getCatchStmt(I))
5438 AnyCatchChanged = true;
5439 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005440 }
Sean Huntc3021132010-05-05 15:23:54 +00005441
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005442 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005443 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005444 if (S->getFinallyStmt()) {
5445 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5446 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005447 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005448 }
5449
5450 // If nothing changed, just retain this statement.
5451 if (!getDerived().AlwaysRebuild() &&
5452 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005453 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005454 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005455 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005456
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005457 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005458 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5459 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005460}
Mike Stump1eb44332009-09-09 15:08:12 +00005461
Douglas Gregor43959a92009-08-20 07:17:43 +00005462template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005463StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005464TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005465 // Transform the @catch parameter, if there is one.
5466 VarDecl *Var = 0;
5467 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5468 TypeSourceInfo *TSInfo = 0;
5469 if (FromVar->getTypeSourceInfo()) {
5470 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5471 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005472 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005473 }
Sean Huntc3021132010-05-05 15:23:54 +00005474
Douglas Gregorbe270a02010-04-26 17:57:08 +00005475 QualType T;
5476 if (TSInfo)
5477 T = TSInfo->getType();
5478 else {
5479 T = getDerived().TransformType(FromVar->getType());
5480 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005481 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005482 }
Sean Huntc3021132010-05-05 15:23:54 +00005483
Douglas Gregorbe270a02010-04-26 17:57:08 +00005484 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5485 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005486 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005487 }
Sean Huntc3021132010-05-05 15:23:54 +00005488
John McCall60d7b3a2010-08-24 06:29:42 +00005489 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005490 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005491 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005492
5493 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005494 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005495 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005496}
Mike Stump1eb44332009-09-09 15:08:12 +00005497
Douglas Gregor43959a92009-08-20 07:17:43 +00005498template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005499StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005500TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005501 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005502 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005503 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005504 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005505
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005506 // If nothing changed, just retain this statement.
5507 if (!getDerived().AlwaysRebuild() &&
5508 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005509 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005510
5511 // Build a new statement.
5512 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005513 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005514}
Mike Stump1eb44332009-09-09 15:08:12 +00005515
Douglas Gregor43959a92009-08-20 07:17:43 +00005516template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005517StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005518TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005519 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005520 if (S->getThrowExpr()) {
5521 Operand = getDerived().TransformExpr(S->getThrowExpr());
5522 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005523 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005524 }
Sean Huntc3021132010-05-05 15:23:54 +00005525
Douglas Gregord1377b22010-04-22 21:44:01 +00005526 if (!getDerived().AlwaysRebuild() &&
5527 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005528 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005529
John McCall9ae2f072010-08-23 23:25:46 +00005530 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005531}
Mike Stump1eb44332009-09-09 15:08:12 +00005532
Douglas Gregor43959a92009-08-20 07:17:43 +00005533template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005534StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005535TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005536 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005537 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005538 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005539 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005540 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005541 Object =
5542 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5543 Object.get());
5544 if (Object.isInvalid())
5545 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005546
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005547 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005548 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005549 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005550 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005551
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005552 // If nothing change, just retain the current statement.
5553 if (!getDerived().AlwaysRebuild() &&
5554 Object.get() == S->getSynchExpr() &&
5555 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005556 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005557
5558 // Build a new statement.
5559 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005560 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005561}
5562
5563template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005564StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005565TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5566 ObjCAutoreleasePoolStmt *S) {
5567 // Transform the body.
5568 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5569 if (Body.isInvalid())
5570 return StmtError();
5571
5572 // If nothing changed, just retain this statement.
5573 if (!getDerived().AlwaysRebuild() &&
5574 Body.get() == S->getSubStmt())
5575 return SemaRef.Owned(S);
5576
5577 // Build a new statement.
5578 return getDerived().RebuildObjCAutoreleasePoolStmt(
5579 S->getAtLoc(), Body.get());
5580}
5581
5582template<typename Derived>
5583StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005584TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005585 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005586 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005587 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005588 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005589 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005590
Douglas Gregorc3203e72010-04-22 23:10:45 +00005591 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005592 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005593 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005594 return StmtError();
John McCall990567c2011-07-27 01:07:15 +00005595 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5596 Collection.take());
5597 if (Collection.isInvalid())
5598 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005599
Douglas Gregorc3203e72010-04-22 23:10:45 +00005600 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005601 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005602 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005603 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005604
Douglas Gregorc3203e72010-04-22 23:10:45 +00005605 // If nothing changed, just retain this statement.
5606 if (!getDerived().AlwaysRebuild() &&
5607 Element.get() == S->getElement() &&
5608 Collection.get() == S->getCollection() &&
5609 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005610 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005611
Douglas Gregorc3203e72010-04-22 23:10:45 +00005612 // Build a new statement.
5613 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5614 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005615 Element.get(),
5616 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005617 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005618 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005619}
5620
5621
5622template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005623StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005624TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5625 // Transform the exception declaration, if any.
5626 VarDecl *Var = 0;
5627 if (S->getExceptionDecl()) {
5628 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005629 TypeSourceInfo *T = getDerived().TransformType(
5630 ExceptionDecl->getTypeSourceInfo());
5631 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005632 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005633
Douglas Gregor83cb9422010-09-09 17:09:21 +00005634 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005635 ExceptionDecl->getInnerLocStart(),
5636 ExceptionDecl->getLocation(),
5637 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005638 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005639 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005640 }
Mike Stump1eb44332009-09-09 15:08:12 +00005641
Douglas Gregor43959a92009-08-20 07:17:43 +00005642 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005643 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005644 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005645 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005646
Douglas Gregor43959a92009-08-20 07:17:43 +00005647 if (!getDerived().AlwaysRebuild() &&
5648 !Var &&
5649 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005650 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005651
5652 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5653 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005654 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005655}
Mike Stump1eb44332009-09-09 15:08:12 +00005656
Douglas Gregor43959a92009-08-20 07:17:43 +00005657template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005658StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005659TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5660 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005661 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005662 = getDerived().TransformCompoundStmt(S->getTryBlock());
5663 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005664 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005665
Douglas Gregor43959a92009-08-20 07:17:43 +00005666 // Transform the handlers.
5667 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005668 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005669 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005670 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005671 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5672 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005673 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005674
Douglas Gregor43959a92009-08-20 07:17:43 +00005675 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5676 Handlers.push_back(Handler.takeAs<Stmt>());
5677 }
Mike Stump1eb44332009-09-09 15:08:12 +00005678
Douglas Gregor43959a92009-08-20 07:17:43 +00005679 if (!getDerived().AlwaysRebuild() &&
5680 TryBlock.get() == S->getTryBlock() &&
5681 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005682 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005683
John McCall9ae2f072010-08-23 23:25:46 +00005684 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005685 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005686}
Mike Stump1eb44332009-09-09 15:08:12 +00005687
Richard Smithad762fc2011-04-14 22:09:26 +00005688template<typename Derived>
5689StmtResult
5690TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5691 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5692 if (Range.isInvalid())
5693 return StmtError();
5694
5695 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5696 if (BeginEnd.isInvalid())
5697 return StmtError();
5698
5699 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5700 if (Cond.isInvalid())
5701 return StmtError();
5702
5703 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5704 if (Inc.isInvalid())
5705 return StmtError();
5706
5707 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5708 if (LoopVar.isInvalid())
5709 return StmtError();
5710
5711 StmtResult NewStmt = S;
5712 if (getDerived().AlwaysRebuild() ||
5713 Range.get() != S->getRangeStmt() ||
5714 BeginEnd.get() != S->getBeginEndStmt() ||
5715 Cond.get() != S->getCond() ||
5716 Inc.get() != S->getInc() ||
5717 LoopVar.get() != S->getLoopVarStmt())
5718 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5719 S->getColonLoc(), Range.get(),
5720 BeginEnd.get(), Cond.get(),
5721 Inc.get(), LoopVar.get(),
5722 S->getRParenLoc());
5723
5724 StmtResult Body = getDerived().TransformStmt(S->getBody());
5725 if (Body.isInvalid())
5726 return StmtError();
5727
5728 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5729 // it now so we have a new statement to attach the body to.
5730 if (Body.get() != S->getBody() && NewStmt.get() == S)
5731 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5732 S->getColonLoc(), Range.get(),
5733 BeginEnd.get(), Cond.get(),
5734 Inc.get(), LoopVar.get(),
5735 S->getRParenLoc());
5736
5737 if (NewStmt.get() == S)
5738 return SemaRef.Owned(S);
5739
5740 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5741}
5742
John Wiegley28bbe4b2011-04-28 01:08:34 +00005743template<typename Derived>
5744StmtResult
5745TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5746 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5747 if(TryBlock.isInvalid()) return StmtError();
5748
5749 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5750 if(!getDerived().AlwaysRebuild() &&
5751 TryBlock.get() == S->getTryBlock() &&
5752 Handler.get() == S->getHandler())
5753 return SemaRef.Owned(S);
5754
5755 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5756 S->getTryLoc(),
5757 TryBlock.take(),
5758 Handler.take());
5759}
5760
5761template<typename Derived>
5762StmtResult
5763TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5764 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5765 if(Block.isInvalid()) return StmtError();
5766
5767 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5768 Block.take());
5769}
5770
5771template<typename Derived>
5772StmtResult
5773TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5774 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5775 if(FilterExpr.isInvalid()) return StmtError();
5776
5777 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5778 if(Block.isInvalid()) return StmtError();
5779
5780 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5781 FilterExpr.take(),
5782 Block.take());
5783}
5784
5785template<typename Derived>
5786StmtResult
5787TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5788 if(isa<SEHFinallyStmt>(Handler))
5789 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5790 else
5791 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5792}
5793
Douglas Gregor43959a92009-08-20 07:17:43 +00005794//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005795// Expression transformation
5796//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005797template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005798ExprResult
John McCall454feb92009-12-08 09:21:05 +00005799TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005800 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005801}
Mike Stump1eb44332009-09-09 15:08:12 +00005802
5803template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005804ExprResult
John McCall454feb92009-12-08 09:21:05 +00005805TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005806 NestedNameSpecifierLoc QualifierLoc;
5807 if (E->getQualifierLoc()) {
5808 QualifierLoc
5809 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5810 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005811 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005812 }
John McCalldbd872f2009-12-08 09:08:17 +00005813
5814 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005815 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5816 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005817 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005818 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005819
John McCallec8045d2010-08-17 21:27:17 +00005820 DeclarationNameInfo NameInfo = E->getNameInfo();
5821 if (NameInfo.getName()) {
5822 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5823 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005824 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005825 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005826
5827 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00005828 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00005829 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005830 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00005831 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005832
5833 // Mark it referenced in the new context regardless.
5834 // FIXME: this is a bit instantiation-specific.
5835 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5836
John McCall3fa5cae2010-10-26 07:05:15 +00005837 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00005838 }
John McCalldbd872f2009-12-08 09:08:17 +00005839
5840 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00005841 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005842 TemplateArgs = &TransArgs;
5843 TransArgs.setLAngleLoc(E->getLAngleLoc());
5844 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005845 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5846 E->getNumTemplateArgs(),
5847 TransArgs))
5848 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00005849 }
5850
Douglas Gregor40d96a62011-02-28 21:54:11 +00005851 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5852 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005853}
Mike Stump1eb44332009-09-09 15:08:12 +00005854
Douglas Gregorb98b1992009-08-11 05:31:07 +00005855template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005856ExprResult
John McCall454feb92009-12-08 09:21:05 +00005857TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005858 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005859}
Mike Stump1eb44332009-09-09 15:08:12 +00005860
Douglas Gregorb98b1992009-08-11 05:31:07 +00005861template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005862ExprResult
John McCall454feb92009-12-08 09:21:05 +00005863TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005864 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005865}
Mike Stump1eb44332009-09-09 15:08:12 +00005866
Douglas Gregorb98b1992009-08-11 05:31:07 +00005867template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005868ExprResult
John McCall454feb92009-12-08 09:21:05 +00005869TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005870 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005871}
Mike Stump1eb44332009-09-09 15:08:12 +00005872
Douglas Gregorb98b1992009-08-11 05:31:07 +00005873template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005874ExprResult
John McCall454feb92009-12-08 09:21:05 +00005875TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005876 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005877}
Mike Stump1eb44332009-09-09 15:08:12 +00005878
Douglas Gregorb98b1992009-08-11 05:31:07 +00005879template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005880ExprResult
John McCall454feb92009-12-08 09:21:05 +00005881TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005882 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005883}
5884
5885template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005886ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00005887TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5888 ExprResult ControllingExpr =
5889 getDerived().TransformExpr(E->getControllingExpr());
5890 if (ControllingExpr.isInvalid())
5891 return ExprError();
5892
Chris Lattner686775d2011-07-20 06:58:45 +00005893 SmallVector<Expr *, 4> AssocExprs;
5894 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00005895 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5896 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5897 if (TS) {
5898 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5899 if (!AssocType)
5900 return ExprError();
5901 AssocTypes.push_back(AssocType);
5902 } else {
5903 AssocTypes.push_back(0);
5904 }
5905
5906 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5907 if (AssocExpr.isInvalid())
5908 return ExprError();
5909 AssocExprs.push_back(AssocExpr.release());
5910 }
5911
5912 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5913 E->getDefaultLoc(),
5914 E->getRParenLoc(),
5915 ControllingExpr.release(),
5916 AssocTypes.data(),
5917 AssocExprs.data(),
5918 E->getNumAssocs());
5919}
5920
5921template<typename Derived>
5922ExprResult
John McCall454feb92009-12-08 09:21:05 +00005923TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005924 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005925 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005926 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005927
Douglas Gregorb98b1992009-08-11 05:31:07 +00005928 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005929 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005930
John McCall9ae2f072010-08-23 23:25:46 +00005931 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005932 E->getRParen());
5933}
5934
Mike Stump1eb44332009-09-09 15:08:12 +00005935template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005936ExprResult
John McCall454feb92009-12-08 09:21:05 +00005937TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005938 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005939 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005940 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005941
Douglas Gregorb98b1992009-08-11 05:31:07 +00005942 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005943 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005944
Douglas Gregorb98b1992009-08-11 05:31:07 +00005945 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5946 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005947 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005948}
Mike Stump1eb44332009-09-09 15:08:12 +00005949
Douglas Gregorb98b1992009-08-11 05:31:07 +00005950template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005951ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005952TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5953 // Transform the type.
5954 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5955 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00005956 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005957
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005958 // Transform all of the components into components similar to what the
5959 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00005960 // FIXME: It would be slightly more efficient in the non-dependent case to
5961 // just map FieldDecls, rather than requiring the rebuilder to look for
5962 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005963 // template code that we don't care.
5964 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00005965 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005966 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00005967 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005968 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5969 const Node &ON = E->getComponent(I);
5970 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00005971 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00005972 Comp.LocStart = ON.getSourceRange().getBegin();
5973 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005974 switch (ON.getKind()) {
5975 case Node::Array: {
5976 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00005977 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005978 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005979 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005980
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005981 ExprChanged = ExprChanged || Index.get() != FromIndex;
5982 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00005983 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005984 break;
5985 }
Sean Huntc3021132010-05-05 15:23:54 +00005986
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005987 case Node::Field:
5988 case Node::Identifier:
5989 Comp.isBrackets = false;
5990 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00005991 if (!Comp.U.IdentInfo)
5992 continue;
Sean Huntc3021132010-05-05 15:23:54 +00005993
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005994 break;
Sean Huntc3021132010-05-05 15:23:54 +00005995
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00005996 case Node::Base:
5997 // Will be recomputed during the rebuild.
5998 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005999 }
Sean Huntc3021132010-05-05 15:23:54 +00006000
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006001 Components.push_back(Comp);
6002 }
Sean Huntc3021132010-05-05 15:23:54 +00006003
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006004 // If nothing changed, retain the existing expression.
6005 if (!getDerived().AlwaysRebuild() &&
6006 Type == E->getTypeSourceInfo() &&
6007 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006008 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006009
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006010 // Build a new offsetof expression.
6011 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6012 Components.data(), Components.size(),
6013 E->getRParenLoc());
6014}
6015
6016template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006017ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006018TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6019 assert(getDerived().AlreadyTransformed(E->getType()) &&
6020 "opaque value expression requires transformation");
6021 return SemaRef.Owned(E);
6022}
6023
6024template<typename Derived>
6025ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006026TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6027 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006028 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006029 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006030
John McCalla93c9342009-12-07 02:54:59 +00006031 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006032 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006033 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006034
John McCall5ab75172009-11-04 07:28:41 +00006035 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006036 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006037
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006038 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6039 E->getKind(),
6040 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006041 }
Mike Stump1eb44332009-09-09 15:08:12 +00006042
John McCall60d7b3a2010-08-24 06:29:42 +00006043 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00006044 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006045 // C++0x [expr.sizeof]p1:
6046 // The operand is either an expression, which is an unevaluated operand
6047 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00006048 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006049
Douglas Gregorb98b1992009-08-11 05:31:07 +00006050 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6051 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006052 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006053
Douglas Gregorb98b1992009-08-11 05:31:07 +00006054 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006055 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006056 }
Mike Stump1eb44332009-09-09 15:08:12 +00006057
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006058 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6059 E->getOperatorLoc(),
6060 E->getKind(),
6061 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006062}
Mike Stump1eb44332009-09-09 15:08:12 +00006063
Douglas Gregorb98b1992009-08-11 05:31:07 +00006064template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006065ExprResult
John McCall454feb92009-12-08 09:21:05 +00006066TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006067 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006068 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006069 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006070
John McCall60d7b3a2010-08-24 06:29:42 +00006071 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006072 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006073 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006074
6075
Douglas Gregorb98b1992009-08-11 05:31:07 +00006076 if (!getDerived().AlwaysRebuild() &&
6077 LHS.get() == E->getLHS() &&
6078 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006079 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006080
John McCall9ae2f072010-08-23 23:25:46 +00006081 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006082 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006083 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006084 E->getRBracketLoc());
6085}
Mike Stump1eb44332009-09-09 15:08:12 +00006086
6087template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006088ExprResult
John McCall454feb92009-12-08 09:21:05 +00006089TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006090 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006091 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006092 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006093 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006094
6095 // Transform arguments.
6096 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006097 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006098 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6099 &ArgChanged))
6100 return ExprError();
6101
Douglas Gregorb98b1992009-08-11 05:31:07 +00006102 if (!getDerived().AlwaysRebuild() &&
6103 Callee.get() == E->getCallee() &&
6104 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006105 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006106
Douglas Gregorb98b1992009-08-11 05:31:07 +00006107 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006108 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006109 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006110 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006111 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006112 E->getRParenLoc());
6113}
Mike Stump1eb44332009-09-09 15:08:12 +00006114
6115template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006116ExprResult
John McCall454feb92009-12-08 09:21:05 +00006117TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006118 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006119 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006120 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006121
Douglas Gregor40d96a62011-02-28 21:54:11 +00006122 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006123 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006124 QualifierLoc
6125 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6126
6127 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006128 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006129 }
Mike Stump1eb44332009-09-09 15:08:12 +00006130
Eli Friedmanf595cc42009-12-04 06:40:45 +00006131 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006132 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6133 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006134 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006135 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006136
John McCall6bb80172010-03-30 21:47:33 +00006137 NamedDecl *FoundDecl = E->getFoundDecl();
6138 if (FoundDecl == E->getMemberDecl()) {
6139 FoundDecl = Member;
6140 } else {
6141 FoundDecl = cast_or_null<NamedDecl>(
6142 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6143 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006144 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006145 }
6146
Douglas Gregorb98b1992009-08-11 05:31:07 +00006147 if (!getDerived().AlwaysRebuild() &&
6148 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006149 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006150 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006151 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006152 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006153
Anders Carlsson1f240322009-12-22 05:24:09 +00006154 // Mark it referenced in the new context regardless.
6155 // FIXME: this is a bit instantiation-specific.
6156 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00006157 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006158 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006159
John McCalld5532b62009-11-23 01:53:49 +00006160 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006161 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006162 TransArgs.setLAngleLoc(E->getLAngleLoc());
6163 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006164 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6165 E->getNumTemplateArgs(),
6166 TransArgs))
6167 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006168 }
Sean Huntc3021132010-05-05 15:23:54 +00006169
Douglas Gregorb98b1992009-08-11 05:31:07 +00006170 // FIXME: Bogus source location for the operator
6171 SourceLocation FakeOperatorLoc
6172 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6173
John McCallc2233c52010-01-15 08:34:02 +00006174 // FIXME: to do this check properly, we will need to preserve the
6175 // first-qualifier-in-scope here, just in case we had a dependent
6176 // base (and therefore couldn't do the check) and a
6177 // nested-name-qualifier (and therefore could do the lookup).
6178 NamedDecl *FirstQualifierInScope = 0;
6179
John McCall9ae2f072010-08-23 23:25:46 +00006180 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006181 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006182 QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006183 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006184 Member,
John McCall6bb80172010-03-30 21:47:33 +00006185 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006186 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006187 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006188 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006189}
Mike Stump1eb44332009-09-09 15:08:12 +00006190
Douglas Gregorb98b1992009-08-11 05:31:07 +00006191template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006192ExprResult
John McCall454feb92009-12-08 09:21:05 +00006193TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006194 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006195 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006196 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006197
John McCall60d7b3a2010-08-24 06:29:42 +00006198 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006199 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006200 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006201
Douglas Gregorb98b1992009-08-11 05:31:07 +00006202 if (!getDerived().AlwaysRebuild() &&
6203 LHS.get() == E->getLHS() &&
6204 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006205 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006206
Douglas Gregorb98b1992009-08-11 05:31:07 +00006207 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006208 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006209}
6210
Mike Stump1eb44332009-09-09 15:08:12 +00006211template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006212ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006213TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006214 CompoundAssignOperator *E) {
6215 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006216}
Mike Stump1eb44332009-09-09 15:08:12 +00006217
Douglas Gregorb98b1992009-08-11 05:31:07 +00006218template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006219ExprResult TreeTransform<Derived>::
6220TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6221 // Just rebuild the common and RHS expressions and see whether we
6222 // get any changes.
6223
6224 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6225 if (commonExpr.isInvalid())
6226 return ExprError();
6227
6228 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6229 if (rhs.isInvalid())
6230 return ExprError();
6231
6232 if (!getDerived().AlwaysRebuild() &&
6233 commonExpr.get() == e->getCommon() &&
6234 rhs.get() == e->getFalseExpr())
6235 return SemaRef.Owned(e);
6236
6237 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6238 e->getQuestionLoc(),
6239 0,
6240 e->getColonLoc(),
6241 rhs.get());
6242}
6243
6244template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006245ExprResult
John McCall454feb92009-12-08 09:21:05 +00006246TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006247 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006248 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006249 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006250
John McCall60d7b3a2010-08-24 06:29:42 +00006251 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006252 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006253 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006254
John McCall60d7b3a2010-08-24 06:29:42 +00006255 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006256 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006257 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006258
Douglas Gregorb98b1992009-08-11 05:31:07 +00006259 if (!getDerived().AlwaysRebuild() &&
6260 Cond.get() == E->getCond() &&
6261 LHS.get() == E->getLHS() &&
6262 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006263 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006264
John McCall9ae2f072010-08-23 23:25:46 +00006265 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006266 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006267 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006268 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006269 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006270}
Mike Stump1eb44332009-09-09 15:08:12 +00006271
6272template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006273ExprResult
John McCall454feb92009-12-08 09:21:05 +00006274TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006275 // Implicit casts are eliminated during transformation, since they
6276 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006277 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006278}
Mike Stump1eb44332009-09-09 15:08:12 +00006279
Douglas Gregorb98b1992009-08-11 05:31:07 +00006280template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006281ExprResult
John McCall454feb92009-12-08 09:21:05 +00006282TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006283 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6284 if (!Type)
6285 return ExprError();
6286
John McCall60d7b3a2010-08-24 06:29:42 +00006287 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006288 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006289 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006290 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006291
Douglas Gregorb98b1992009-08-11 05:31:07 +00006292 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006293 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006294 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006295 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006296
John McCall9d125032010-01-15 18:39:57 +00006297 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006298 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006299 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006300 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006301}
Mike Stump1eb44332009-09-09 15:08:12 +00006302
Douglas Gregorb98b1992009-08-11 05:31:07 +00006303template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006304ExprResult
John McCall454feb92009-12-08 09:21:05 +00006305TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006306 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6307 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6308 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006309 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006310
John McCall60d7b3a2010-08-24 06:29:42 +00006311 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006312 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006313 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006314
Douglas Gregorb98b1992009-08-11 05:31:07 +00006315 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006316 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006317 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00006318 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006319
John McCall1d7d8d62010-01-19 22:33:45 +00006320 // Note: the expression type doesn't necessarily match the
6321 // type-as-written, but that's okay, because it should always be
6322 // derivable from the initializer.
6323
John McCall42f56b52010-01-18 19:35:47 +00006324 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006325 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006326 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006327}
Mike Stump1eb44332009-09-09 15:08:12 +00006328
Douglas Gregorb98b1992009-08-11 05:31:07 +00006329template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006330ExprResult
John McCall454feb92009-12-08 09:21:05 +00006331TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006332 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006333 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006334 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006335
Douglas Gregorb98b1992009-08-11 05:31:07 +00006336 if (!getDerived().AlwaysRebuild() &&
6337 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006338 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006339
Douglas Gregorb98b1992009-08-11 05:31:07 +00006340 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006341 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006342 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006343 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006344 E->getAccessorLoc(),
6345 E->getAccessor());
6346}
Mike Stump1eb44332009-09-09 15:08:12 +00006347
Douglas Gregorb98b1992009-08-11 05:31:07 +00006348template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006349ExprResult
John McCall454feb92009-12-08 09:21:05 +00006350TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006351 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006352
John McCallca0408f2010-08-23 06:44:23 +00006353 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006354 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6355 Inits, &InitChanged))
6356 return ExprError();
6357
Douglas Gregorb98b1992009-08-11 05:31:07 +00006358 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006359 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006360
Douglas Gregorb98b1992009-08-11 05:31:07 +00006361 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006362 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006363}
Mike Stump1eb44332009-09-09 15:08:12 +00006364
Douglas Gregorb98b1992009-08-11 05:31:07 +00006365template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006366ExprResult
John McCall454feb92009-12-08 09:21:05 +00006367TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006368 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006369
Douglas Gregor43959a92009-08-20 07:17:43 +00006370 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006371 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006372 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006373 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006374
Douglas Gregor43959a92009-08-20 07:17:43 +00006375 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006376 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006377 bool ExprChanged = false;
6378 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6379 DEnd = E->designators_end();
6380 D != DEnd; ++D) {
6381 if (D->isFieldDesignator()) {
6382 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6383 D->getDotLoc(),
6384 D->getFieldLoc()));
6385 continue;
6386 }
Mike Stump1eb44332009-09-09 15:08:12 +00006387
Douglas Gregorb98b1992009-08-11 05:31:07 +00006388 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006389 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006390 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006391 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006392
6393 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006394 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006395
Douglas Gregorb98b1992009-08-11 05:31:07 +00006396 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6397 ArrayExprs.push_back(Index.release());
6398 continue;
6399 }
Mike Stump1eb44332009-09-09 15:08:12 +00006400
Douglas Gregorb98b1992009-08-11 05:31:07 +00006401 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006402 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006403 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6404 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006405 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006406
John McCall60d7b3a2010-08-24 06:29:42 +00006407 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006408 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006409 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006410
6411 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006412 End.get(),
6413 D->getLBracketLoc(),
6414 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006415
Douglas Gregorb98b1992009-08-11 05:31:07 +00006416 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6417 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006418
Douglas Gregorb98b1992009-08-11 05:31:07 +00006419 ArrayExprs.push_back(Start.release());
6420 ArrayExprs.push_back(End.release());
6421 }
Mike Stump1eb44332009-09-09 15:08:12 +00006422
Douglas Gregorb98b1992009-08-11 05:31:07 +00006423 if (!getDerived().AlwaysRebuild() &&
6424 Init.get() == E->getInit() &&
6425 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006426 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006427
Douglas Gregorb98b1992009-08-11 05:31:07 +00006428 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6429 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006430 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006431}
Mike Stump1eb44332009-09-09 15:08:12 +00006432
Douglas Gregorb98b1992009-08-11 05:31:07 +00006433template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006434ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006435TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006436 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006437 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006438
Douglas Gregor5557b252009-10-28 00:29:27 +00006439 // FIXME: Will we ever have proper type location here? Will we actually
6440 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006441 QualType T = getDerived().TransformType(E->getType());
6442 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006443 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006444
Douglas Gregorb98b1992009-08-11 05:31:07 +00006445 if (!getDerived().AlwaysRebuild() &&
6446 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006447 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006448
Douglas Gregorb98b1992009-08-11 05:31:07 +00006449 return getDerived().RebuildImplicitValueInitExpr(T);
6450}
Mike Stump1eb44332009-09-09 15:08:12 +00006451
Douglas Gregorb98b1992009-08-11 05:31:07 +00006452template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006453ExprResult
John McCall454feb92009-12-08 09:21:05 +00006454TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006455 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6456 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006457 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006458
John McCall60d7b3a2010-08-24 06:29:42 +00006459 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006460 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006461 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006462
Douglas Gregorb98b1992009-08-11 05:31:07 +00006463 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006464 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006465 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006466 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006467
John McCall9ae2f072010-08-23 23:25:46 +00006468 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006469 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006470}
6471
6472template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006473ExprResult
John McCall454feb92009-12-08 09:21:05 +00006474TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006475 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006476 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006477 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6478 &ArgumentChanged))
6479 return ExprError();
6480
Douglas Gregorb98b1992009-08-11 05:31:07 +00006481 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6482 move_arg(Inits),
6483 E->getRParenLoc());
6484}
Mike Stump1eb44332009-09-09 15:08:12 +00006485
Douglas Gregorb98b1992009-08-11 05:31:07 +00006486/// \brief Transform an address-of-label expression.
6487///
6488/// By default, the transformation of an address-of-label expression always
6489/// rebuilds the expression, so that the label identifier can be resolved to
6490/// the corresponding label statement by semantic analysis.
6491template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006492ExprResult
John McCall454feb92009-12-08 09:21:05 +00006493TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006494 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6495 E->getLabel());
6496 if (!LD)
6497 return ExprError();
6498
Douglas Gregorb98b1992009-08-11 05:31:07 +00006499 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006500 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006501}
Mike Stump1eb44332009-09-09 15:08:12 +00006502
6503template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006504ExprResult
John McCall454feb92009-12-08 09:21:05 +00006505TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006506 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006507 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6508 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006509 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006510
Douglas Gregorb98b1992009-08-11 05:31:07 +00006511 if (!getDerived().AlwaysRebuild() &&
6512 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00006513 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006514
6515 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006516 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006517 E->getRParenLoc());
6518}
Mike Stump1eb44332009-09-09 15:08:12 +00006519
Douglas Gregorb98b1992009-08-11 05:31:07 +00006520template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006521ExprResult
John McCall454feb92009-12-08 09:21:05 +00006522TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006523 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006524 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006525 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006526
John McCall60d7b3a2010-08-24 06:29:42 +00006527 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006528 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006529 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006530
John McCall60d7b3a2010-08-24 06:29:42 +00006531 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006532 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006533 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006534
Douglas Gregorb98b1992009-08-11 05:31:07 +00006535 if (!getDerived().AlwaysRebuild() &&
6536 Cond.get() == E->getCond() &&
6537 LHS.get() == E->getLHS() &&
6538 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006539 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006540
Douglas Gregorb98b1992009-08-11 05:31:07 +00006541 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006542 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006543 E->getRParenLoc());
6544}
Mike Stump1eb44332009-09-09 15:08:12 +00006545
Douglas Gregorb98b1992009-08-11 05:31:07 +00006546template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006547ExprResult
John McCall454feb92009-12-08 09:21:05 +00006548TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006549 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006550}
6551
6552template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006553ExprResult
John McCall454feb92009-12-08 09:21:05 +00006554TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006555 switch (E->getOperator()) {
6556 case OO_New:
6557 case OO_Delete:
6558 case OO_Array_New:
6559 case OO_Array_Delete:
6560 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00006561 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006562
Douglas Gregor668d6d92009-12-13 20:44:55 +00006563 case OO_Call: {
6564 // This is a call to an object's operator().
6565 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6566
6567 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006568 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006569 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006570 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006571
6572 // FIXME: Poor location information
6573 SourceLocation FakeLParenLoc
6574 = SemaRef.PP.getLocForEndOfToken(
6575 static_cast<Expr *>(Object.get())->getLocEnd());
6576
6577 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006578 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006579 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6580 Args))
6581 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006582
John McCall9ae2f072010-08-23 23:25:46 +00006583 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006584 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006585 E->getLocEnd());
6586 }
6587
6588#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6589 case OO_##Name:
6590#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6591#include "clang/Basic/OperatorKinds.def"
6592 case OO_Subscript:
6593 // Handled below.
6594 break;
6595
6596 case OO_Conditional:
6597 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00006598 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006599
6600 case OO_None:
6601 case NUM_OVERLOADED_OPERATORS:
6602 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00006603 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006604 }
6605
John McCall60d7b3a2010-08-24 06:29:42 +00006606 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006607 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006608 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006609
John McCall60d7b3a2010-08-24 06:29:42 +00006610 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006611 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006612 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006613
John McCall60d7b3a2010-08-24 06:29:42 +00006614 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006615 if (E->getNumArgs() == 2) {
6616 Second = getDerived().TransformExpr(E->getArg(1));
6617 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006618 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006619 }
Mike Stump1eb44332009-09-09 15:08:12 +00006620
Douglas Gregorb98b1992009-08-11 05:31:07 +00006621 if (!getDerived().AlwaysRebuild() &&
6622 Callee.get() == E->getCallee() &&
6623 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006624 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00006625 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006626
Douglas Gregorb98b1992009-08-11 05:31:07 +00006627 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6628 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006629 Callee.get(),
6630 First.get(),
6631 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006632}
Mike Stump1eb44332009-09-09 15:08:12 +00006633
Douglas Gregorb98b1992009-08-11 05:31:07 +00006634template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006635ExprResult
John McCall454feb92009-12-08 09:21:05 +00006636TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6637 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006638}
Mike Stump1eb44332009-09-09 15:08:12 +00006639
Douglas Gregorb98b1992009-08-11 05:31:07 +00006640template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006641ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006642TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6643 // Transform the callee.
6644 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6645 if (Callee.isInvalid())
6646 return ExprError();
6647
6648 // Transform exec config.
6649 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6650 if (EC.isInvalid())
6651 return ExprError();
6652
6653 // Transform arguments.
6654 bool ArgChanged = false;
6655 ASTOwningVector<Expr*> Args(SemaRef);
6656 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6657 &ArgChanged))
6658 return ExprError();
6659
6660 if (!getDerived().AlwaysRebuild() &&
6661 Callee.get() == E->getCallee() &&
6662 !ArgChanged)
6663 return SemaRef.Owned(E);
6664
6665 // FIXME: Wrong source location information for the '('.
6666 SourceLocation FakeLParenLoc
6667 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6668 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6669 move_arg(Args),
6670 E->getRParenLoc(), EC.get());
6671}
6672
6673template<typename Derived>
6674ExprResult
John McCall454feb92009-12-08 09:21:05 +00006675TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006676 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6677 if (!Type)
6678 return ExprError();
6679
John McCall60d7b3a2010-08-24 06:29:42 +00006680 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006681 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006682 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006683 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006684
Douglas Gregorb98b1992009-08-11 05:31:07 +00006685 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006686 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006687 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006688 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006689
Douglas Gregorb98b1992009-08-11 05:31:07 +00006690 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006691 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006692 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6693 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6694 SourceLocation FakeRParenLoc
6695 = SemaRef.PP.getLocForEndOfToken(
6696 E->getSubExpr()->getSourceRange().getEnd());
6697 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006698 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006699 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006700 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006701 FakeRAngleLoc,
6702 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006703 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006704 FakeRParenLoc);
6705}
Mike Stump1eb44332009-09-09 15:08:12 +00006706
Douglas Gregorb98b1992009-08-11 05:31:07 +00006707template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006708ExprResult
John McCall454feb92009-12-08 09:21:05 +00006709TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6710 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006711}
Mike Stump1eb44332009-09-09 15:08:12 +00006712
6713template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006714ExprResult
John McCall454feb92009-12-08 09:21:05 +00006715TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6716 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006717}
6718
Douglas Gregorb98b1992009-08-11 05:31:07 +00006719template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006720ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006721TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006722 CXXReinterpretCastExpr *E) {
6723 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006724}
Mike Stump1eb44332009-09-09 15:08:12 +00006725
Douglas Gregorb98b1992009-08-11 05:31:07 +00006726template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006727ExprResult
John McCall454feb92009-12-08 09:21:05 +00006728TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6729 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006730}
Mike Stump1eb44332009-09-09 15:08:12 +00006731
Douglas Gregorb98b1992009-08-11 05:31:07 +00006732template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006733ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006734TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006735 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006736 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6737 if (!Type)
6738 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006739
John McCall60d7b3a2010-08-24 06:29:42 +00006740 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006741 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006742 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006743 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006744
Douglas Gregorb98b1992009-08-11 05:31:07 +00006745 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006746 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006747 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006748 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006749
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006750 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006751 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006752 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006753 E->getRParenLoc());
6754}
Mike Stump1eb44332009-09-09 15:08:12 +00006755
Douglas Gregorb98b1992009-08-11 05:31:07 +00006756template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006757ExprResult
John McCall454feb92009-12-08 09:21:05 +00006758TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006759 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006760 TypeSourceInfo *TInfo
6761 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6762 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006763 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006764
Douglas Gregorb98b1992009-08-11 05:31:07 +00006765 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006766 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006767 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006768
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006769 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6770 E->getLocStart(),
6771 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006772 E->getLocEnd());
6773 }
Mike Stump1eb44332009-09-09 15:08:12 +00006774
Douglas Gregorb98b1992009-08-11 05:31:07 +00006775 // We don't know whether the expression is potentially evaluated until
6776 // after we perform semantic analysis, so the expression is potentially
6777 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00006778 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00006779 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006780
John McCall60d7b3a2010-08-24 06:29:42 +00006781 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006782 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006783 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006784
Douglas Gregorb98b1992009-08-11 05:31:07 +00006785 if (!getDerived().AlwaysRebuild() &&
6786 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006787 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006788
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006789 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6790 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006791 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006792 E->getLocEnd());
6793}
6794
6795template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006796ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00006797TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6798 if (E->isTypeOperand()) {
6799 TypeSourceInfo *TInfo
6800 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6801 if (!TInfo)
6802 return ExprError();
6803
6804 if (!getDerived().AlwaysRebuild() &&
6805 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006806 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006807
Douglas Gregor3c52a212011-03-06 17:40:41 +00006808 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00006809 E->getLocStart(),
6810 TInfo,
6811 E->getLocEnd());
6812 }
6813
6814 // We don't know whether the expression is potentially evaluated until
6815 // after we perform semantic analysis, so the expression is potentially
6816 // potentially evaluated.
6817 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6818
6819 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6820 if (SubExpr.isInvalid())
6821 return ExprError();
6822
6823 if (!getDerived().AlwaysRebuild() &&
6824 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006825 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006826
6827 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6828 E->getLocStart(),
6829 SubExpr.get(),
6830 E->getLocEnd());
6831}
6832
6833template<typename Derived>
6834ExprResult
John McCall454feb92009-12-08 09:21:05 +00006835TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006836 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006837}
Mike Stump1eb44332009-09-09 15:08:12 +00006838
Douglas Gregorb98b1992009-08-11 05:31:07 +00006839template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006840ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006841TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00006842 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006843 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006844}
Mike Stump1eb44332009-09-09 15:08:12 +00006845
Douglas Gregorb98b1992009-08-11 05:31:07 +00006846template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006847ExprResult
John McCall454feb92009-12-08 09:21:05 +00006848TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006849 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00006850 QualType T;
6851 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
6852 T = MD->getThisType(getSema().Context);
6853 else
6854 T = getSema().Context.getPointerType(
6855 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00006856
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006857 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006858 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006859
Douglas Gregor828a1972010-01-07 23:12:05 +00006860 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006861}
Mike Stump1eb44332009-09-09 15:08:12 +00006862
Douglas Gregorb98b1992009-08-11 05:31:07 +00006863template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006864ExprResult
John McCall454feb92009-12-08 09:21:05 +00006865TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006866 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006867 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006868 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006869
Douglas Gregorb98b1992009-08-11 05:31:07 +00006870 if (!getDerived().AlwaysRebuild() &&
6871 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006872 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006873
Douglas Gregorbca01b42011-07-06 22:04:06 +00006874 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
6875 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006876}
Mike Stump1eb44332009-09-09 15:08:12 +00006877
Douglas Gregorb98b1992009-08-11 05:31:07 +00006878template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006879ExprResult
John McCall454feb92009-12-08 09:21:05 +00006880TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006881 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006882 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6883 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006884 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00006885 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006886
Chandler Carruth53cb6f82010-02-08 06:42:49 +00006887 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006888 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00006889 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006890
Douglas Gregor036aed12009-12-23 23:03:06 +00006891 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006892}
Mike Stump1eb44332009-09-09 15:08:12 +00006893
Douglas Gregorb98b1992009-08-11 05:31:07 +00006894template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006895ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00006896TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6897 CXXScalarValueInitExpr *E) {
6898 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6899 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006900 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00006901
Douglas Gregorb98b1992009-08-11 05:31:07 +00006902 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006903 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006904 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006905
Douglas Gregorab6677e2010-09-08 00:15:04 +00006906 return getDerived().RebuildCXXScalarValueInitExpr(T,
6907 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00006908 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006909}
Mike Stump1eb44332009-09-09 15:08:12 +00006910
Douglas Gregorb98b1992009-08-11 05:31:07 +00006911template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006912ExprResult
John McCall454feb92009-12-08 09:21:05 +00006913TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006914 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006915 TypeSourceInfo *AllocTypeInfo
6916 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6917 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006918 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006919
Douglas Gregorb98b1992009-08-11 05:31:07 +00006920 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00006921 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006922 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006923 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006924
Douglas Gregorb98b1992009-08-11 05:31:07 +00006925 // Transform the placement arguments (if any).
6926 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006927 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006928 if (getDerived().TransformExprs(E->getPlacementArgs(),
6929 E->getNumPlacementArgs(), true,
6930 PlacementArgs, &ArgumentChanged))
6931 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006932
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00006933 // Transform the constructor arguments (if any).
6934 // As an annoying corner case, we may have introduced an implicit value-
6935 // initialization expression when allocating a new array, which we implicitly
6936 // drop. It will be re-created during type checking.
John McCallca0408f2010-08-23 06:44:23 +00006937 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00006938 if (!(E->isArray() && E->getNumConstructorArgs() == 1 &&
6939 isa<ImplicitValueInitExpr>(E->getConstructorArgs()[0])) &&
6940 TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006941 ConstructorArgs, &ArgumentChanged))
6942 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006943
Douglas Gregor1af74512010-02-26 00:38:10 +00006944 // Transform constructor, new operator, and delete operator.
6945 CXXConstructorDecl *Constructor = 0;
6946 if (E->getConstructor()) {
6947 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006948 getDerived().TransformDecl(E->getLocStart(),
6949 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006950 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006951 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006952 }
6953
6954 FunctionDecl *OperatorNew = 0;
6955 if (E->getOperatorNew()) {
6956 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006957 getDerived().TransformDecl(E->getLocStart(),
6958 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006959 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00006960 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006961 }
6962
6963 FunctionDecl *OperatorDelete = 0;
6964 if (E->getOperatorDelete()) {
6965 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006966 getDerived().TransformDecl(E->getLocStart(),
6967 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006968 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006969 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006970 }
Sean Huntc3021132010-05-05 15:23:54 +00006971
Douglas Gregorb98b1992009-08-11 05:31:07 +00006972 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006973 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006974 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006975 Constructor == E->getConstructor() &&
6976 OperatorNew == E->getOperatorNew() &&
6977 OperatorDelete == E->getOperatorDelete() &&
6978 !ArgumentChanged) {
6979 // Mark any declarations we need as referenced.
6980 // FIXME: instantiation-specific.
6981 if (Constructor)
6982 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6983 if (OperatorNew)
6984 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6985 if (OperatorDelete)
6986 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00006987
6988 if (E->isArray() && Constructor &&
6989 !E->getAllocatedType()->isDependentType()) {
6990 QualType ElementType
6991 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
6992 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
6993 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
6994 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
6995 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Destructor);
6996 }
6997 }
6998 }
6999
John McCall3fa5cae2010-10-26 07:05:15 +00007000 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007001 }
Mike Stump1eb44332009-09-09 15:08:12 +00007002
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007003 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007004 if (!ArraySize.get()) {
7005 // If no array size was specified, but the new expression was
7006 // instantiated with an array type (e.g., "new T" where T is
7007 // instantiated with "int[4]"), extract the outer bound from the
7008 // array type as our array size. We do this with constant and
7009 // dependently-sized array types.
7010 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7011 if (!ArrayT) {
7012 // Do nothing
7013 } else if (const ConstantArrayType *ConsArrayT
7014 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00007015 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007016 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7017 ConsArrayT->getSize(),
7018 SemaRef.Context.getSizeType(),
7019 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007020 AllocType = ConsArrayT->getElementType();
7021 } else if (const DependentSizedArrayType *DepArrayT
7022 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7023 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007024 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007025 AllocType = DepArrayT->getElementType();
7026 }
7027 }
7028 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007029
Douglas Gregorb98b1992009-08-11 05:31:07 +00007030 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7031 E->isGlobalNew(),
7032 /*FIXME:*/E->getLocStart(),
7033 move_arg(PlacementArgs),
7034 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007035 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007036 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007037 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007038 ArraySize.get(),
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007039 E->getConstructorLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007040 move_arg(ConstructorArgs),
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007041 E->getConstructorRParen());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007042}
Mike Stump1eb44332009-09-09 15:08:12 +00007043
Douglas Gregorb98b1992009-08-11 05:31:07 +00007044template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007045ExprResult
John McCall454feb92009-12-08 09:21:05 +00007046TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007047 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007048 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007049 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007050
Douglas Gregor1af74512010-02-26 00:38:10 +00007051 // Transform the delete operator, if known.
7052 FunctionDecl *OperatorDelete = 0;
7053 if (E->getOperatorDelete()) {
7054 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007055 getDerived().TransformDecl(E->getLocStart(),
7056 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007057 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007058 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007059 }
Sean Huntc3021132010-05-05 15:23:54 +00007060
Douglas Gregorb98b1992009-08-11 05:31:07 +00007061 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007062 Operand.get() == E->getArgument() &&
7063 OperatorDelete == E->getOperatorDelete()) {
7064 // Mark any declarations we need as referenced.
7065 // FIXME: instantiation-specific.
7066 if (OperatorDelete)
7067 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007068
7069 if (!E->getArgument()->isTypeDependent()) {
7070 QualType Destroyed = SemaRef.Context.getBaseElementType(
7071 E->getDestroyedType());
7072 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7073 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
7074 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
7075 SemaRef.LookupDestructor(Record));
7076 }
7077 }
7078
John McCall3fa5cae2010-10-26 07:05:15 +00007079 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007080 }
Mike Stump1eb44332009-09-09 15:08:12 +00007081
Douglas Gregorb98b1992009-08-11 05:31:07 +00007082 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7083 E->isGlobalDelete(),
7084 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007085 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007086}
Mike Stump1eb44332009-09-09 15:08:12 +00007087
Douglas Gregorb98b1992009-08-11 05:31:07 +00007088template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007089ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007090TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007091 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007092 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007093 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007094 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007095
John McCallb3d87482010-08-24 05:47:05 +00007096 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007097 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007098 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007099 E->getOperatorLoc(),
7100 E->isArrow()? tok::arrow : tok::period,
7101 ObjectTypePtr,
7102 MayBePseudoDestructor);
7103 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007104 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007105
John McCallb3d87482010-08-24 05:47:05 +00007106 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007107 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7108 if (QualifierLoc) {
7109 QualifierLoc
7110 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7111 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007112 return ExprError();
7113 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007114 CXXScopeSpec SS;
7115 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007116
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007117 PseudoDestructorTypeStorage Destroyed;
7118 if (E->getDestroyedTypeInfo()) {
7119 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007120 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007121 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007122 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007123 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007124 Destroyed = DestroyedTypeInfo;
7125 } else if (ObjectType->isDependentType()) {
7126 // We aren't likely to be able to resolve the identifier down to a type
7127 // now anyway, so just retain the identifier.
7128 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7129 E->getDestroyedTypeLoc());
7130 } else {
7131 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007132 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007133 *E->getDestroyedTypeIdentifier(),
7134 E->getDestroyedTypeLoc(),
7135 /*Scope=*/0,
7136 SS, ObjectTypePtr,
7137 false);
7138 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007139 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007140
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007141 Destroyed
7142 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7143 E->getDestroyedTypeLoc());
7144 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007145
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007146 TypeSourceInfo *ScopeTypeInfo = 0;
7147 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007148 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007149 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007150 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007151 }
Sean Huntc3021132010-05-05 15:23:54 +00007152
John McCall9ae2f072010-08-23 23:25:46 +00007153 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007154 E->getOperatorLoc(),
7155 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007156 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007157 ScopeTypeInfo,
7158 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007159 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007160 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007161}
Mike Stump1eb44332009-09-09 15:08:12 +00007162
Douglas Gregora71d8192009-09-04 17:36:40 +00007163template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007164ExprResult
John McCallba135432009-11-21 08:51:07 +00007165TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007166 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007167 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7168 Sema::LookupOrdinaryName);
7169
7170 // Transform all the decls.
7171 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7172 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007173 NamedDecl *InstD = static_cast<NamedDecl*>(
7174 getDerived().TransformDecl(Old->getNameLoc(),
7175 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007176 if (!InstD) {
7177 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7178 // This can happen because of dependent hiding.
7179 if (isa<UsingShadowDecl>(*I))
7180 continue;
7181 else
John McCallf312b1e2010-08-26 23:41:50 +00007182 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007183 }
John McCallf7a1a742009-11-24 19:00:30 +00007184
7185 // Expand using declarations.
7186 if (isa<UsingDecl>(InstD)) {
7187 UsingDecl *UD = cast<UsingDecl>(InstD);
7188 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7189 E = UD->shadow_end(); I != E; ++I)
7190 R.addDecl(*I);
7191 continue;
7192 }
7193
7194 R.addDecl(InstD);
7195 }
7196
7197 // Resolve a kind, but don't do any further analysis. If it's
7198 // ambiguous, the callee needs to deal with it.
7199 R.resolveKind();
7200
7201 // Rebuild the nested-name qualifier, if present.
7202 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007203 if (Old->getQualifierLoc()) {
7204 NestedNameSpecifierLoc QualifierLoc
7205 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7206 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007207 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007208
Douglas Gregor4c9be892011-02-28 20:01:57 +00007209 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007210 }
7211
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007212 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007213 CXXRecordDecl *NamingClass
7214 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7215 Old->getNameLoc(),
7216 Old->getNamingClass()));
7217 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007218 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007219
Douglas Gregor66c45152010-04-27 16:10:10 +00007220 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007221 }
7222
7223 // If we have no template arguments, it's a normal declaration name.
7224 if (!Old->hasExplicitTemplateArgs())
7225 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7226
7227 // If we have template arguments, rebuild them, then rebuild the
7228 // templateid expression.
7229 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007230 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7231 Old->getNumTemplateArgs(),
7232 TransArgs))
7233 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007234
7235 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7236 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007237}
Mike Stump1eb44332009-09-09 15:08:12 +00007238
Douglas Gregorb98b1992009-08-11 05:31:07 +00007239template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007240ExprResult
John McCall454feb92009-12-08 09:21:05 +00007241TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007242 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7243 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007244 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007245
Douglas Gregorb98b1992009-08-11 05:31:07 +00007246 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007247 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007248 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007249
Mike Stump1eb44332009-09-09 15:08:12 +00007250 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007251 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007252 T,
7253 E->getLocEnd());
7254}
Mike Stump1eb44332009-09-09 15:08:12 +00007255
Douglas Gregorb98b1992009-08-11 05:31:07 +00007256template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007257ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007258TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7259 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7260 if (!LhsT)
7261 return ExprError();
7262
7263 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7264 if (!RhsT)
7265 return ExprError();
7266
7267 if (!getDerived().AlwaysRebuild() &&
7268 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7269 return SemaRef.Owned(E);
7270
7271 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7272 E->getLocStart(),
7273 LhsT, RhsT,
7274 E->getLocEnd());
7275}
7276
7277template<typename Derived>
7278ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007279TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7280 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7281 if (!T)
7282 return ExprError();
7283
7284 if (!getDerived().AlwaysRebuild() &&
7285 T == E->getQueriedTypeSourceInfo())
7286 return SemaRef.Owned(E);
7287
7288 ExprResult SubExpr;
7289 {
7290 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7291 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7292 if (SubExpr.isInvalid())
7293 return ExprError();
7294
7295 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7296 return SemaRef.Owned(E);
7297 }
7298
7299 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7300 E->getLocStart(),
7301 T,
7302 SubExpr.get(),
7303 E->getLocEnd());
7304}
7305
7306template<typename Derived>
7307ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007308TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7309 ExprResult SubExpr;
7310 {
7311 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7312 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7313 if (SubExpr.isInvalid())
7314 return ExprError();
7315
7316 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7317 return SemaRef.Owned(E);
7318 }
7319
7320 return getDerived().RebuildExpressionTrait(
7321 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7322}
7323
7324template<typename Derived>
7325ExprResult
John McCall865d4472009-11-19 22:55:06 +00007326TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007327 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007328 NestedNameSpecifierLoc QualifierLoc
7329 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7330 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007331 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007332
John McCall43fed0d2010-11-12 08:19:04 +00007333 // TODO: If this is a conversion-function-id, verify that the
7334 // destination type name (if present) resolves the same way after
7335 // instantiation as it did in the local scope.
7336
Abramo Bagnara25777432010-08-11 22:01:17 +00007337 DeclarationNameInfo NameInfo
7338 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7339 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007340 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007341
John McCallf7a1a742009-11-24 19:00:30 +00007342 if (!E->hasExplicitTemplateArgs()) {
7343 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007344 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007345 // Note: it is sufficient to compare the Name component of NameInfo:
7346 // if name has not changed, DNLoc has not changed either.
7347 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007348 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007349
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007350 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007351 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007352 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007353 }
John McCalld5532b62009-11-23 01:53:49 +00007354
7355 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007356 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7357 E->getNumTemplateArgs(),
7358 TransArgs))
7359 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007360
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007361 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007362 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007363 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007364}
7365
7366template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007367ExprResult
John McCall454feb92009-12-08 09:21:05 +00007368TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007369 // CXXConstructExprs are always implicit, so when we have a
7370 // 1-argument construction we just transform that argument.
7371 if (E->getNumArgs() == 1 ||
7372 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7373 return getDerived().TransformExpr(E->getArg(0));
7374
Douglas Gregorb98b1992009-08-11 05:31:07 +00007375 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7376
7377 QualType T = getDerived().TransformType(E->getType());
7378 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007379 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007380
7381 CXXConstructorDecl *Constructor
7382 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007383 getDerived().TransformDecl(E->getLocStart(),
7384 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007385 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007386 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007387
Douglas Gregorb98b1992009-08-11 05:31:07 +00007388 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007389 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007390 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7391 &ArgumentChanged))
7392 return ExprError();
7393
Douglas Gregorb98b1992009-08-11 05:31:07 +00007394 if (!getDerived().AlwaysRebuild() &&
7395 T == E->getType() &&
7396 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007397 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007398 // Mark the constructor as referenced.
7399 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00007400 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007401 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007402 }
Mike Stump1eb44332009-09-09 15:08:12 +00007403
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007404 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7405 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007406 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007407 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007408 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007409 E->getConstructionKind(),
7410 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007411}
Mike Stump1eb44332009-09-09 15:08:12 +00007412
Douglas Gregorb98b1992009-08-11 05:31:07 +00007413/// \brief Transform a C++ temporary-binding expression.
7414///
Douglas Gregor51326552009-12-24 18:51:59 +00007415/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7416/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007417template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007418ExprResult
John McCall454feb92009-12-08 09:21:05 +00007419TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007420 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007421}
Mike Stump1eb44332009-09-09 15:08:12 +00007422
John McCall4765fa02010-12-06 08:20:24 +00007423/// \brief Transform a C++ expression that contains cleanups that should
7424/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007425///
John McCall4765fa02010-12-06 08:20:24 +00007426/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007427/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007428template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007429ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007430TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007431 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007432}
Mike Stump1eb44332009-09-09 15:08:12 +00007433
Douglas Gregorb98b1992009-08-11 05:31:07 +00007434template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007435ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007436TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007437 CXXTemporaryObjectExpr *E) {
7438 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7439 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007440 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007441
Douglas Gregorb98b1992009-08-11 05:31:07 +00007442 CXXConstructorDecl *Constructor
7443 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007444 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007445 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007446 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007447 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007448
Douglas Gregorb98b1992009-08-11 05:31:07 +00007449 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007450 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007451 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007452 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7453 &ArgumentChanged))
7454 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007455
Douglas Gregorb98b1992009-08-11 05:31:07 +00007456 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007457 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007458 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007459 !ArgumentChanged) {
7460 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00007461 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007462 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007463 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007464
7465 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7466 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007467 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007468 E->getLocEnd());
7469}
Mike Stump1eb44332009-09-09 15:08:12 +00007470
Douglas Gregorb98b1992009-08-11 05:31:07 +00007471template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007472ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007473TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007474 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007475 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7476 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007477 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007478
Douglas Gregorb98b1992009-08-11 05:31:07 +00007479 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007480 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007481 Args.reserve(E->arg_size());
7482 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7483 &ArgumentChanged))
7484 return ExprError();
7485
Douglas Gregorb98b1992009-08-11 05:31:07 +00007486 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007487 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007488 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007489 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007490
Douglas Gregorb98b1992009-08-11 05:31:07 +00007491 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00007492 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007493 E->getLParenLoc(),
7494 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007495 E->getRParenLoc());
7496}
Mike Stump1eb44332009-09-09 15:08:12 +00007497
Douglas Gregorb98b1992009-08-11 05:31:07 +00007498template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007499ExprResult
John McCall865d4472009-11-19 22:55:06 +00007500TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007501 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007502 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007503 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007504 Expr *OldBase;
7505 QualType BaseType;
7506 QualType ObjectType;
7507 if (!E->isImplicitAccess()) {
7508 OldBase = E->getBase();
7509 Base = getDerived().TransformExpr(OldBase);
7510 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007511 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007512
John McCallaa81e162009-12-01 22:10:20 +00007513 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00007514 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00007515 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007516 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007517 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00007518 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00007519 ObjectTy,
7520 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00007521 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007522 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007523
John McCallb3d87482010-08-24 05:47:05 +00007524 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00007525 BaseType = ((Expr*) Base.get())->getType();
7526 } else {
7527 OldBase = 0;
7528 BaseType = getDerived().TransformType(E->getBaseType());
7529 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7530 }
Mike Stump1eb44332009-09-09 15:08:12 +00007531
Douglas Gregor6cd21982009-10-20 05:58:46 +00007532 // Transform the first part of the nested-name-specifier that qualifies
7533 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00007534 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00007535 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007536 E->getFirstQualifierFoundInScope(),
7537 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00007538
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007539 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00007540 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007541 QualifierLoc
7542 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7543 ObjectType,
7544 FirstQualifierInScope);
7545 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007546 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00007547 }
Mike Stump1eb44332009-09-09 15:08:12 +00007548
John McCall43fed0d2010-11-12 08:19:04 +00007549 // TODO: If this is a conversion-function-id, verify that the
7550 // destination type name (if present) resolves the same way after
7551 // instantiation as it did in the local scope.
7552
Abramo Bagnara25777432010-08-11 22:01:17 +00007553 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00007554 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00007555 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007556 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007557
John McCallaa81e162009-12-01 22:10:20 +00007558 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007559 // This is a reference to a member without an explicitly-specified
7560 // template argument list. Optimize for this common case.
7561 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00007562 Base.get() == OldBase &&
7563 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007564 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007565 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007566 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00007567 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007568
John McCall9ae2f072010-08-23 23:25:46 +00007569 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007570 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007571 E->isArrow(),
7572 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007573 QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00007574 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007575 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007576 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007577 }
7578
John McCalld5532b62009-11-23 01:53:49 +00007579 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007580 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7581 E->getNumTemplateArgs(),
7582 TransArgs))
7583 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007584
John McCall9ae2f072010-08-23 23:25:46 +00007585 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007586 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007587 E->isArrow(),
7588 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007589 QualifierLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007590 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007591 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007592 &TransArgs);
7593}
7594
7595template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007596ExprResult
John McCall454feb92009-12-08 09:21:05 +00007597TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00007598 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007599 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007600 QualType BaseType;
7601 if (!Old->isImplicitAccess()) {
7602 Base = getDerived().TransformExpr(Old->getBase());
7603 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007604 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007605 BaseType = ((Expr*) Base.get())->getType();
7606 } else {
7607 BaseType = getDerived().TransformType(Old->getBaseType());
7608 }
John McCall129e2df2009-11-30 22:42:35 +00007609
Douglas Gregor4c9be892011-02-28 20:01:57 +00007610 NestedNameSpecifierLoc QualifierLoc;
7611 if (Old->getQualifierLoc()) {
7612 QualifierLoc
7613 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7614 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007615 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007616 }
7617
Abramo Bagnara25777432010-08-11 22:01:17 +00007618 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00007619 Sema::LookupOrdinaryName);
7620
7621 // Transform all the decls.
7622 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7623 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007624 NamedDecl *InstD = static_cast<NamedDecl*>(
7625 getDerived().TransformDecl(Old->getMemberLoc(),
7626 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007627 if (!InstD) {
7628 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7629 // This can happen because of dependent hiding.
7630 if (isa<UsingShadowDecl>(*I))
7631 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007632 else {
7633 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007634 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007635 }
John McCall9f54ad42009-12-10 09:41:52 +00007636 }
John McCall129e2df2009-11-30 22:42:35 +00007637
7638 // Expand using declarations.
7639 if (isa<UsingDecl>(InstD)) {
7640 UsingDecl *UD = cast<UsingDecl>(InstD);
7641 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7642 E = UD->shadow_end(); I != E; ++I)
7643 R.addDecl(*I);
7644 continue;
7645 }
7646
7647 R.addDecl(InstD);
7648 }
7649
7650 R.resolveKind();
7651
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007652 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00007653 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00007654 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007655 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00007656 Old->getMemberLoc(),
7657 Old->getNamingClass()));
7658 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007659 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007660
Douglas Gregor66c45152010-04-27 16:10:10 +00007661 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007662 }
Sean Huntc3021132010-05-05 15:23:54 +00007663
John McCall129e2df2009-11-30 22:42:35 +00007664 TemplateArgumentListInfo TransArgs;
7665 if (Old->hasExplicitTemplateArgs()) {
7666 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7667 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007668 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7669 Old->getNumTemplateArgs(),
7670 TransArgs))
7671 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007672 }
John McCallc2233c52010-01-15 08:34:02 +00007673
7674 // FIXME: to do this check properly, we will need to preserve the
7675 // first-qualifier-in-scope here, just in case we had a dependent
7676 // base (and therefore couldn't do the check) and a
7677 // nested-name-qualifier (and therefore could do the lookup).
7678 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00007679
John McCall9ae2f072010-08-23 23:25:46 +00007680 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007681 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00007682 Old->getOperatorLoc(),
7683 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00007684 QualifierLoc,
John McCallc2233c52010-01-15 08:34:02 +00007685 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00007686 R,
7687 (Old->hasExplicitTemplateArgs()
7688 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007689}
7690
7691template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007692ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00007693TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00007694 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00007695 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7696 if (SubExpr.isInvalid())
7697 return ExprError();
7698
7699 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007700 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00007701
7702 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7703}
7704
7705template<typename Derived>
7706ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00007707TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00007708 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7709 if (Pattern.isInvalid())
7710 return ExprError();
7711
7712 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7713 return SemaRef.Owned(E);
7714
Douglas Gregor67fd1252011-01-14 21:20:45 +00007715 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7716 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00007717}
Douglas Gregoree8aff02011-01-04 17:33:58 +00007718
7719template<typename Derived>
7720ExprResult
7721TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7722 // If E is not value-dependent, then nothing will change when we transform it.
7723 // Note: This is an instantiation-centric view.
7724 if (!E->isValueDependent())
7725 return SemaRef.Owned(E);
7726
7727 // Note: None of the implementations of TryExpandParameterPacks can ever
7728 // produce a diagnostic when given only a single unexpanded parameter pack,
7729 // so
7730 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7731 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00007732 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00007733 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00007734 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00007735 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00007736 ShouldExpand, RetainExpansion,
7737 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00007738 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00007739
Douglas Gregor089e8932011-10-10 18:59:29 +00007740 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00007741 return SemaRef.Owned(E);
Douglas Gregor089e8932011-10-10 18:59:29 +00007742
7743 NamedDecl *Pack = E->getPack();
7744 if (!ShouldExpand) {
7745 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
7746 Pack));
7747 if (!Pack)
7748 return ExprError();
7749 }
7750
Douglas Gregoree8aff02011-01-04 17:33:58 +00007751
7752 // We now know the length of the parameter pack, so build a new expression
7753 // that stores that length.
Douglas Gregor089e8932011-10-10 18:59:29 +00007754 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregoree8aff02011-01-04 17:33:58 +00007755 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00007756 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00007757}
7758
Douglas Gregorbe230c32011-01-03 17:17:50 +00007759template<typename Derived>
7760ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00007761TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7762 SubstNonTypeTemplateParmPackExpr *E) {
7763 // Default behavior is to do nothing with this transformation.
7764 return SemaRef.Owned(E);
7765}
7766
7767template<typename Derived>
7768ExprResult
John McCall91a57552011-07-15 05:09:51 +00007769TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
7770 SubstNonTypeTemplateParmExpr *E) {
7771 // Default behavior is to do nothing with this transformation.
7772 return SemaRef.Owned(E);
7773}
7774
7775template<typename Derived>
7776ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00007777TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
7778 MaterializeTemporaryExpr *E) {
7779 return getDerived().TransformExpr(E->GetTemporaryExpr());
7780}
7781
7782template<typename Derived>
7783ExprResult
John McCall454feb92009-12-08 09:21:05 +00007784TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007785 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007786}
7787
Mike Stump1eb44332009-09-09 15:08:12 +00007788template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007789ExprResult
John McCall454feb92009-12-08 09:21:05 +00007790TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00007791 TypeSourceInfo *EncodedTypeInfo
7792 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7793 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007794 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007795
Douglas Gregorb98b1992009-08-11 05:31:07 +00007796 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00007797 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007798 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007799
7800 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00007801 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007802 E->getRParenLoc());
7803}
Mike Stump1eb44332009-09-09 15:08:12 +00007804
Douglas Gregorb98b1992009-08-11 05:31:07 +00007805template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00007806ExprResult TreeTransform<Derived>::
7807TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7808 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7809 if (result.isInvalid()) return ExprError();
7810 Expr *subExpr = result.take();
7811
7812 if (!getDerived().AlwaysRebuild() &&
7813 subExpr == E->getSubExpr())
7814 return SemaRef.Owned(E);
7815
7816 return SemaRef.Owned(new(SemaRef.Context)
7817 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7818}
7819
7820template<typename Derived>
7821ExprResult TreeTransform<Derived>::
7822TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7823 TypeSourceInfo *TSInfo
7824 = getDerived().TransformType(E->getTypeInfoAsWritten());
7825 if (!TSInfo)
7826 return ExprError();
7827
7828 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7829 if (Result.isInvalid())
7830 return ExprError();
7831
7832 if (!getDerived().AlwaysRebuild() &&
7833 TSInfo == E->getTypeInfoAsWritten() &&
7834 Result.get() == E->getSubExpr())
7835 return SemaRef.Owned(E);
7836
7837 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
7838 E->getBridgeKeywordLoc(), TSInfo,
7839 Result.get());
7840}
7841
7842template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007843ExprResult
John McCall454feb92009-12-08 09:21:05 +00007844TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00007845 // Transform arguments.
7846 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007847 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007848 Args.reserve(E->getNumArgs());
7849 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7850 &ArgChanged))
7851 return ExprError();
7852
Douglas Gregor92e986e2010-04-22 16:44:27 +00007853 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7854 // Class message: transform the receiver type.
7855 TypeSourceInfo *ReceiverTypeInfo
7856 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7857 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007858 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007859
Douglas Gregor92e986e2010-04-22 16:44:27 +00007860 // If nothing changed, just retain the existing message send.
7861 if (!getDerived().AlwaysRebuild() &&
7862 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007863 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00007864
7865 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00007866 SmallVector<SourceLocation, 16> SelLocs;
7867 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00007868 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7869 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00007870 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00007871 E->getMethodDecl(),
7872 E->getLeftLoc(),
7873 move_arg(Args),
7874 E->getRightLoc());
7875 }
7876
7877 // Instance message: transform the receiver
7878 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7879 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00007880 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00007881 = getDerived().TransformExpr(E->getInstanceReceiver());
7882 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007883 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00007884
7885 // If nothing changed, just retain the existing message send.
7886 if (!getDerived().AlwaysRebuild() &&
7887 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007888 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007889
Douglas Gregor92e986e2010-04-22 16:44:27 +00007890 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00007891 SmallVector<SourceLocation, 16> SelLocs;
7892 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00007893 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007894 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00007895 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00007896 E->getMethodDecl(),
7897 E->getLeftLoc(),
7898 move_arg(Args),
7899 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007900}
7901
Mike Stump1eb44332009-09-09 15:08:12 +00007902template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007903ExprResult
John McCall454feb92009-12-08 09:21:05 +00007904TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007905 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007906}
7907
Mike Stump1eb44332009-09-09 15:08:12 +00007908template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007909ExprResult
John McCall454feb92009-12-08 09:21:05 +00007910TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007911 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007912}
7913
Mike Stump1eb44332009-09-09 15:08:12 +00007914template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007915ExprResult
John McCall454feb92009-12-08 09:21:05 +00007916TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007917 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007918 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007919 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007920 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007921
7922 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007923
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007924 // If nothing changed, just retain the existing expression.
7925 if (!getDerived().AlwaysRebuild() &&
7926 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007927 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007928
John McCall9ae2f072010-08-23 23:25:46 +00007929 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007930 E->getLocation(),
7931 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007932}
7933
Mike Stump1eb44332009-09-09 15:08:12 +00007934template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007935ExprResult
John McCall454feb92009-12-08 09:21:05 +00007936TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00007937 // 'super' and types never change. Property never changes. Just
7938 // retain the existing expression.
7939 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00007940 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00007941
Douglas Gregore3303542010-04-26 20:47:02 +00007942 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007943 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00007944 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007945 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007946
Douglas Gregore3303542010-04-26 20:47:02 +00007947 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007948
Douglas Gregore3303542010-04-26 20:47:02 +00007949 // If nothing changed, just retain the existing expression.
7950 if (!getDerived().AlwaysRebuild() &&
7951 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007952 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007953
John McCall12f78a62010-12-02 01:19:52 +00007954 if (E->isExplicitProperty())
7955 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7956 E->getExplicitProperty(),
7957 E->getLocation());
7958
7959 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7960 E->getType(),
7961 E->getImplicitPropertyGetter(),
7962 E->getImplicitPropertySetter(),
7963 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007964}
7965
Mike Stump1eb44332009-09-09 15:08:12 +00007966template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007967ExprResult
John McCall454feb92009-12-08 09:21:05 +00007968TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007969 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007970 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007971 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007972 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007973
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007974 // If nothing changed, just retain the existing expression.
7975 if (!getDerived().AlwaysRebuild() &&
7976 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007977 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007978
John McCall9ae2f072010-08-23 23:25:46 +00007979 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007980 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007981}
7982
Mike Stump1eb44332009-09-09 15:08:12 +00007983template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007984ExprResult
John McCall454feb92009-12-08 09:21:05 +00007985TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007986 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007987 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007988 SubExprs.reserve(E->getNumSubExprs());
7989 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7990 SubExprs, &ArgumentChanged))
7991 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007992
Douglas Gregorb98b1992009-08-11 05:31:07 +00007993 if (!getDerived().AlwaysRebuild() &&
7994 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007995 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007996
Douglas Gregorb98b1992009-08-11 05:31:07 +00007997 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7998 move_arg(SubExprs),
7999 E->getRParenLoc());
8000}
8001
Mike Stump1eb44332009-09-09 15:08:12 +00008002template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008003ExprResult
John McCall454feb92009-12-08 09:21:05 +00008004TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008005 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008006
John McCallc6ac9c32011-02-04 18:33:18 +00008007 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8008 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8009
8010 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanianff365592011-05-05 17:18:12 +00008011 // We built a new blockScopeInfo in call to ActOnBlockStart
8012 // in above, CapturesCXXThis need be set here from the block
8013 // expression.
8014 blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
8015
Chris Lattner686775d2011-07-20 06:58:45 +00008016 SmallVector<ParmVarDecl*, 4> params;
8017 SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008018
8019 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008020 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8021 oldBlock->param_begin(),
8022 oldBlock->param_size(),
8023 0, paramTypes, &params))
Douglas Gregora779d9c2011-01-19 21:32:01 +00008024 return true;
John McCallc6ac9c32011-02-04 18:33:18 +00008025
8026 const FunctionType *exprFunctionType = E->getFunctionType();
8027 QualType exprResultType = exprFunctionType->getResultType();
8028 if (!exprResultType.isNull()) {
8029 if (!exprResultType->isDependentType())
8030 blockScope->ReturnType = exprResultType;
8031 else if (exprResultType != getSema().Context.DependentTy)
8032 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008033 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00008034
8035 // If the return type has not been determined yet, leave it as a dependent
8036 // type; it'll get set when we process the body.
John McCallc6ac9c32011-02-04 18:33:18 +00008037 if (blockScope->ReturnType.isNull())
8038 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregora779d9c2011-01-19 21:32:01 +00008039
8040 // Don't allow returning a objc interface by value.
John McCallc6ac9c32011-02-04 18:33:18 +00008041 if (blockScope->ReturnType->isObjCObjectType()) {
8042 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00008043 diag::err_object_cannot_be_passed_returned_by_value)
John McCallc6ac9c32011-02-04 18:33:18 +00008044 << 0 << blockScope->ReturnType;
Douglas Gregora779d9c2011-01-19 21:32:01 +00008045 return ExprError();
8046 }
John McCall711c52b2011-01-05 12:14:39 +00008047
John McCallc6ac9c32011-02-04 18:33:18 +00008048 QualType functionType = getDerived().RebuildFunctionProtoType(
8049 blockScope->ReturnType,
8050 paramTypes.data(),
8051 paramTypes.size(),
8052 oldBlock->isVariadic(),
Douglas Gregorc938c162011-01-26 05:01:58 +00008053 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008054 exprFunctionType->getExtInfo());
8055 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008056
8057 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008058 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008059 blockScope->TheDecl->setParams(params);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008060
8061 // If the return type wasn't explicitly set, it will have been marked as a
8062 // dependent type (DependentTy); clear out the return type setting so
8063 // we will deduce the return type when type-checking the block's body.
John McCallc6ac9c32011-02-04 18:33:18 +00008064 if (blockScope->ReturnType == getSema().Context.DependentTy)
8065 blockScope->ReturnType = QualType();
Douglas Gregora779d9c2011-01-19 21:32:01 +00008066
John McCall711c52b2011-01-05 12:14:39 +00008067 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008068 StmtResult body = getDerived().TransformStmt(E->getBody());
8069 if (body.isInvalid())
John McCall711c52b2011-01-05 12:14:39 +00008070 return ExprError();
8071
John McCallc6ac9c32011-02-04 18:33:18 +00008072#ifndef NDEBUG
8073 // In builds with assertions, make sure that we captured everything we
8074 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008075 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8076 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8077 e = oldBlock->capture_end(); i != e; ++i) {
8078 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008079
Douglas Gregorfc921372011-05-20 15:32:55 +00008080 // Ignore parameter packs.
8081 if (isa<ParmVarDecl>(oldCapture) &&
8082 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8083 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008084
Douglas Gregorfc921372011-05-20 15:32:55 +00008085 VarDecl *newCapture =
8086 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8087 oldCapture));
8088 assert(blockScope->CaptureMap.count(newCapture));
8089 }
John McCallc6ac9c32011-02-04 18:33:18 +00008090 }
8091#endif
8092
8093 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8094 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008095}
8096
Mike Stump1eb44332009-09-09 15:08:12 +00008097template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008098ExprResult
John McCall454feb92009-12-08 09:21:05 +00008099TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008100 ValueDecl *ND
8101 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8102 E->getDecl()));
8103 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00008104 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00008105
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008106 if (!getDerived().AlwaysRebuild() &&
8107 ND == E->getDecl()) {
8108 // Mark it referenced in the new context regardless.
8109 // FIXME: this is a bit instantiation-specific.
8110 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
8111
John McCall3fa5cae2010-10-26 07:05:15 +00008112 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008113 }
8114
Abramo Bagnara25777432010-08-11 22:01:17 +00008115 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregor40d96a62011-02-28 21:54:11 +00008116 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnara25777432010-08-11 22:01:17 +00008117 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008118}
Mike Stump1eb44332009-09-09 15:08:12 +00008119
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008120template<typename Derived>
8121ExprResult
8122TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008123 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008124}
Eli Friedman276b0612011-10-11 02:20:01 +00008125
8126template<typename Derived>
8127ExprResult
8128TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008129 QualType RetTy = getDerived().TransformType(E->getType());
8130 bool ArgumentChanged = false;
8131 ASTOwningVector<Expr*> SubExprs(SemaRef);
8132 SubExprs.reserve(E->getNumSubExprs());
8133 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8134 SubExprs, &ArgumentChanged))
8135 return ExprError();
8136
8137 if (!getDerived().AlwaysRebuild() &&
8138 !ArgumentChanged)
8139 return SemaRef.Owned(E);
8140
8141 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8142 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008143}
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008144
Douglas Gregorb98b1992009-08-11 05:31:07 +00008145//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008146// Type reconstruction
8147//===----------------------------------------------------------------------===//
8148
Mike Stump1eb44332009-09-09 15:08:12 +00008149template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008150QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8151 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008152 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008153 getDerived().getBaseEntity());
8154}
8155
Mike Stump1eb44332009-09-09 15:08:12 +00008156template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008157QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8158 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008159 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008160 getDerived().getBaseEntity());
8161}
8162
Mike Stump1eb44332009-09-09 15:08:12 +00008163template<typename Derived>
8164QualType
John McCall85737a72009-10-30 00:06:24 +00008165TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8166 bool WrittenAsLValue,
8167 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008168 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008169 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008170}
8171
8172template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008173QualType
John McCall85737a72009-10-30 00:06:24 +00008174TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8175 QualType ClassType,
8176 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008177 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008178 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008179}
8180
8181template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008182QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008183TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8184 ArrayType::ArraySizeModifier SizeMod,
8185 const llvm::APInt *Size,
8186 Expr *SizeExpr,
8187 unsigned IndexTypeQuals,
8188 SourceRange BracketsRange) {
8189 if (SizeExpr || !Size)
8190 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8191 IndexTypeQuals, BracketsRange,
8192 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008193
8194 QualType Types[] = {
8195 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8196 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8197 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008198 };
8199 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8200 QualType SizeType;
8201 for (unsigned I = 0; I != NumTypes; ++I)
8202 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8203 SizeType = Types[I];
8204 break;
8205 }
Mike Stump1eb44332009-09-09 15:08:12 +00008206
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008207 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
8208 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00008209 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008210 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008211 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008212}
Mike Stump1eb44332009-09-09 15:08:12 +00008213
Douglas Gregor577f75a2009-08-04 16:50:30 +00008214template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008215QualType
8216TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008217 ArrayType::ArraySizeModifier SizeMod,
8218 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008219 unsigned IndexTypeQuals,
8220 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008221 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008222 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008223}
8224
8225template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008226QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008227TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008228 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008229 unsigned IndexTypeQuals,
8230 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008231 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008232 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008233}
Mike Stump1eb44332009-09-09 15:08:12 +00008234
Douglas Gregor577f75a2009-08-04 16:50:30 +00008235template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008236QualType
8237TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008238 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008239 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008240 unsigned IndexTypeQuals,
8241 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008242 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008243 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008244 IndexTypeQuals, BracketsRange);
8245}
8246
8247template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008248QualType
8249TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008250 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008251 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008252 unsigned IndexTypeQuals,
8253 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008254 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008255 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008256 IndexTypeQuals, BracketsRange);
8257}
8258
8259template<typename Derived>
8260QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008261 unsigned NumElements,
8262 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008263 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008264 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008265}
Mike Stump1eb44332009-09-09 15:08:12 +00008266
Douglas Gregor577f75a2009-08-04 16:50:30 +00008267template<typename Derived>
8268QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8269 unsigned NumElements,
8270 SourceLocation AttributeLoc) {
8271 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8272 NumElements, true);
8273 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008274 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8275 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008276 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008277}
Mike Stump1eb44332009-09-09 15:08:12 +00008278
Douglas Gregor577f75a2009-08-04 16:50:30 +00008279template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008280QualType
8281TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008282 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008283 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008284 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008285}
Mike Stump1eb44332009-09-09 15:08:12 +00008286
Douglas Gregor577f75a2009-08-04 16:50:30 +00008287template<typename Derived>
8288QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00008289 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008290 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00008291 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00008292 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00008293 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00008294 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00008295 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregorc938c162011-01-26 05:01:58 +00008296 Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008297 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00008298 getDerived().getBaseEntity(),
8299 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008300}
Mike Stump1eb44332009-09-09 15:08:12 +00008301
Douglas Gregor577f75a2009-08-04 16:50:30 +00008302template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00008303QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8304 return SemaRef.Context.getFunctionNoProtoType(T);
8305}
8306
8307template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00008308QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8309 assert(D && "no decl found");
8310 if (D->isInvalidDecl()) return QualType();
8311
Douglas Gregor92e986e2010-04-22 16:44:27 +00008312 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00008313 TypeDecl *Ty;
8314 if (isa<UsingDecl>(D)) {
8315 UsingDecl *Using = cast<UsingDecl>(D);
8316 assert(Using->isTypeName() &&
8317 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8318
8319 // A valid resolved using typename decl points to exactly one type decl.
8320 assert(++Using->shadow_begin() == Using->shadow_end());
8321 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00008322
John McCalled976492009-12-04 22:46:56 +00008323 } else {
8324 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8325 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8326 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8327 }
8328
8329 return SemaRef.Context.getTypeDeclType(Ty);
8330}
8331
8332template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008333QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8334 SourceLocation Loc) {
8335 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008336}
8337
8338template<typename Derived>
8339QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8340 return SemaRef.Context.getTypeOfType(Underlying);
8341}
8342
8343template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008344QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8345 SourceLocation Loc) {
8346 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008347}
8348
8349template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00008350QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8351 UnaryTransformType::UTTKind UKind,
8352 SourceLocation Loc) {
8353 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8354}
8355
8356template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00008357QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00008358 TemplateName Template,
8359 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00008360 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00008361 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008362}
Mike Stump1eb44332009-09-09 15:08:12 +00008363
Douglas Gregordcee1a12009-08-06 05:28:30 +00008364template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00008365QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
8366 SourceLocation KWLoc) {
8367 return SemaRef.BuildAtomicType(ValueType, KWLoc);
8368}
8369
8370template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008371TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008372TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00008373 bool TemplateKW,
8374 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008375 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00008376 Template);
8377}
8378
8379template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008380TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008381TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8382 const IdentifierInfo &Name,
8383 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00008384 QualType ObjectType,
8385 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008386 UnqualifiedId TemplateName;
8387 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008388 Sema::TemplateTy Template;
8389 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008390 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008391 SS,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008392 TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00008393 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008394 /*EnteringContext=*/false,
8395 Template);
John McCall43fed0d2010-11-12 08:19:04 +00008396 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00008397}
Mike Stump1eb44332009-09-09 15:08:12 +00008398
Douglas Gregorb98b1992009-08-11 05:31:07 +00008399template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008400TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008401TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008402 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008403 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008404 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008405 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008406 // FIXME: Bogus location information.
8407 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8408 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008409 Sema::TemplateTy Template;
8410 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008411 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008412 SS,
8413 Name,
John McCallb3d87482010-08-24 05:47:05 +00008414 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008415 /*EnteringContext=*/false,
8416 Template);
8417 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008418}
Sean Huntc3021132010-05-05 15:23:54 +00008419
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008420template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008421ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008422TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8423 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00008424 Expr *OrigCallee,
8425 Expr *First,
8426 Expr *Second) {
8427 Expr *Callee = OrigCallee->IgnoreParenCasts();
8428 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00008429
Douglas Gregorb98b1992009-08-11 05:31:07 +00008430 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00008431 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00008432 if (!First->getType()->isOverloadableType() &&
8433 !Second->getType()->isOverloadableType())
8434 return getSema().CreateBuiltinArraySubscriptExpr(First,
8435 Callee->getLocStart(),
8436 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00008437 } else if (Op == OO_Arrow) {
8438 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00008439 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8440 } else if (Second == 0 || isPostIncDec) {
8441 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008442 // The argument is not of overloadable type, so try to create a
8443 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00008444 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008445 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00008446
John McCall9ae2f072010-08-23 23:25:46 +00008447 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008448 }
8449 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008450 if (!First->getType()->isOverloadableType() &&
8451 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008452 // Neither of the arguments is an overloadable type, so try to
8453 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00008454 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008455 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00008456 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008457 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008458 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008459
Douglas Gregorb98b1992009-08-11 05:31:07 +00008460 return move(Result);
8461 }
8462 }
Mike Stump1eb44332009-09-09 15:08:12 +00008463
8464 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00008465 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00008466 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00008467
John McCall9ae2f072010-08-23 23:25:46 +00008468 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00008469 assert(ULE->requiresADL());
8470
8471 // FIXME: Do we have to check
8472 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00008473 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00008474 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008475 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00008476 }
Mike Stump1eb44332009-09-09 15:08:12 +00008477
Douglas Gregorb98b1992009-08-11 05:31:07 +00008478 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00008479 Expr *Args[2] = { First, Second };
8480 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00008481
Douglas Gregorb98b1992009-08-11 05:31:07 +00008482 // Create the overloaded operator invocation for unary operators.
8483 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00008484 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008485 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00008486 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008487 }
Mike Stump1eb44332009-09-09 15:08:12 +00008488
Douglas Gregor5b8968c2011-07-15 16:25:15 +00008489 if (Op == OO_Subscript) {
8490 SourceLocation LBrace;
8491 SourceLocation RBrace;
8492
8493 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
8494 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
8495 LBrace = SourceLocation::getFromRawEncoding(
8496 NameLoc.CXXOperatorName.BeginOpNameLoc);
8497 RBrace = SourceLocation::getFromRawEncoding(
8498 NameLoc.CXXOperatorName.EndOpNameLoc);
8499 } else {
8500 LBrace = Callee->getLocStart();
8501 RBrace = OpLoc;
8502 }
8503
8504 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
8505 First, Second);
8506 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00008507
Douglas Gregorb98b1992009-08-11 05:31:07 +00008508 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00008509 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008510 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00008511 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8512 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008513 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008514
Mike Stump1eb44332009-09-09 15:08:12 +00008515 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008516}
Mike Stump1eb44332009-09-09 15:08:12 +00008517
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008518template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008519ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00008520TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008521 SourceLocation OperatorLoc,
8522 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00008523 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008524 TypeSourceInfo *ScopeType,
8525 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008526 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008527 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00008528 QualType BaseType = Base->getType();
8529 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008530 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00008531 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00008532 !BaseType->getAs<PointerType>()->getPointeeType()
8533 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008534 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00008535 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008536 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008537 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008538 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008539 /*FIXME?*/true);
8540 }
Abramo Bagnara25777432010-08-11 22:01:17 +00008541
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008542 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00008543 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8544 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8545 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8546 NameInfo.setNamedTypeInfo(DestroyedType);
8547
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008548 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00008549
John McCall9ae2f072010-08-23 23:25:46 +00008550 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008551 OperatorLoc, isArrow,
8552 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00008553 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008554 /*TemplateArgs*/ 0);
8555}
8556
Douglas Gregor577f75a2009-08-04 16:50:30 +00008557} // end namespace clang
8558
8559#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H