blob: f5fc3b7cb8426ce5dbce7ff168e23a27ee8cb572 [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 Gregord1bb4ae2012-01-25 16:15:54 +0000533 llvm::Optional<unsigned> NumExpansions,
534 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000535
John McCall43fed0d2010-11-12 08:19:04 +0000536 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000537
John McCall60d7b3a2010-08-24 06:29:42 +0000538 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
539 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000540
Douglas Gregor43959a92009-08-20 07:17:43 +0000541#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000542 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000543#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000544 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000545#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000546#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000547
Douglas Gregor577f75a2009-08-04 16:50:30 +0000548 /// \brief Build a new pointer type given its pointee type.
549 ///
550 /// By default, performs semantic analysis when building the pointer type.
551 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000552 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000553
554 /// \brief Build a new block pointer type given its pointee type.
555 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000556 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000557 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000558 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000559
John McCall85737a72009-10-30 00:06:24 +0000560 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000561 ///
John McCall85737a72009-10-30 00:06:24 +0000562 /// By default, performs semantic analysis when building the
563 /// reference type. Subclasses may override this routine to provide
564 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000565 ///
John McCall85737a72009-10-30 00:06:24 +0000566 /// \param LValue whether the type was written with an lvalue sigil
567 /// or an rvalue sigil.
568 QualType RebuildReferenceType(QualType ReferentType,
569 bool LValue,
570 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000571
Douglas Gregor577f75a2009-08-04 16:50:30 +0000572 /// \brief Build a new member pointer type given the pointee type and the
573 /// class type it refers into.
574 ///
575 /// By default, performs semantic analysis when building the member pointer
576 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000577 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
578 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000579
Douglas Gregor577f75a2009-08-04 16:50:30 +0000580 /// \brief Build a new array type given the element type, size
581 /// modifier, size of the array (if known), size expression, and index type
582 /// qualifiers.
583 ///
584 /// By default, performs semantic analysis when building the array type.
585 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000586 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000587 QualType RebuildArrayType(QualType ElementType,
588 ArrayType::ArraySizeModifier SizeMod,
589 const llvm::APInt *Size,
590 Expr *SizeExpr,
591 unsigned IndexTypeQuals,
592 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000593
Douglas Gregor577f75a2009-08-04 16:50:30 +0000594 /// \brief Build a new constant array type given the element type, size
595 /// modifier, (known) size of the array, and index type qualifiers.
596 ///
597 /// By default, performs semantic analysis when building the array type.
598 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000599 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000600 ArrayType::ArraySizeModifier SizeMod,
601 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000602 unsigned IndexTypeQuals,
603 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000604
Douglas Gregor577f75a2009-08-04 16:50:30 +0000605 /// \brief Build a new incomplete array type given the element type, size
606 /// modifier, and index type qualifiers.
607 ///
608 /// By default, performs semantic analysis when building the array type.
609 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000610 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000611 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000612 unsigned IndexTypeQuals,
613 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000614
Mike Stump1eb44332009-09-09 15:08:12 +0000615 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000616 /// size modifier, size expression, and index type qualifiers.
617 ///
618 /// By default, performs semantic analysis when building the array type.
619 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000620 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000621 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000622 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000623 unsigned IndexTypeQuals,
624 SourceRange BracketsRange);
625
Mike Stump1eb44332009-09-09 15:08:12 +0000626 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000627 /// size modifier, size expression, and index type qualifiers.
628 ///
629 /// By default, performs semantic analysis when building the array type.
630 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000631 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000632 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000633 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000634 unsigned IndexTypeQuals,
635 SourceRange BracketsRange);
636
637 /// \brief Build a new vector type given the element type and
638 /// number of elements.
639 ///
640 /// By default, performs semantic analysis when building the vector type.
641 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000642 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000643 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000644
Douglas Gregor577f75a2009-08-04 16:50:30 +0000645 /// \brief Build a new extended vector type given the element type and
646 /// number of elements.
647 ///
648 /// By default, performs semantic analysis when building the vector type.
649 /// Subclasses may override this routine to provide different behavior.
650 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
651 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000652
653 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000654 /// given the element type and number of elements.
655 ///
656 /// By default, performs semantic analysis when building the vector type.
657 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000658 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000659 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000660 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000661
Douglas Gregor577f75a2009-08-04 16:50:30 +0000662 /// \brief Build a new function type.
663 ///
664 /// By default, performs semantic analysis when building the function type.
665 /// Subclasses may override this routine to provide different behavior.
666 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000667 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000668 unsigned NumParamTypes,
Eli Friedmanfa869542010-08-05 02:54:05 +0000669 bool Variadic, unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000670 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000671 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000672
John McCalla2becad2009-10-21 00:40:46 +0000673 /// \brief Build a new unprototyped function type.
674 QualType RebuildFunctionNoProtoType(QualType ResultType);
675
John McCalled976492009-12-04 22:46:56 +0000676 /// \brief Rebuild an unresolved typename type, given the decl that
677 /// the UnresolvedUsingTypenameDecl was transformed to.
678 QualType RebuildUnresolvedUsingType(Decl *D);
679
Douglas Gregor577f75a2009-08-04 16:50:30 +0000680 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000681 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000682 return SemaRef.Context.getTypeDeclType(Typedef);
683 }
684
685 /// \brief Build a new class/struct/union type.
686 QualType RebuildRecordType(RecordDecl *Record) {
687 return SemaRef.Context.getTypeDeclType(Record);
688 }
689
690 /// \brief Build a new Enum type.
691 QualType RebuildEnumType(EnumDecl *Enum) {
692 return SemaRef.Context.getTypeDeclType(Enum);
693 }
John McCall7da24312009-09-05 00:15:47 +0000694
Mike Stump1eb44332009-09-09 15:08:12 +0000695 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000696 ///
697 /// By default, performs semantic analysis when building the typeof type.
698 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000699 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000700
Mike Stump1eb44332009-09-09 15:08:12 +0000701 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000702 ///
703 /// By default, builds a new TypeOfType with the given underlying type.
704 QualType RebuildTypeOfType(QualType Underlying);
705
Sean Huntca63c202011-05-24 22:41:36 +0000706 /// \brief Build a new unary transform type.
707 QualType RebuildUnaryTransformType(QualType BaseType,
708 UnaryTransformType::UTTKind UKind,
709 SourceLocation Loc);
710
Mike Stump1eb44332009-09-09 15:08:12 +0000711 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000712 ///
713 /// By default, performs semantic analysis when building the decltype type.
714 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000715 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000716
Richard Smith34b41d92011-02-20 03:19:35 +0000717 /// \brief Build a new C++0x auto type.
718 ///
719 /// By default, builds a new AutoType with the given deduced type.
720 QualType RebuildAutoType(QualType Deduced) {
721 return SemaRef.Context.getAutoType(Deduced);
722 }
723
Douglas Gregor577f75a2009-08-04 16:50:30 +0000724 /// \brief Build a new template specialization type.
725 ///
726 /// By default, performs semantic analysis when building the template
727 /// specialization type. Subclasses may override this routine to provide
728 /// different behavior.
729 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000730 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000731 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000732
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000733 /// \brief Build a new parenthesized type.
734 ///
735 /// By default, builds a new ParenType type from the inner type.
736 /// Subclasses may override this routine to provide different behavior.
737 QualType RebuildParenType(QualType InnerType) {
738 return SemaRef.Context.getParenType(InnerType);
739 }
740
Douglas Gregor577f75a2009-08-04 16:50:30 +0000741 /// \brief Build a new qualified name type.
742 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000743 /// By default, builds a new ElaboratedType type from the keyword,
744 /// the nested-name-specifier and the named type.
745 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000746 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
747 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000748 NestedNameSpecifierLoc QualifierLoc,
749 QualType Named) {
750 return SemaRef.Context.getElaboratedType(Keyword,
751 QualifierLoc.getNestedNameSpecifier(),
752 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000753 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000754
755 /// \brief Build a new typename type that refers to a template-id.
756 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000757 /// By default, builds a new DependentNameType type from the
758 /// nested-name-specifier and the given type. Subclasses may override
759 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000760 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000761 ElaboratedTypeKeyword Keyword,
762 NestedNameSpecifierLoc QualifierLoc,
763 const IdentifierInfo *Name,
764 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000765 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000766 // Rebuild the template name.
767 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000768 CXXScopeSpec SS;
769 SS.Adopt(QualifierLoc);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000770 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000771 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000772
773 if (InstName.isNull())
774 return QualType();
775
776 // If it's still dependent, make a dependent specialization.
777 if (InstName.getAsDependentTemplateName())
778 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
779 QualifierLoc.getNestedNameSpecifier(),
780 Name,
781 Args);
782
783 // Otherwise, make an elaborated type wrapping a non-dependent
784 // specialization.
785 QualType T =
786 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
787 if (T.isNull()) return QualType();
788
789 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
790 return T;
791
792 return SemaRef.Context.getElaboratedType(Keyword,
793 QualifierLoc.getNestedNameSpecifier(),
794 T);
795 }
796
Douglas Gregor577f75a2009-08-04 16:50:30 +0000797 /// \brief Build a new typename type that refers to an identifier.
798 ///
799 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000800 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000801 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000802 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000803 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000804 NestedNameSpecifierLoc QualifierLoc,
805 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000806 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000807 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000808 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000809
Douglas Gregor2494dd02011-03-01 01:34:45 +0000810 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000811 // If the name is still dependent, just build a new dependent name type.
812 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor2494dd02011-03-01 01:34:45 +0000813 return SemaRef.Context.getDependentNameType(Keyword,
814 QualifierLoc.getNestedNameSpecifier(),
815 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000816 }
817
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000818 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000819 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000820 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000821
822 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
823
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000824 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000825 // into a non-dependent elaborated-type-specifier. Find the tag we're
826 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000827 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000828 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
829 if (!DC)
830 return QualType();
831
John McCall56138762010-05-27 06:40:31 +0000832 if (SemaRef.RequireCompleteDeclContext(SS, DC))
833 return QualType();
834
Douglas Gregor40336422010-03-31 22:19:08 +0000835 TagDecl *Tag = 0;
836 SemaRef.LookupQualifiedName(Result, DC);
837 switch (Result.getResultKind()) {
838 case LookupResult::NotFound:
839 case LookupResult::NotFoundInCurrentInstantiation:
840 break;
Sean Huntc3021132010-05-05 15:23:54 +0000841
Douglas Gregor40336422010-03-31 22:19:08 +0000842 case LookupResult::Found:
843 Tag = Result.getAsSingle<TagDecl>();
844 break;
Sean Huntc3021132010-05-05 15:23:54 +0000845
Douglas Gregor40336422010-03-31 22:19:08 +0000846 case LookupResult::FoundOverloaded:
847 case LookupResult::FoundUnresolvedValue:
848 llvm_unreachable("Tag lookup cannot find non-tags");
849 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000850
Douglas Gregor40336422010-03-31 22:19:08 +0000851 case LookupResult::Ambiguous:
852 // Let the LookupResult structure handle ambiguities.
853 return QualType();
854 }
855
856 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000857 // Check where the name exists but isn't a tag type and use that to emit
858 // better diagnostics.
859 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
860 SemaRef.LookupQualifiedName(Result, DC);
861 switch (Result.getResultKind()) {
862 case LookupResult::Found:
863 case LookupResult::FoundOverloaded:
864 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000865 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000866 unsigned Kind = 0;
867 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000868 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
869 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000870 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
871 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
872 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000873 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000874 default:
875 // FIXME: Would be nice to highlight just the source range.
876 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
877 << Kind << Id << DC;
878 break;
879 }
Douglas Gregor40336422010-03-31 22:19:08 +0000880 return QualType();
881 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000882
Richard Trieubbf34c02011-06-10 03:11:26 +0000883 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
884 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000885 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000886 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
887 return QualType();
888 }
889
890 // Build the elaborated-type-specifier type.
891 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor2494dd02011-03-01 01:34:45 +0000892 return SemaRef.Context.getElaboratedType(Keyword,
893 QualifierLoc.getNestedNameSpecifier(),
894 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000895 }
Mike Stump1eb44332009-09-09 15:08:12 +0000896
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000897 /// \brief Build a new pack expansion type.
898 ///
899 /// By default, builds a new PackExpansionType type from the given pattern.
900 /// Subclasses may override this routine to provide different behavior.
901 QualType RebuildPackExpansionType(QualType Pattern,
902 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000903 SourceLocation EllipsisLoc,
904 llvm::Optional<unsigned> NumExpansions) {
905 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
906 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000907 }
908
Eli Friedmanb001de72011-10-06 23:00:33 +0000909 /// \brief Build a new atomic type given its value type.
910 ///
911 /// By default, performs semantic analysis when building the atomic type.
912 /// Subclasses may override this routine to provide different behavior.
913 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
914
Douglas Gregord1067e52009-08-06 06:41:21 +0000915 /// \brief Build a new template name given a nested name specifier, a flag
916 /// indicating whether the "template" keyword was provided, and the template
917 /// that the template name refers to.
918 ///
919 /// By default, builds the new template name directly. Subclasses may override
920 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000921 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000922 bool TemplateKW,
923 TemplateDecl *Template);
924
Douglas Gregord1067e52009-08-06 06:41:21 +0000925 /// \brief Build a new template name given a nested name specifier and the
926 /// name that is referred to as a template.
927 ///
928 /// By default, performs semantic analysis to determine whether the name can
929 /// be resolved to a specific template, then builds the appropriate kind of
930 /// template name. Subclasses may override this routine to provide different
931 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000932 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
933 const IdentifierInfo &Name,
934 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000935 QualType ObjectType,
936 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000937
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000938 /// \brief Build a new template name given a nested name specifier and the
939 /// overloaded operator name that is referred to as a template.
940 ///
941 /// By default, performs semantic analysis to determine whether the name can
942 /// be resolved to a specific template, then builds the appropriate kind of
943 /// template name. Subclasses may override this routine to provide different
944 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000945 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000946 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000947 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000948 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000949
950 /// \brief Build a new template name given a template template parameter pack
951 /// and the
952 ///
953 /// By default, performs semantic analysis to determine whether the name can
954 /// be resolved to a specific template, then builds the appropriate kind of
955 /// template name. Subclasses may override this routine to provide different
956 /// behavior.
957 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
958 const TemplateArgument &ArgPack) {
959 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
960 }
961
Douglas Gregor43959a92009-08-20 07:17:43 +0000962 /// \brief Build a new compound statement.
963 ///
964 /// By default, performs semantic analysis to build the new statement.
965 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000966 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000967 MultiStmtArg Statements,
968 SourceLocation RBraceLoc,
969 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000970 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +0000971 IsStmtExpr);
972 }
973
974 /// \brief Build a new case statement.
975 ///
976 /// By default, performs semantic analysis to build the new statement.
977 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000978 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000979 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000980 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000981 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000982 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000983 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000984 ColonLoc);
985 }
Mike Stump1eb44332009-09-09 15:08:12 +0000986
Douglas Gregor43959a92009-08-20 07:17:43 +0000987 /// \brief Attach the body to a new case statement.
988 ///
989 /// By default, performs semantic analysis to build the new statement.
990 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000991 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000992 getSema().ActOnCaseStmtBody(S, Body);
993 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000994 }
Mike Stump1eb44332009-09-09 15:08:12 +0000995
Douglas Gregor43959a92009-08-20 07:17:43 +0000996 /// \brief Build a new default statement.
997 ///
998 /// By default, performs semantic analysis to build the new statement.
999 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001000 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001001 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001002 Stmt *SubStmt) {
1003 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001004 /*CurScope=*/0);
1005 }
Mike Stump1eb44332009-09-09 15:08:12 +00001006
Douglas Gregor43959a92009-08-20 07:17:43 +00001007 /// \brief Build a new label statement.
1008 ///
1009 /// By default, performs semantic analysis to build the new statement.
1010 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001011 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1012 SourceLocation ColonLoc, Stmt *SubStmt) {
1013 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001014 }
Mike Stump1eb44332009-09-09 15:08:12 +00001015
Douglas Gregor43959a92009-08-20 07:17:43 +00001016 /// \brief Build a new "if" statement.
1017 ///
1018 /// By default, performs semantic analysis to build the new statement.
1019 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001020 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattner57ad3782011-02-17 20:34:02 +00001021 VarDecl *CondVar, Stmt *Then,
1022 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001023 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001024 }
Mike Stump1eb44332009-09-09 15:08:12 +00001025
Douglas Gregor43959a92009-08-20 07:17:43 +00001026 /// \brief Start building a new switch statement.
1027 ///
1028 /// By default, performs semantic analysis to build the new statement.
1029 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001030 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001031 Expr *Cond, VarDecl *CondVar) {
John McCall9ae2f072010-08-23 23:25:46 +00001032 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001033 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001034 }
Mike Stump1eb44332009-09-09 15:08:12 +00001035
Douglas Gregor43959a92009-08-20 07:17:43 +00001036 /// \brief Attach the body to the switch statement.
1037 ///
1038 /// By default, performs semantic analysis to build the new statement.
1039 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001040 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001041 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001042 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001043 }
1044
1045 /// \brief Build a new while statement.
1046 ///
1047 /// By default, performs semantic analysis to build the new statement.
1048 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001049 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1050 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001051 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001052 }
Mike Stump1eb44332009-09-09 15:08:12 +00001053
Douglas Gregor43959a92009-08-20 07:17:43 +00001054 /// \brief Build a new do-while statement.
1055 ///
1056 /// By default, performs semantic analysis to build the new statement.
1057 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001058 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001059 SourceLocation WhileLoc, SourceLocation LParenLoc,
1060 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001061 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1062 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001063 }
1064
1065 /// \brief Build a new for statement.
1066 ///
1067 /// By default, performs semantic analysis to build the new statement.
1068 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001069 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1070 Stmt *Init, Sema::FullExprArg Cond,
1071 VarDecl *CondVar, Sema::FullExprArg Inc,
1072 SourceLocation RParenLoc, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001073 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001074 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001075 }
Mike Stump1eb44332009-09-09 15:08:12 +00001076
Douglas Gregor43959a92009-08-20 07:17:43 +00001077 /// \brief Build a new goto statement.
1078 ///
1079 /// By default, performs semantic analysis to build the new statement.
1080 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001081 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1082 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001083 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001084 }
1085
1086 /// \brief Build a new indirect goto statement.
1087 ///
1088 /// By default, performs semantic analysis to build the new statement.
1089 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001090 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001091 SourceLocation StarLoc,
1092 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001093 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001094 }
Mike Stump1eb44332009-09-09 15:08:12 +00001095
Douglas Gregor43959a92009-08-20 07:17:43 +00001096 /// \brief Build a new return statement.
1097 ///
1098 /// By default, performs semantic analysis to build the new statement.
1099 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001100 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001101 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001102 }
Mike Stump1eb44332009-09-09 15:08:12 +00001103
Douglas Gregor43959a92009-08-20 07:17:43 +00001104 /// \brief Build a new declaration statement.
1105 ///
1106 /// By default, performs semantic analysis to build the new statement.
1107 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001108 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001109 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001110 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001111 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1112 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001113 }
Mike Stump1eb44332009-09-09 15:08:12 +00001114
Anders Carlsson703e3942010-01-24 05:50:09 +00001115 /// \brief Build a new inline asm statement.
1116 ///
1117 /// By default, performs semantic analysis to build the new statement.
1118 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001119 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001120 bool IsSimple,
1121 bool IsVolatile,
1122 unsigned NumOutputs,
1123 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001124 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001125 MultiExprArg Constraints,
1126 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001127 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001128 MultiExprArg Clobbers,
1129 SourceLocation RParenLoc,
1130 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001131 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001132 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001133 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001134 RParenLoc, MSAsm);
1135 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001136
1137 /// \brief Build a new Objective-C @try statement.
1138 ///
1139 /// By default, performs semantic analysis to build the new statement.
1140 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001141 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001142 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001143 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001144 Stmt *Finally) {
1145 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1146 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001147 }
1148
Douglas Gregorbe270a02010-04-26 17:57:08 +00001149 /// \brief Rebuild an Objective-C exception declaration.
1150 ///
1151 /// By default, performs semantic analysis to build the new declaration.
1152 /// Subclasses may override this routine to provide different behavior.
1153 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1154 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001155 return getSema().BuildObjCExceptionDecl(TInfo, T,
1156 ExceptionDecl->getInnerLocStart(),
1157 ExceptionDecl->getLocation(),
1158 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001159 }
Sean Huntc3021132010-05-05 15:23:54 +00001160
Douglas Gregorbe270a02010-04-26 17:57:08 +00001161 /// \brief Build a new Objective-C @catch statement.
1162 ///
1163 /// By default, performs semantic analysis to build the new statement.
1164 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001165 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001166 SourceLocation RParenLoc,
1167 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001168 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001169 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001170 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001171 }
Sean Huntc3021132010-05-05 15:23:54 +00001172
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001173 /// \brief Build a new Objective-C @finally statement.
1174 ///
1175 /// By default, performs semantic analysis to build the new statement.
1176 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001177 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001178 Stmt *Body) {
1179 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001180 }
Sean Huntc3021132010-05-05 15:23:54 +00001181
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001182 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001183 ///
1184 /// By default, performs semantic analysis to build the new statement.
1185 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001186 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001187 Expr *Operand) {
1188 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001189 }
Sean Huntc3021132010-05-05 15:23:54 +00001190
John McCall07524032011-07-27 21:50:02 +00001191 /// \brief Rebuild the operand to an Objective-C @synchronized statement.
1192 ///
1193 /// By default, performs semantic analysis to build the new statement.
1194 /// Subclasses may override this routine to provide different behavior.
1195 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1196 Expr *object) {
1197 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1198 }
1199
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001200 /// \brief Build a new Objective-C @synchronized statement.
1201 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001202 /// By default, performs semantic analysis to build the new statement.
1203 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001204 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001205 Expr *Object, Stmt *Body) {
1206 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001207 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001208
John McCallf85e1932011-06-15 23:02:42 +00001209 /// \brief Build a new Objective-C @autoreleasepool statement.
1210 ///
1211 /// By default, performs semantic analysis to build the new statement.
1212 /// Subclasses may override this routine to provide different behavior.
1213 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1214 Stmt *Body) {
1215 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1216 }
John McCall990567c2011-07-27 01:07:15 +00001217
1218 /// \brief Build the collection operand to a new Objective-C fast
1219 /// enumeration statement.
1220 ///
1221 /// By default, performs semantic analysis to build the new statement.
1222 /// Subclasses may override this routine to provide different behavior.
1223 ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc,
1224 Expr *collection) {
1225 return getSema().ActOnObjCForCollectionOperand(forLoc, collection);
1226 }
John McCallf85e1932011-06-15 23:02:42 +00001227
Douglas Gregorc3203e72010-04-22 23:10:45 +00001228 /// \brief Build a new Objective-C fast enumeration statement.
1229 ///
1230 /// By default, performs semantic analysis to build the new statement.
1231 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001232 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001233 SourceLocation LParenLoc,
1234 Stmt *Element,
1235 Expr *Collection,
1236 SourceLocation RParenLoc,
1237 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001238 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001239 Element,
1240 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001241 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001242 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001243 }
Sean Huntc3021132010-05-05 15:23:54 +00001244
Douglas Gregor43959a92009-08-20 07:17:43 +00001245 /// \brief Build a new C++ exception declaration.
1246 ///
1247 /// By default, performs semantic analysis to build the new decaration.
1248 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001249 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001250 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001251 SourceLocation StartLoc,
1252 SourceLocation IdLoc,
1253 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001254 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1255 StartLoc, IdLoc, Id);
1256 if (Var)
1257 getSema().CurContext->addDecl(Var);
1258 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001259 }
1260
1261 /// \brief Build a new C++ catch statement.
1262 ///
1263 /// By default, performs semantic analysis to build the new statement.
1264 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001265 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001266 VarDecl *ExceptionDecl,
1267 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001268 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1269 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001270 }
Mike Stump1eb44332009-09-09 15:08:12 +00001271
Douglas Gregor43959a92009-08-20 07:17:43 +00001272 /// \brief Build a new C++ try statement.
1273 ///
1274 /// By default, performs semantic analysis to build the new statement.
1275 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001276 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001277 Stmt *TryBlock,
1278 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001279 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001280 }
Mike Stump1eb44332009-09-09 15:08:12 +00001281
Richard Smithad762fc2011-04-14 22:09:26 +00001282 /// \brief Build a new C++0x range-based for statement.
1283 ///
1284 /// By default, performs semantic analysis to build the new statement.
1285 /// Subclasses may override this routine to provide different behavior.
1286 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1287 SourceLocation ColonLoc,
1288 Stmt *Range, Stmt *BeginEnd,
1289 Expr *Cond, Expr *Inc,
1290 Stmt *LoopVar,
1291 SourceLocation RParenLoc) {
1292 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1293 Cond, Inc, LoopVar, RParenLoc);
1294 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001295
1296 /// \brief Build a new C++0x range-based for statement.
1297 ///
1298 /// By default, performs semantic analysis to build the new statement.
1299 /// Subclasses may override this routine to provide different behavior.
1300 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
1301 bool IsIfExists,
1302 NestedNameSpecifierLoc QualifierLoc,
1303 DeclarationNameInfo NameInfo,
1304 Stmt *Nested) {
1305 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1306 QualifierLoc, NameInfo, Nested);
1307 }
1308
Richard Smithad762fc2011-04-14 22:09:26 +00001309 /// \brief Attach body to a C++0x range-based for statement.
1310 ///
1311 /// By default, performs semantic analysis to finish the new statement.
1312 /// Subclasses may override this routine to provide different behavior.
1313 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1314 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1315 }
1316
John Wiegley28bbe4b2011-04-28 01:08:34 +00001317 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1318 SourceLocation TryLoc,
1319 Stmt *TryBlock,
1320 Stmt *Handler) {
1321 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1322 }
1323
1324 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1325 Expr *FilterExpr,
1326 Stmt *Block) {
1327 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1328 }
1329
1330 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1331 Stmt *Block) {
1332 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1333 }
1334
Douglas Gregorb98b1992009-08-11 05:31:07 +00001335 /// \brief Build a new expression that references a declaration.
1336 ///
1337 /// By default, performs semantic analysis to build the new expression.
1338 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001339 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001340 LookupResult &R,
1341 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001342 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1343 }
1344
1345
1346 /// \brief Build a new expression that references a declaration.
1347 ///
1348 /// By default, performs semantic analysis to build the new expression.
1349 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001350 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001351 ValueDecl *VD,
1352 const DeclarationNameInfo &NameInfo,
1353 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001354 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001355 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001356
1357 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001358
1359 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001360 }
Mike Stump1eb44332009-09-09 15:08:12 +00001361
Douglas Gregorb98b1992009-08-11 05:31:07 +00001362 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001363 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001364 /// By default, performs semantic analysis to build the new expression.
1365 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001366 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001367 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001368 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001369 }
1370
Douglas Gregora71d8192009-09-04 17:36:40 +00001371 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001372 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001373 /// By default, performs semantic analysis to build the new expression.
1374 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001375 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001376 SourceLocation OperatorLoc,
1377 bool isArrow,
1378 CXXScopeSpec &SS,
1379 TypeSourceInfo *ScopeType,
1380 SourceLocation CCLoc,
1381 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001382 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001383
Douglas Gregorb98b1992009-08-11 05:31:07 +00001384 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001385 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001386 /// By default, performs semantic analysis to build the new expression.
1387 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001388 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001389 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001390 Expr *SubExpr) {
1391 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001392 }
Mike Stump1eb44332009-09-09 15:08:12 +00001393
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001394 /// \brief Build a new builtin offsetof expression.
1395 ///
1396 /// By default, performs semantic analysis to build the new expression.
1397 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001398 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001399 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001400 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001401 unsigned NumComponents,
1402 SourceLocation RParenLoc) {
1403 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1404 NumComponents, RParenLoc);
1405 }
Sean Huntc3021132010-05-05 15:23:54 +00001406
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001407 /// \brief Build a new sizeof, alignof or vec_step expression with a
1408 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001409 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001410 /// By default, performs semantic analysis to build the new expression.
1411 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001412 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1413 SourceLocation OpLoc,
1414 UnaryExprOrTypeTrait ExprKind,
1415 SourceRange R) {
1416 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001417 }
1418
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001419 /// \brief Build a new sizeof, alignof or vec step expression with an
1420 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001421 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001422 /// By default, performs semantic analysis to build the new expression.
1423 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001424 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1425 UnaryExprOrTypeTrait ExprKind,
1426 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001427 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001428 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001429 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001430 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001431
Douglas Gregorb98b1992009-08-11 05:31:07 +00001432 return move(Result);
1433 }
Mike Stump1eb44332009-09-09 15:08:12 +00001434
Douglas Gregorb98b1992009-08-11 05:31:07 +00001435 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001436 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001437 /// By default, performs semantic analysis to build the new expression.
1438 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001439 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001440 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001441 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001442 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001443 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1444 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001445 RBracketLoc);
1446 }
1447
1448 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001449 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001450 /// By default, performs semantic analysis to build the new expression.
1451 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001452 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001453 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001454 SourceLocation RParenLoc,
1455 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001456 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001457 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001458 }
1459
1460 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001461 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001462 /// By default, performs semantic analysis to build the new expression.
1463 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001464 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001465 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001466 NestedNameSpecifierLoc QualifierLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001467 const DeclarationNameInfo &MemberNameInfo,
1468 ValueDecl *Member,
1469 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001470 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001471 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001472 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1473 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001474 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001475 // We have a reference to an unnamed field. This is always the
1476 // base of an anonymous struct/union member access, i.e. the
1477 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001478 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001479 assert(Member->getType()->isRecordType() &&
1480 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001481
Richard Smith9138b4e2011-10-26 19:06:56 +00001482 BaseResult =
1483 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001484 QualifierLoc.getNestedNameSpecifier(),
1485 FoundDecl, Member);
1486 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001487 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001488 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001489 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001490 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001491 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001492 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001493 cast<FieldDecl>(Member)->getType(),
1494 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001495 return getSema().Owned(ME);
1496 }
Mike Stump1eb44332009-09-09 15:08:12 +00001497
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001498 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001499 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001500
John Wiegley429bb272011-04-08 18:41:53 +00001501 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001502 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001503
John McCall6bb80172010-03-30 21:47:33 +00001504 // FIXME: this involves duplicating earlier analysis in a lot of
1505 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001506 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001507 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001508 R.resolveKind();
1509
John McCall9ae2f072010-08-23 23:25:46 +00001510 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001511 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001512 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001513 }
Mike Stump1eb44332009-09-09 15:08:12 +00001514
Douglas Gregorb98b1992009-08-11 05:31:07 +00001515 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001516 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001517 /// By default, performs semantic analysis to build the new expression.
1518 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001519 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001520 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001521 Expr *LHS, Expr *RHS) {
1522 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001523 }
1524
1525 /// \brief Build a new conditional operator 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 RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001530 SourceLocation QuestionLoc,
1531 Expr *LHS,
1532 SourceLocation ColonLoc,
1533 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001534 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1535 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001536 }
1537
Douglas Gregorb98b1992009-08-11 05:31:07 +00001538 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001539 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001540 /// By default, performs semantic analysis to build the new expression.
1541 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001542 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001543 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001544 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001545 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001546 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001547 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001548 }
Mike Stump1eb44332009-09-09 15:08:12 +00001549
Douglas Gregorb98b1992009-08-11 05:31:07 +00001550 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001551 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001552 /// By default, performs semantic analysis to build the new expression.
1553 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001554 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001555 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001556 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001557 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001558 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001559 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001560 }
Mike Stump1eb44332009-09-09 15:08:12 +00001561
Douglas Gregorb98b1992009-08-11 05:31:07 +00001562 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001563 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001564 /// By default, performs semantic analysis to build the new expression.
1565 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001566 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001567 SourceLocation OpLoc,
1568 SourceLocation AccessorLoc,
1569 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001570
John McCall129e2df2009-11-30 22:42:35 +00001571 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001572 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001573 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001574 OpLoc, /*IsArrow*/ false,
1575 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001576 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001577 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001578 }
Mike Stump1eb44332009-09-09 15:08:12 +00001579
Douglas Gregorb98b1992009-08-11 05:31:07 +00001580 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001581 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001582 /// By default, performs semantic analysis to build the new expression.
1583 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001584 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001585 MultiExprArg Inits,
1586 SourceLocation RBraceLoc,
1587 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001588 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001589 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1590 if (Result.isInvalid() || ResultTy->isDependentType())
1591 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001592
Douglas Gregore48319a2009-11-09 17:16:50 +00001593 // Patch in the result type we were given, which may have been computed
1594 // when the initial InitListExpr was built.
1595 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1596 ILE->setType(ResultTy);
1597 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001598 }
Mike Stump1eb44332009-09-09 15:08:12 +00001599
Douglas Gregorb98b1992009-08-11 05:31:07 +00001600 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001601 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 /// By default, performs semantic analysis to build the new expression.
1603 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001604 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001605 MultiExprArg ArrayExprs,
1606 SourceLocation EqualOrColonLoc,
1607 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001608 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001609 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001610 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001611 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001612 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001613 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001614
Douglas Gregorb98b1992009-08-11 05:31:07 +00001615 ArrayExprs.release();
1616 return move(Result);
1617 }
Mike Stump1eb44332009-09-09 15:08:12 +00001618
Douglas Gregorb98b1992009-08-11 05:31:07 +00001619 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001620 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001621 /// By default, builds the implicit value initialization without performing
1622 /// any semantic analysis. Subclasses may override this routine to provide
1623 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001624 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001625 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1626 }
Mike Stump1eb44332009-09-09 15:08:12 +00001627
Douglas Gregorb98b1992009-08-11 05:31:07 +00001628 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001629 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001630 /// By default, performs semantic analysis to build the new expression.
1631 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001632 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001633 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001634 SourceLocation RParenLoc) {
1635 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001636 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001637 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001638 }
1639
1640 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001641 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001642 /// By default, performs semantic analysis to build the new expression.
1643 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001644 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001645 MultiExprArg SubExprs,
1646 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001647 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001648 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001649 }
Mike Stump1eb44332009-09-09 15:08:12 +00001650
Douglas Gregorb98b1992009-08-11 05:31:07 +00001651 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001652 ///
1653 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001654 /// rather than attempting to map the label statement itself.
1655 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001656 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001657 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001658 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001659 }
Mike Stump1eb44332009-09-09 15:08:12 +00001660
Douglas Gregorb98b1992009-08-11 05:31:07 +00001661 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001662 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001663 /// By default, performs semantic analysis to build the new expression.
1664 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001665 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001666 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001667 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001668 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001669 }
Mike Stump1eb44332009-09-09 15:08:12 +00001670
Douglas Gregorb98b1992009-08-11 05:31:07 +00001671 /// \brief Build a new __builtin_choose_expr expression.
1672 ///
1673 /// By default, performs semantic analysis to build the new expression.
1674 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001675 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001676 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001677 SourceLocation RParenLoc) {
1678 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001679 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001680 RParenLoc);
1681 }
Mike Stump1eb44332009-09-09 15:08:12 +00001682
Peter Collingbournef111d932011-04-15 00:35:48 +00001683 /// \brief Build a new generic selection expression.
1684 ///
1685 /// By default, performs semantic analysis to build the new expression.
1686 /// Subclasses may override this routine to provide different behavior.
1687 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1688 SourceLocation DefaultLoc,
1689 SourceLocation RParenLoc,
1690 Expr *ControllingExpr,
1691 TypeSourceInfo **Types,
1692 Expr **Exprs,
1693 unsigned NumAssocs) {
1694 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1695 ControllingExpr, Types, Exprs,
1696 NumAssocs);
1697 }
1698
Douglas Gregorb98b1992009-08-11 05:31:07 +00001699 /// \brief Build a new overloaded operator call expression.
1700 ///
1701 /// By default, performs semantic analysis to build the new expression.
1702 /// The semantic analysis provides the behavior of template instantiation,
1703 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001704 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001705 /// argument-dependent lookup, etc. Subclasses may override this routine to
1706 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001707 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001708 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001709 Expr *Callee,
1710 Expr *First,
1711 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001712
1713 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001714 /// reinterpret_cast.
1715 ///
1716 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001717 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001719 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001720 Stmt::StmtClass Class,
1721 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001722 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001723 SourceLocation RAngleLoc,
1724 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001725 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001726 SourceLocation RParenLoc) {
1727 switch (Class) {
1728 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001729 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001730 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001731 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001732
1733 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001734 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001735 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001736 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001737
Douglas Gregorb98b1992009-08-11 05:31:07 +00001738 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001739 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001740 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001741 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001742 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001743
Douglas Gregorb98b1992009-08-11 05:31:07 +00001744 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001745 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001746 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001747 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001748
Douglas Gregorb98b1992009-08-11 05:31:07 +00001749 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001750 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001751 }
Mike Stump1eb44332009-09-09 15:08:12 +00001752
John McCallf312b1e2010-08-26 23:41:50 +00001753 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001754 }
Mike Stump1eb44332009-09-09 15:08:12 +00001755
Douglas Gregorb98b1992009-08-11 05:31:07 +00001756 /// \brief Build a new C++ static_cast expression.
1757 ///
1758 /// By default, performs semantic analysis to build the new expression.
1759 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001760 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001761 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001762 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001763 SourceLocation RAngleLoc,
1764 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001765 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001766 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001767 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001768 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001769 SourceRange(LAngleLoc, RAngleLoc),
1770 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001771 }
1772
1773 /// \brief Build a new C++ dynamic_cast expression.
1774 ///
1775 /// By default, performs semantic analysis to build the new expression.
1776 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001777 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001778 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001779 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001780 SourceLocation RAngleLoc,
1781 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001782 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001783 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001784 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001785 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001786 SourceRange(LAngleLoc, RAngleLoc),
1787 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001788 }
1789
1790 /// \brief Build a new C++ reinterpret_cast expression.
1791 ///
1792 /// By default, performs semantic analysis to build the new expression.
1793 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001794 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001795 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001796 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001797 SourceLocation RAngleLoc,
1798 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001799 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001800 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001801 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001802 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001803 SourceRange(LAngleLoc, RAngleLoc),
1804 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001805 }
1806
1807 /// \brief Build a new C++ const_cast expression.
1808 ///
1809 /// By default, performs semantic analysis to build the new expression.
1810 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001811 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001812 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001813 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001814 SourceLocation RAngleLoc,
1815 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001816 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001817 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001818 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001819 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001820 SourceRange(LAngleLoc, RAngleLoc),
1821 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001822 }
Mike Stump1eb44332009-09-09 15:08:12 +00001823
Douglas Gregorb98b1992009-08-11 05:31:07 +00001824 /// \brief Build a new C++ functional-style cast expression.
1825 ///
1826 /// By default, performs semantic analysis to build the new expression.
1827 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001828 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1829 SourceLocation LParenLoc,
1830 Expr *Sub,
1831 SourceLocation RParenLoc) {
1832 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001833 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001834 RParenLoc);
1835 }
Mike Stump1eb44332009-09-09 15:08:12 +00001836
Douglas Gregorb98b1992009-08-11 05:31:07 +00001837 /// \brief Build a new C++ typeid(type) 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,
1843 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001844 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001845 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001846 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001847 }
Mike Stump1eb44332009-09-09 15:08:12 +00001848
Francois Pichet01b7c302010-09-08 12:20:18 +00001849
Douglas Gregorb98b1992009-08-11 05:31:07 +00001850 /// \brief Build a new C++ typeid(expr) expression.
1851 ///
1852 /// By default, performs semantic analysis to build the new expression.
1853 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001854 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001855 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001856 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001857 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001858 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001859 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001860 }
1861
Francois Pichet01b7c302010-09-08 12:20:18 +00001862 /// \brief Build a new C++ __uuidof(type) expression.
1863 ///
1864 /// By default, performs semantic analysis to build the new expression.
1865 /// Subclasses may override this routine to provide different behavior.
1866 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1867 SourceLocation TypeidLoc,
1868 TypeSourceInfo *Operand,
1869 SourceLocation RParenLoc) {
1870 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1871 RParenLoc);
1872 }
1873
1874 /// \brief Build a new C++ __uuidof(expr) expression.
1875 ///
1876 /// By default, performs semantic analysis to build the new expression.
1877 /// Subclasses may override this routine to provide different behavior.
1878 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1879 SourceLocation TypeidLoc,
1880 Expr *Operand,
1881 SourceLocation RParenLoc) {
1882 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1883 RParenLoc);
1884 }
1885
Douglas Gregorb98b1992009-08-11 05:31:07 +00001886 /// \brief Build a new C++ "this" expression.
1887 ///
1888 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001889 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001890 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001891 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001892 QualType ThisType,
1893 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001894 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001895 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001896 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1897 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001898 }
1899
1900 /// \brief Build a new C++ throw expression.
1901 ///
1902 /// By default, performs semantic analysis to build the new expression.
1903 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001904 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1905 bool IsThrownVariableInScope) {
1906 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001907 }
1908
1909 /// \brief Build a new C++ default-argument expression.
1910 ///
1911 /// By default, builds a new default-argument expression, which does not
1912 /// require any semantic analysis. Subclasses may override this routine to
1913 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001914 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001915 ParmVarDecl *Param) {
1916 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1917 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001918 }
1919
1920 /// \brief Build a new C++ zero-initialization expression.
1921 ///
1922 /// By default, performs semantic analysis to build the new expression.
1923 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001924 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1925 SourceLocation LParenLoc,
1926 SourceLocation RParenLoc) {
1927 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001928 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001929 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001930 }
Mike Stump1eb44332009-09-09 15:08:12 +00001931
Douglas Gregorb98b1992009-08-11 05:31:07 +00001932 /// \brief Build a new C++ "new" expression.
1933 ///
1934 /// By default, performs semantic analysis to build the new expression.
1935 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001936 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001937 bool UseGlobal,
1938 SourceLocation PlacementLParen,
1939 MultiExprArg PlacementArgs,
1940 SourceLocation PlacementRParen,
1941 SourceRange TypeIdParens,
1942 QualType AllocatedType,
1943 TypeSourceInfo *AllocatedTypeInfo,
1944 Expr *ArraySize,
1945 SourceLocation ConstructorLParen,
1946 MultiExprArg ConstructorArgs,
1947 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001948 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001949 PlacementLParen,
1950 move(PlacementArgs),
1951 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001952 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001953 AllocatedType,
1954 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001955 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001956 ConstructorLParen,
1957 move(ConstructorArgs),
1958 ConstructorRParen);
1959 }
Mike Stump1eb44332009-09-09 15:08:12 +00001960
Douglas Gregorb98b1992009-08-11 05:31:07 +00001961 /// \brief Build a new C++ "delete" expression.
1962 ///
1963 /// By default, performs semantic analysis to build the new expression.
1964 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001965 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001966 bool IsGlobalDelete,
1967 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001968 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001969 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001970 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001971 }
Mike Stump1eb44332009-09-09 15:08:12 +00001972
Douglas Gregorb98b1992009-08-11 05:31:07 +00001973 /// \brief Build a new unary type trait expression.
1974 ///
1975 /// By default, performs semantic analysis to build the new expression.
1976 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001977 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001978 SourceLocation StartLoc,
1979 TypeSourceInfo *T,
1980 SourceLocation RParenLoc) {
1981 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001982 }
1983
Francois Pichet6ad6f282010-12-07 00:08:36 +00001984 /// \brief Build a new binary type trait expression.
1985 ///
1986 /// By default, performs semantic analysis to build the new expression.
1987 /// Subclasses may override this routine to provide different behavior.
1988 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1989 SourceLocation StartLoc,
1990 TypeSourceInfo *LhsT,
1991 TypeSourceInfo *RhsT,
1992 SourceLocation RParenLoc) {
1993 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1994 }
1995
John Wiegley21ff2e52011-04-28 00:16:57 +00001996 /// \brief Build a new array type trait expression.
1997 ///
1998 /// By default, performs semantic analysis to build the new expression.
1999 /// Subclasses may override this routine to provide different behavior.
2000 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2001 SourceLocation StartLoc,
2002 TypeSourceInfo *TSInfo,
2003 Expr *DimExpr,
2004 SourceLocation RParenLoc) {
2005 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2006 }
2007
John Wiegley55262202011-04-25 06:54:41 +00002008 /// \brief Build a new expression trait expression.
2009 ///
2010 /// By default, performs semantic analysis to build the new expression.
2011 /// Subclasses may override this routine to provide different behavior.
2012 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2013 SourceLocation StartLoc,
2014 Expr *Queried,
2015 SourceLocation RParenLoc) {
2016 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2017 }
2018
Mike Stump1eb44332009-09-09 15:08:12 +00002019 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002020 /// expression.
2021 ///
2022 /// By default, performs semantic analysis to build the new expression.
2023 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002024 ExprResult RebuildDependentScopeDeclRefExpr(
2025 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002026 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002027 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002028 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002029 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002030
2031 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00002032 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002033 *TemplateArgs);
2034
Abramo Bagnara25777432010-08-11 22:01:17 +00002035 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002036 }
2037
2038 /// \brief Build a new template-id expression.
2039 ///
2040 /// By default, performs semantic analysis to build the new expression.
2041 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002042 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00002043 LookupResult &R,
2044 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00002045 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00002046 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002047 }
2048
2049 /// \brief Build a new object-construction expression.
2050 ///
2051 /// By default, performs semantic analysis to build the new expression.
2052 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002053 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002054 SourceLocation Loc,
2055 CXXConstructorDecl *Constructor,
2056 bool IsElidable,
2057 MultiExprArg Args,
2058 bool HadMultipleCandidates,
2059 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002060 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002061 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00002062 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00002063 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002064 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002065 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002066
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002067 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002068 move_arg(ConvertedArgs),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002069 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002070 RequiresZeroInit, ConstructKind,
2071 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002072 }
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 RebuildCXXTemporaryObjectExpr(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 }
2087
2088 /// \brief Build a new object-construction expression.
2089 ///
2090 /// By default, performs semantic analysis to build the new expression.
2091 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002092 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2093 SourceLocation LParenLoc,
2094 MultiExprArg Args,
2095 SourceLocation RParenLoc) {
2096 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002097 LParenLoc,
2098 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002099 RParenLoc);
2100 }
Mike Stump1eb44332009-09-09 15:08:12 +00002101
Douglas Gregorb98b1992009-08-11 05:31:07 +00002102 /// \brief Build a new member reference expression.
2103 ///
2104 /// By default, performs semantic analysis to build the new expression.
2105 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002106 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002107 QualType BaseType,
2108 bool IsArrow,
2109 SourceLocation OperatorLoc,
2110 NestedNameSpecifierLoc QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00002111 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002112 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002113 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002114 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002115 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002116
John McCall9ae2f072010-08-23 23:25:46 +00002117 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002118 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00002119 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002120 MemberNameInfo,
2121 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002122 }
2123
John McCall129e2df2009-11-30 22:42:35 +00002124 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002125 ///
2126 /// By default, performs semantic analysis to build the new expression.
2127 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002128 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2129 SourceLocation OperatorLoc,
2130 bool IsArrow,
2131 NestedNameSpecifierLoc QualifierLoc,
2132 NamedDecl *FirstQualifierInScope,
2133 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002134 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002135 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002136 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002137
John McCall9ae2f072010-08-23 23:25:46 +00002138 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002139 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00002140 SS, FirstQualifierInScope,
2141 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002142 }
Mike Stump1eb44332009-09-09 15:08:12 +00002143
Sebastian Redl2e156222010-09-10 20:55:43 +00002144 /// \brief Build a new noexcept expression.
2145 ///
2146 /// By default, performs semantic analysis to build the new expression.
2147 /// Subclasses may override this routine to provide different behavior.
2148 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2149 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2150 }
2151
Douglas Gregoree8aff02011-01-04 17:33:58 +00002152 /// \brief Build a new expression to compute the length of a parameter pack.
2153 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2154 SourceLocation PackLoc,
2155 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002156 llvm::Optional<unsigned> Length) {
2157 if (Length)
2158 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2159 OperatorLoc, Pack, PackLoc,
2160 RParenLoc, *Length);
2161
Douglas Gregoree8aff02011-01-04 17:33:58 +00002162 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2163 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002164 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002165 }
2166
Douglas Gregorb98b1992009-08-11 05:31:07 +00002167 /// \brief Build a new Objective-C @encode expression.
2168 ///
2169 /// By default, performs semantic analysis to build the new expression.
2170 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002171 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002172 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002173 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002174 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002175 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002176 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002177
Douglas Gregor92e986e2010-04-22 16:44:27 +00002178 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002179 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002180 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002181 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002182 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002183 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002184 MultiExprArg Args,
2185 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002186 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2187 ReceiverTypeInfo->getType(),
2188 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002189 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002190 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002191 }
2192
2193 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002194 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002195 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002196 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002197 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002198 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002199 MultiExprArg Args,
2200 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002201 return SemaRef.BuildInstanceMessage(Receiver,
2202 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002203 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002204 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002205 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002206 }
2207
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002208 /// \brief Build a new Objective-C ivar reference expression.
2209 ///
2210 /// By default, performs semantic analysis to build the new expression.
2211 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002212 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002213 SourceLocation IvarLoc,
2214 bool IsArrow, bool IsFreeIvar) {
2215 // FIXME: We lose track of the IsFreeIvar bit.
2216 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002217 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002218 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2219 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002220 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002221 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002222 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002223 false);
John Wiegley429bb272011-04-08 18:41:53 +00002224 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002225 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002226
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002227 if (Result.get())
2228 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002229
John Wiegley429bb272011-04-08 18:41:53 +00002230 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002231 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002232 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002233 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002234 /*TemplateArgs=*/0);
2235 }
Douglas Gregore3303542010-04-26 20:47:02 +00002236
2237 /// \brief Build a new Objective-C property reference expression.
2238 ///
2239 /// By default, performs semantic analysis to build the new expression.
2240 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002241 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002242 ObjCPropertyDecl *Property,
2243 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002244 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002245 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002246 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2247 Sema::LookupMemberName);
2248 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002249 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002250 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002251 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002252 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002253 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002254
Douglas Gregore3303542010-04-26 20:47:02 +00002255 if (Result.get())
2256 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002257
John Wiegley429bb272011-04-08 18:41:53 +00002258 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002259 /*FIXME:*/PropertyLoc, IsArrow,
2260 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00002261 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002262 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002263 /*TemplateArgs=*/0);
2264 }
Sean Huntc3021132010-05-05 15:23:54 +00002265
John McCall12f78a62010-12-02 01:19:52 +00002266 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002267 ///
2268 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002269 /// Subclasses may override this routine to provide different behavior.
2270 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2271 ObjCMethodDecl *Getter,
2272 ObjCMethodDecl *Setter,
2273 SourceLocation PropertyLoc) {
2274 // Since these expressions can only be value-dependent, we do not
2275 // need to perform semantic analysis again.
2276 return Owned(
2277 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2278 VK_LValue, OK_ObjCProperty,
2279 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002280 }
2281
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002282 /// \brief Build a new Objective-C "isa" expression.
2283 ///
2284 /// By default, performs semantic analysis to build the new expression.
2285 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002286 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002287 bool IsArrow) {
2288 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002289 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002290 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2291 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002292 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002293 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002294 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002295 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002296 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002297
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002298 if (Result.get())
2299 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002300
John Wiegley429bb272011-04-08 18:41:53 +00002301 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002302 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002303 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002304 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002305 /*TemplateArgs=*/0);
2306 }
Sean Huntc3021132010-05-05 15:23:54 +00002307
Douglas Gregorb98b1992009-08-11 05:31:07 +00002308 /// \brief Build a new shuffle vector expression.
2309 ///
2310 /// By default, performs semantic analysis to build the new expression.
2311 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002312 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002313 MultiExprArg SubExprs,
2314 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002315 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002316 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002317 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2318 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2319 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2320 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002321
Douglas Gregorb98b1992009-08-11 05:31:07 +00002322 // Build a reference to the __builtin_shufflevector builtin
2323 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002324 ExprResult Callee
2325 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2326 VK_LValue, BuiltinLoc));
2327 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2328 if (Callee.isInvalid())
2329 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002330
2331 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002332 unsigned NumSubExprs = SubExprs.size();
2333 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002334 ExprResult TheCall = SemaRef.Owned(
2335 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002336 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002337 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002338 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002339 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002340
Douglas Gregorb98b1992009-08-11 05:31:07 +00002341 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002342 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002343 }
John McCall43fed0d2010-11-12 08:19:04 +00002344
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002345 /// \brief Build a new template argument pack expansion.
2346 ///
2347 /// By default, performs semantic analysis to build a new pack expansion
2348 /// for a template argument. Subclasses may override this routine to provide
2349 /// different behavior.
2350 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002351 SourceLocation EllipsisLoc,
2352 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002353 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002354 case TemplateArgument::Expression: {
2355 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002356 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2357 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002358 if (Result.isInvalid())
2359 return TemplateArgumentLoc();
2360
2361 return TemplateArgumentLoc(Result.get(), Result.get());
2362 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002363
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002364 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002365 return TemplateArgumentLoc(TemplateArgument(
2366 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002367 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002368 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002369 Pattern.getTemplateNameLoc(),
2370 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002371
2372 case TemplateArgument::Null:
2373 case TemplateArgument::Integral:
2374 case TemplateArgument::Declaration:
2375 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002376 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002377 llvm_unreachable("Pack expansion pattern has no parameter packs");
2378
2379 case TemplateArgument::Type:
2380 if (TypeSourceInfo *Expansion
2381 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002382 EllipsisLoc,
2383 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002384 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2385 Expansion);
2386 break;
2387 }
2388
2389 return TemplateArgumentLoc();
2390 }
2391
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002392 /// \brief Build a new expression pack expansion.
2393 ///
2394 /// By default, performs semantic analysis to build a new pack expansion
2395 /// for an expression. Subclasses may override this routine to provide
2396 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002397 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2398 llvm::Optional<unsigned> NumExpansions) {
2399 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002400 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002401
2402 /// \brief Build a new atomic operation expression.
2403 ///
2404 /// By default, performs semantic analysis to build the new expression.
2405 /// Subclasses may override this routine to provide different behavior.
2406 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2407 MultiExprArg SubExprs,
2408 QualType RetTy,
2409 AtomicExpr::AtomicOp Op,
2410 SourceLocation RParenLoc) {
2411 // Just create the expression; there is not any interesting semantic
2412 // analysis here because we can't actually build an AtomicExpr until
2413 // we are sure it is semantically sound.
2414 unsigned NumSubExprs = SubExprs.size();
2415 Expr **Subs = (Expr **)SubExprs.release();
2416 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2417 NumSubExprs, RetTy, Op,
2418 RParenLoc);
2419 }
2420
John McCall43fed0d2010-11-12 08:19:04 +00002421private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002422 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2423 QualType ObjectType,
2424 NamedDecl *FirstQualifierInScope,
2425 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002426
2427 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2428 QualType ObjectType,
2429 NamedDecl *FirstQualifierInScope,
2430 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002431};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002432
Douglas Gregor43959a92009-08-20 07:17:43 +00002433template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002434StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002435 if (!S)
2436 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002437
Douglas Gregor43959a92009-08-20 07:17:43 +00002438 switch (S->getStmtClass()) {
2439 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002440
Douglas Gregor43959a92009-08-20 07:17:43 +00002441 // Transform individual statement nodes
2442#define STMT(Node, Parent) \
2443 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002444#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002445#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002446#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002447
Douglas Gregor43959a92009-08-20 07:17:43 +00002448 // Transform expressions by calling TransformExpr.
2449#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002450#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002451#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002452#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002453 {
John McCall60d7b3a2010-08-24 06:29:42 +00002454 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002455 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002456 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002457
John McCall9ae2f072010-08-23 23:25:46 +00002458 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002459 }
Mike Stump1eb44332009-09-09 15:08:12 +00002460 }
2461
John McCall3fa5cae2010-10-26 07:05:15 +00002462 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002463}
Mike Stump1eb44332009-09-09 15:08:12 +00002464
2465
Douglas Gregor670444e2009-08-04 22:27:00 +00002466template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002467ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002468 if (!E)
2469 return SemaRef.Owned(E);
2470
2471 switch (E->getStmtClass()) {
2472 case Stmt::NoStmtClass: break;
2473#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002474#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002475#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002476 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002477#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002478 }
2479
John McCall3fa5cae2010-10-26 07:05:15 +00002480 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002481}
2482
2483template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002484bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2485 unsigned NumInputs,
2486 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002487 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002488 bool *ArgChanged) {
2489 for (unsigned I = 0; I != NumInputs; ++I) {
2490 // If requested, drop call arguments that need to be dropped.
2491 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2492 if (ArgChanged)
2493 *ArgChanged = true;
2494
2495 break;
2496 }
2497
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002498 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2499 Expr *Pattern = Expansion->getPattern();
2500
Chris Lattner686775d2011-07-20 06:58:45 +00002501 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002502 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2503 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2504
2505 // Determine whether the set of unexpanded parameter packs can and should
2506 // be expanded.
2507 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002508 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002509 llvm::Optional<unsigned> OrigNumExpansions
2510 = Expansion->getNumExpansions();
2511 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002512 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2513 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002514 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002515 Expand, RetainExpansion,
2516 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002517 return true;
2518
2519 if (!Expand) {
2520 // The transform has determined that we should perform a simple
2521 // transformation on the pack expansion, producing another pack
2522 // expansion.
2523 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2524 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2525 if (OutPattern.isInvalid())
2526 return true;
2527
2528 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002529 Expansion->getEllipsisLoc(),
2530 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002531 if (Out.isInvalid())
2532 return true;
2533
2534 if (ArgChanged)
2535 *ArgChanged = true;
2536 Outputs.push_back(Out.get());
2537 continue;
2538 }
John McCallc8fc90a2011-07-06 07:30:07 +00002539
2540 // Record right away that the argument was changed. This needs
2541 // to happen even if the array expands to nothing.
2542 if (ArgChanged) *ArgChanged = true;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002543
2544 // The transform has determined that we should perform an elementwise
2545 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002546 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002547 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2548 ExprResult Out = getDerived().TransformExpr(Pattern);
2549 if (Out.isInvalid())
2550 return true;
2551
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002552 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002553 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2554 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002555 if (Out.isInvalid())
2556 return true;
2557 }
2558
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002559 Outputs.push_back(Out.get());
2560 }
2561
2562 continue;
2563 }
2564
Douglas Gregoraa165f82011-01-03 19:04:46 +00002565 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2566 if (Result.isInvalid())
2567 return true;
2568
2569 if (Result.get() != Inputs[I] && ArgChanged)
2570 *ArgChanged = true;
2571
2572 Outputs.push_back(Result.get());
2573 }
2574
2575 return false;
2576}
2577
2578template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002579NestedNameSpecifierLoc
2580TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2581 NestedNameSpecifierLoc NNS,
2582 QualType ObjectType,
2583 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002584 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002585 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2586 Qualifier = Qualifier.getPrefix())
2587 Qualifiers.push_back(Qualifier);
2588
2589 CXXScopeSpec SS;
2590 while (!Qualifiers.empty()) {
2591 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2592 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2593
2594 switch (QNNS->getKind()) {
2595 case NestedNameSpecifier::Identifier:
2596 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2597 *QNNS->getAsIdentifier(),
2598 Q.getLocalBeginLoc(),
2599 Q.getLocalEndLoc(),
2600 ObjectType, false, SS,
2601 FirstQualifierInScope, false))
2602 return NestedNameSpecifierLoc();
2603
2604 break;
2605
2606 case NestedNameSpecifier::Namespace: {
2607 NamespaceDecl *NS
2608 = cast_or_null<NamespaceDecl>(
2609 getDerived().TransformDecl(
2610 Q.getLocalBeginLoc(),
2611 QNNS->getAsNamespace()));
2612 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2613 break;
2614 }
2615
2616 case NestedNameSpecifier::NamespaceAlias: {
2617 NamespaceAliasDecl *Alias
2618 = cast_or_null<NamespaceAliasDecl>(
2619 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2620 QNNS->getAsNamespaceAlias()));
2621 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2622 Q.getLocalEndLoc());
2623 break;
2624 }
2625
2626 case NestedNameSpecifier::Global:
2627 // There is no meaningful transformation that one could perform on the
2628 // global scope.
2629 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2630 break;
2631
2632 case NestedNameSpecifier::TypeSpecWithTemplate:
2633 case NestedNameSpecifier::TypeSpec: {
2634 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2635 FirstQualifierInScope, SS);
2636
2637 if (!TL)
2638 return NestedNameSpecifierLoc();
2639
2640 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2641 (SemaRef.getLangOptions().CPlusPlus0x &&
2642 TL.getType()->isEnumeralType())) {
2643 assert(!TL.getType().hasLocalQualifiers() &&
2644 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002645 if (TL.getType()->isEnumeralType())
2646 SemaRef.Diag(TL.getBeginLoc(),
2647 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002648 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2649 Q.getLocalEndLoc());
2650 break;
2651 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002652 // If the nested-name-specifier is an invalid type def, don't emit an
2653 // error because a previous error should have already been emitted.
2654 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2655 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2656 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2657 << TL.getType() << SS.getRange();
2658 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002659 return NestedNameSpecifierLoc();
2660 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002661 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002662
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002663 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002664 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002665 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002666 }
2667
2668 // Don't rebuild the nested-name-specifier if we don't have to.
2669 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2670 !getDerived().AlwaysRebuild())
2671 return NNS;
2672
2673 // If we can re-use the source-location data from the original
2674 // nested-name-specifier, do so.
2675 if (SS.location_size() == NNS.getDataLength() &&
2676 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2677 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2678
2679 // Allocate new nested-name-specifier location information.
2680 return SS.getWithLocInContext(SemaRef.Context);
2681}
2682
2683template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002684DeclarationNameInfo
2685TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002686::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002687 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002688 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002689 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002690
2691 switch (Name.getNameKind()) {
2692 case DeclarationName::Identifier:
2693 case DeclarationName::ObjCZeroArgSelector:
2694 case DeclarationName::ObjCOneArgSelector:
2695 case DeclarationName::ObjCMultiArgSelector:
2696 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002697 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002698 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002699 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002700
Douglas Gregor81499bb2009-09-03 22:13:48 +00002701 case DeclarationName::CXXConstructorName:
2702 case DeclarationName::CXXDestructorName:
2703 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002704 TypeSourceInfo *NewTInfo;
2705 CanQualType NewCanTy;
2706 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002707 NewTInfo = getDerived().TransformType(OldTInfo);
2708 if (!NewTInfo)
2709 return DeclarationNameInfo();
2710 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002711 }
2712 else {
2713 NewTInfo = 0;
2714 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002715 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002716 if (NewT.isNull())
2717 return DeclarationNameInfo();
2718 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2719 }
Mike Stump1eb44332009-09-09 15:08:12 +00002720
Abramo Bagnara25777432010-08-11 22:01:17 +00002721 DeclarationName NewName
2722 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2723 NewCanTy);
2724 DeclarationNameInfo NewNameInfo(NameInfo);
2725 NewNameInfo.setName(NewName);
2726 NewNameInfo.setNamedTypeInfo(NewTInfo);
2727 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002728 }
Mike Stump1eb44332009-09-09 15:08:12 +00002729 }
2730
David Blaikieb219cfc2011-09-23 05:06:16 +00002731 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002732}
2733
2734template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002735TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002736TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2737 TemplateName Name,
2738 SourceLocation NameLoc,
2739 QualType ObjectType,
2740 NamedDecl *FirstQualifierInScope) {
2741 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2742 TemplateDecl *Template = QTN->getTemplateDecl();
2743 assert(Template && "qualified template name must refer to a template");
2744
2745 TemplateDecl *TransTemplate
2746 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2747 Template));
2748 if (!TransTemplate)
2749 return TemplateName();
2750
2751 if (!getDerived().AlwaysRebuild() &&
2752 SS.getScopeRep() == QTN->getQualifier() &&
2753 TransTemplate == Template)
2754 return Name;
2755
2756 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2757 TransTemplate);
2758 }
2759
2760 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2761 if (SS.getScopeRep()) {
2762 // These apply to the scope specifier, not the template.
2763 ObjectType = QualType();
2764 FirstQualifierInScope = 0;
2765 }
2766
2767 if (!getDerived().AlwaysRebuild() &&
2768 SS.getScopeRep() == DTN->getQualifier() &&
2769 ObjectType.isNull())
2770 return Name;
2771
2772 if (DTN->isIdentifier()) {
2773 return getDerived().RebuildTemplateName(SS,
2774 *DTN->getIdentifier(),
2775 NameLoc,
2776 ObjectType,
2777 FirstQualifierInScope);
2778 }
2779
2780 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2781 ObjectType);
2782 }
2783
2784 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2785 TemplateDecl *TransTemplate
2786 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2787 Template));
2788 if (!TransTemplate)
2789 return TemplateName();
2790
2791 if (!getDerived().AlwaysRebuild() &&
2792 TransTemplate == Template)
2793 return Name;
2794
2795 return TemplateName(TransTemplate);
2796 }
2797
2798 if (SubstTemplateTemplateParmPackStorage *SubstPack
2799 = Name.getAsSubstTemplateTemplateParmPack()) {
2800 TemplateTemplateParmDecl *TransParam
2801 = cast_or_null<TemplateTemplateParmDecl>(
2802 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2803 if (!TransParam)
2804 return TemplateName();
2805
2806 if (!getDerived().AlwaysRebuild() &&
2807 TransParam == SubstPack->getParameterPack())
2808 return Name;
2809
2810 return getDerived().RebuildTemplateName(TransParam,
2811 SubstPack->getArgumentPack());
2812 }
2813
2814 // These should be getting filtered out before they reach the AST.
2815 llvm_unreachable("overloaded function decl survived to here");
2816 return TemplateName();
2817}
2818
2819template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002820void TreeTransform<Derived>::InventTemplateArgumentLoc(
2821 const TemplateArgument &Arg,
2822 TemplateArgumentLoc &Output) {
2823 SourceLocation Loc = getDerived().getBaseLocation();
2824 switch (Arg.getKind()) {
2825 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002826 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002827 break;
2828
2829 case TemplateArgument::Type:
2830 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002831 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002832
John McCall833ca992009-10-29 08:12:44 +00002833 break;
2834
Douglas Gregor788cd062009-11-11 01:00:40 +00002835 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002836 case TemplateArgument::TemplateExpansion: {
2837 NestedNameSpecifierLocBuilder Builder;
2838 TemplateName Template = Arg.getAsTemplate();
2839 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2840 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2841 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2842 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2843
2844 if (Arg.getKind() == TemplateArgument::Template)
2845 Output = TemplateArgumentLoc(Arg,
2846 Builder.getWithLocInContext(SemaRef.Context),
2847 Loc);
2848 else
2849 Output = TemplateArgumentLoc(Arg,
2850 Builder.getWithLocInContext(SemaRef.Context),
2851 Loc, Loc);
2852
Douglas Gregor788cd062009-11-11 01:00:40 +00002853 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002854 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002855
John McCall833ca992009-10-29 08:12:44 +00002856 case TemplateArgument::Expression:
2857 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2858 break;
2859
2860 case TemplateArgument::Declaration:
2861 case TemplateArgument::Integral:
2862 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002863 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002864 break;
2865 }
2866}
2867
2868template<typename Derived>
2869bool TreeTransform<Derived>::TransformTemplateArgument(
2870 const TemplateArgumentLoc &Input,
2871 TemplateArgumentLoc &Output) {
2872 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002873 switch (Arg.getKind()) {
2874 case TemplateArgument::Null:
2875 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002876 Output = Input;
2877 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002878
Douglas Gregor670444e2009-08-04 22:27:00 +00002879 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002880 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002881 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002882 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002883
2884 DI = getDerived().TransformType(DI);
2885 if (!DI) return true;
2886
2887 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2888 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002889 }
Mike Stump1eb44332009-09-09 15:08:12 +00002890
Douglas Gregor670444e2009-08-04 22:27:00 +00002891 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002892 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002893 DeclarationName Name;
2894 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2895 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002896 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002897 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002898 if (!D) return true;
2899
John McCall828bff22009-10-29 18:45:58 +00002900 Expr *SourceExpr = Input.getSourceDeclExpression();
2901 if (SourceExpr) {
2902 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00002903 Sema::ConstantEvaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002904 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002905 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002906 }
2907
2908 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002909 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002910 }
Mike Stump1eb44332009-09-09 15:08:12 +00002911
Douglas Gregor788cd062009-11-11 01:00:40 +00002912 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002913 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2914 if (QualifierLoc) {
2915 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2916 if (!QualifierLoc)
2917 return true;
2918 }
2919
Douglas Gregor1d752d72011-03-02 18:46:51 +00002920 CXXScopeSpec SS;
2921 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00002922 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00002923 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2924 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00002925 if (Template.isNull())
2926 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002927
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002928 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00002929 Input.getTemplateNameLoc());
2930 return false;
2931 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002932
2933 case TemplateArgument::TemplateExpansion:
2934 llvm_unreachable("Caller should expand pack expansions");
2935
Douglas Gregor670444e2009-08-04 22:27:00 +00002936 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00002937 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00002938 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00002939 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002940
John McCall833ca992009-10-29 08:12:44 +00002941 Expr *InputExpr = Input.getSourceExpression();
2942 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2943
Chris Lattner223de242011-04-25 20:37:58 +00002944 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall833ca992009-10-29 08:12:44 +00002945 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002946 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002947 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002948 }
Mike Stump1eb44332009-09-09 15:08:12 +00002949
Douglas Gregor670444e2009-08-04 22:27:00 +00002950 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00002951 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00002952 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002953 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002954 AEnd = Arg.pack_end();
2955 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002956
John McCall833ca992009-10-29 08:12:44 +00002957 // FIXME: preserve source information here when we start
2958 // caring about parameter packs.
2959
John McCall828bff22009-10-29 18:45:58 +00002960 TemplateArgumentLoc InputArg;
2961 TemplateArgumentLoc OutputArg;
2962 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2963 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002964 return true;
2965
John McCall828bff22009-10-29 18:45:58 +00002966 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002967 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002968
2969 TemplateArgument *TransformedArgsPtr
2970 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2971 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2972 TransformedArgsPtr);
2973 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2974 TransformedArgs.size()),
2975 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002976 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002977 }
2978 }
Mike Stump1eb44332009-09-09 15:08:12 +00002979
Douglas Gregor670444e2009-08-04 22:27:00 +00002980 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002981 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002982}
2983
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002984/// \brief Iterator adaptor that invents template argument location information
2985/// for each of the template arguments in its underlying iterator.
2986template<typename Derived, typename InputIterator>
2987class TemplateArgumentLocInventIterator {
2988 TreeTransform<Derived> &Self;
2989 InputIterator Iter;
2990
2991public:
2992 typedef TemplateArgumentLoc value_type;
2993 typedef TemplateArgumentLoc reference;
2994 typedef typename std::iterator_traits<InputIterator>::difference_type
2995 difference_type;
2996 typedef std::input_iterator_tag iterator_category;
2997
2998 class pointer {
2999 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003000
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003001 public:
3002 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3003
3004 const TemplateArgumentLoc *operator->() const { return &Arg; }
3005 };
3006
3007 TemplateArgumentLocInventIterator() { }
3008
3009 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3010 InputIterator Iter)
3011 : Self(Self), Iter(Iter) { }
3012
3013 TemplateArgumentLocInventIterator &operator++() {
3014 ++Iter;
3015 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003016 }
3017
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003018 TemplateArgumentLocInventIterator operator++(int) {
3019 TemplateArgumentLocInventIterator Old(*this);
3020 ++(*this);
3021 return Old;
3022 }
3023
3024 reference operator*() const {
3025 TemplateArgumentLoc Result;
3026 Self.InventTemplateArgumentLoc(*Iter, Result);
3027 return Result;
3028 }
3029
3030 pointer operator->() const { return pointer(**this); }
3031
3032 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3033 const TemplateArgumentLocInventIterator &Y) {
3034 return X.Iter == Y.Iter;
3035 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003036
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003037 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3038 const TemplateArgumentLocInventIterator &Y) {
3039 return X.Iter != Y.Iter;
3040 }
3041};
3042
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003043template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003044template<typename InputIterator>
3045bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3046 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003047 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003048 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003049 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003050 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003051
3052 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3053 // Unpack argument packs, which we translate them into separate
3054 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003055 // FIXME: We could do much better if we could guarantee that the
3056 // TemplateArgumentLocInfo for the pack expansion would be usable for
3057 // all of the template arguments in the argument pack.
3058 typedef TemplateArgumentLocInventIterator<Derived,
3059 TemplateArgument::pack_iterator>
3060 PackLocIterator;
3061 if (TransformTemplateArguments(PackLocIterator(*this,
3062 In.getArgument().pack_begin()),
3063 PackLocIterator(*this,
3064 In.getArgument().pack_end()),
3065 Outputs))
3066 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003067
3068 continue;
3069 }
3070
3071 if (In.getArgument().isPackExpansion()) {
3072 // We have a pack expansion, for which we will be substituting into
3073 // the pattern.
3074 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003075 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003076 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003077 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3078 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003079
Chris Lattner686775d2011-07-20 06:58:45 +00003080 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003081 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3082 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3083
3084 // Determine whether the set of unexpanded parameter packs can and should
3085 // be expanded.
3086 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003087 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003088 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003089 if (getDerived().TryExpandParameterPacks(Ellipsis,
3090 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003091 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003092 Expand,
3093 RetainExpansion,
3094 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003095 return true;
3096
3097 if (!Expand) {
3098 // The transform has determined that we should perform a simple
3099 // transformation on the pack expansion, producing another pack
3100 // expansion.
3101 TemplateArgumentLoc OutPattern;
3102 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3103 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3104 return true;
3105
Douglas Gregorcded4f62011-01-14 17:04:44 +00003106 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3107 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003108 if (Out.getArgument().isNull())
3109 return true;
3110
3111 Outputs.addArgument(Out);
3112 continue;
3113 }
3114
3115 // The transform has determined that we should perform an elementwise
3116 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003117 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003118 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3119
3120 if (getDerived().TransformTemplateArgument(Pattern, Out))
3121 return true;
3122
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003123 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003124 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3125 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003126 if (Out.getArgument().isNull())
3127 return true;
3128 }
3129
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003130 Outputs.addArgument(Out);
3131 }
3132
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003133 // If we're supposed to retain a pack expansion, do so by temporarily
3134 // forgetting the partially-substituted parameter pack.
3135 if (RetainExpansion) {
3136 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3137
3138 if (getDerived().TransformTemplateArgument(Pattern, Out))
3139 return true;
3140
Douglas Gregorcded4f62011-01-14 17:04:44 +00003141 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3142 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003143 if (Out.getArgument().isNull())
3144 return true;
3145
3146 Outputs.addArgument(Out);
3147 }
Douglas Gregord3731192011-01-10 07:32:04 +00003148
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003149 continue;
3150 }
3151
3152 // The simple case:
3153 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003154 return true;
3155
3156 Outputs.addArgument(Out);
3157 }
3158
3159 return false;
3160
3161}
3162
Douglas Gregor577f75a2009-08-04 16:50:30 +00003163//===----------------------------------------------------------------------===//
3164// Type transformation
3165//===----------------------------------------------------------------------===//
3166
3167template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003168QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003169 if (getDerived().AlreadyTransformed(T))
3170 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003171
John McCalla2becad2009-10-21 00:40:46 +00003172 // Temporary workaround. All of these transformations should
3173 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003174 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3175 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003176
John McCall43fed0d2010-11-12 08:19:04 +00003177 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003178
John McCalla2becad2009-10-21 00:40:46 +00003179 if (!NewDI)
3180 return QualType();
3181
3182 return NewDI->getType();
3183}
3184
3185template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003186TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003187 // Refine the base location to the type's location.
3188 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3189 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003190 if (getDerived().AlreadyTransformed(DI->getType()))
3191 return DI;
3192
3193 TypeLocBuilder TLB;
3194
3195 TypeLoc TL = DI->getTypeLoc();
3196 TLB.reserve(TL.getFullDataSize());
3197
John McCall43fed0d2010-11-12 08:19:04 +00003198 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003199 if (Result.isNull())
3200 return 0;
3201
John McCalla93c9342009-12-07 02:54:59 +00003202 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003203}
3204
3205template<typename Derived>
3206QualType
John McCall43fed0d2010-11-12 08:19:04 +00003207TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003208 switch (T.getTypeLocClass()) {
3209#define ABSTRACT_TYPELOC(CLASS, PARENT)
3210#define TYPELOC(CLASS, PARENT) \
3211 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003212 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003213#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003214 }
Mike Stump1eb44332009-09-09 15:08:12 +00003215
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003216 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003217 return QualType();
3218}
3219
3220/// FIXME: By default, this routine adds type qualifiers only to types
3221/// that can have qualifiers, and silently suppresses those qualifiers
3222/// that are not permitted (e.g., qualifiers on reference or function
3223/// types). This is the right thing for template instantiation, but
3224/// probably not for other clients.
3225template<typename Derived>
3226QualType
3227TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003228 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003229 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003230
John McCall43fed0d2010-11-12 08:19:04 +00003231 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003232 if (Result.isNull())
3233 return QualType();
3234
3235 // Silently suppress qualifiers if the result type can't be qualified.
3236 // FIXME: this is the right thing for template instantiation, but
3237 // probably not for other clients.
3238 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003239 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003240
John McCallf85e1932011-06-15 23:02:42 +00003241 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003242 // resulting type.
3243 if (Quals.hasObjCLifetime()) {
3244 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3245 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003246 else if (Result.getObjCLifetime()) {
Douglas Gregore559ca12011-06-17 22:11:49 +00003247 // Objective-C ARC:
3248 // A lifetime qualifier applied to a substituted template parameter
3249 // overrides the lifetime qualifier from the template argument.
3250 if (const SubstTemplateTypeParmType *SubstTypeParam
3251 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3252 QualType Replacement = SubstTypeParam->getReplacementType();
3253 Qualifiers Qs = Replacement.getQualifiers();
3254 Qs.removeObjCLifetime();
3255 Replacement
3256 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3257 Qs);
3258 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3259 SubstTypeParam->getReplacedParameter(),
3260 Replacement);
3261 TLB.TypeWasModifiedSafely(Result);
3262 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003263 // Otherwise, complain about the addition of a qualifier to an
3264 // already-qualified type.
3265 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003266 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003267 << Result << R;
3268
Douglas Gregore559ca12011-06-17 22:11:49 +00003269 Quals.removeObjCLifetime();
3270 }
3271 }
3272 }
John McCall28654742010-06-05 06:41:15 +00003273 if (!Quals.empty()) {
3274 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3275 TLB.push<QualifiedTypeLoc>(Result);
3276 // No location information to preserve.
3277 }
John McCalla2becad2009-10-21 00:40:46 +00003278
3279 return Result;
3280}
3281
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003282template<typename Derived>
3283TypeLoc
3284TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3285 QualType ObjectType,
3286 NamedDecl *UnqualLookup,
3287 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003288 QualType T = TL.getType();
3289 if (getDerived().AlreadyTransformed(T))
3290 return TL;
3291
3292 TypeLocBuilder TLB;
3293 QualType Result;
3294
3295 if (isa<TemplateSpecializationType>(T)) {
3296 TemplateSpecializationTypeLoc SpecTL
3297 = cast<TemplateSpecializationTypeLoc>(TL);
3298
3299 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003300 getDerived().TransformTemplateName(SS,
3301 SpecTL.getTypePtr()->getTemplateName(),
3302 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003303 ObjectType, UnqualLookup);
3304 if (Template.isNull())
3305 return TypeLoc();
3306
3307 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3308 Template);
3309 } else if (isa<DependentTemplateSpecializationType>(T)) {
3310 DependentTemplateSpecializationTypeLoc SpecTL
3311 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3312
Douglas Gregora88f09f2011-02-28 17:23:35 +00003313 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003314 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003315 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003316 SpecTL.getNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003317 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003318 if (Template.isNull())
3319 return TypeLoc();
3320
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003321 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003322 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003323 Template,
3324 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003325 } else {
3326 // Nothing special needs to be done for these.
3327 Result = getDerived().TransformType(TLB, TL);
3328 }
3329
3330 if (Result.isNull())
3331 return TypeLoc();
3332
3333 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3334}
3335
Douglas Gregorb71d8212011-03-02 18:32:08 +00003336template<typename Derived>
3337TypeSourceInfo *
3338TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3339 QualType ObjectType,
3340 NamedDecl *UnqualLookup,
3341 CXXScopeSpec &SS) {
3342 // FIXME: Painfully copy-paste from the above!
3343
3344 QualType T = TSInfo->getType();
3345 if (getDerived().AlreadyTransformed(T))
3346 return TSInfo;
3347
3348 TypeLocBuilder TLB;
3349 QualType Result;
3350
3351 TypeLoc TL = TSInfo->getTypeLoc();
3352 if (isa<TemplateSpecializationType>(T)) {
3353 TemplateSpecializationTypeLoc SpecTL
3354 = cast<TemplateSpecializationTypeLoc>(TL);
3355
3356 TemplateName Template
3357 = getDerived().TransformTemplateName(SS,
3358 SpecTL.getTypePtr()->getTemplateName(),
3359 SpecTL.getTemplateNameLoc(),
3360 ObjectType, UnqualLookup);
3361 if (Template.isNull())
3362 return 0;
3363
3364 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3365 Template);
3366 } else if (isa<DependentTemplateSpecializationType>(T)) {
3367 DependentTemplateSpecializationTypeLoc SpecTL
3368 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3369
3370 TemplateName Template
3371 = getDerived().RebuildTemplateName(SS,
3372 *SpecTL.getTypePtr()->getIdentifier(),
3373 SpecTL.getNameLoc(),
3374 ObjectType, UnqualLookup);
3375 if (Template.isNull())
3376 return 0;
3377
3378 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3379 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003380 Template,
3381 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003382 } else {
3383 // Nothing special needs to be done for these.
3384 Result = getDerived().TransformType(TLB, TL);
3385 }
3386
3387 if (Result.isNull())
3388 return 0;
3389
3390 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3391}
3392
John McCalla2becad2009-10-21 00:40:46 +00003393template <class TyLoc> static inline
3394QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3395 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3396 NewT.setNameLoc(T.getNameLoc());
3397 return T.getType();
3398}
3399
John McCalla2becad2009-10-21 00:40:46 +00003400template<typename Derived>
3401QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003402 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003403 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3404 NewT.setBuiltinLoc(T.getBuiltinLoc());
3405 if (T.needsExtraLocalData())
3406 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3407 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003408}
Mike Stump1eb44332009-09-09 15:08:12 +00003409
Douglas Gregor577f75a2009-08-04 16:50:30 +00003410template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003411QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003412 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003413 // FIXME: recurse?
3414 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003415}
Mike Stump1eb44332009-09-09 15:08:12 +00003416
Douglas Gregor577f75a2009-08-04 16:50:30 +00003417template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003418QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003419 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003420 QualType PointeeType
3421 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003422 if (PointeeType.isNull())
3423 return QualType();
3424
3425 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003426 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003427 // A dependent pointer type 'T *' has is being transformed such
3428 // that an Objective-C class type is being replaced for 'T'. The
3429 // resulting pointer type is an ObjCObjectPointerType, not a
3430 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003431 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003432
John McCallc12c5bb2010-05-15 11:32:37 +00003433 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3434 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003435 return Result;
3436 }
John McCall43fed0d2010-11-12 08:19:04 +00003437
Douglas Gregor92e986e2010-04-22 16:44:27 +00003438 if (getDerived().AlwaysRebuild() ||
3439 PointeeType != TL.getPointeeLoc().getType()) {
3440 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3441 if (Result.isNull())
3442 return QualType();
3443 }
John McCallf85e1932011-06-15 23:02:42 +00003444
3445 // Objective-C ARC can add lifetime qualifiers to the type that we're
3446 // pointing to.
3447 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3448
Douglas Gregor92e986e2010-04-22 16:44:27 +00003449 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3450 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003451 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003452}
Mike Stump1eb44332009-09-09 15:08:12 +00003453
3454template<typename Derived>
3455QualType
John McCalla2becad2009-10-21 00:40:46 +00003456TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003457 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003458 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003459 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3460 if (PointeeType.isNull())
3461 return QualType();
3462
3463 QualType Result = TL.getType();
3464 if (getDerived().AlwaysRebuild() ||
3465 PointeeType != TL.getPointeeLoc().getType()) {
3466 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003467 TL.getSigilLoc());
3468 if (Result.isNull())
3469 return QualType();
3470 }
3471
Douglas Gregor39968ad2010-04-22 16:50:51 +00003472 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003473 NewT.setSigilLoc(TL.getSigilLoc());
3474 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003475}
3476
John McCall85737a72009-10-30 00:06:24 +00003477/// Transforms a reference type. Note that somewhat paradoxically we
3478/// don't care whether the type itself is an l-value type or an r-value
3479/// type; we only care if the type was *written* as an l-value type
3480/// or an r-value type.
3481template<typename Derived>
3482QualType
3483TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003484 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003485 const ReferenceType *T = TL.getTypePtr();
3486
3487 // Note that this works with the pointee-as-written.
3488 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3489 if (PointeeType.isNull())
3490 return QualType();
3491
3492 QualType Result = TL.getType();
3493 if (getDerived().AlwaysRebuild() ||
3494 PointeeType != T->getPointeeTypeAsWritten()) {
3495 Result = getDerived().RebuildReferenceType(PointeeType,
3496 T->isSpelledAsLValue(),
3497 TL.getSigilLoc());
3498 if (Result.isNull())
3499 return QualType();
3500 }
3501
John McCallf85e1932011-06-15 23:02:42 +00003502 // Objective-C ARC can add lifetime qualifiers to the type that we're
3503 // referring to.
3504 TLB.TypeWasModifiedSafely(
3505 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3506
John McCall85737a72009-10-30 00:06:24 +00003507 // r-value references can be rebuilt as l-value references.
3508 ReferenceTypeLoc NewTL;
3509 if (isa<LValueReferenceType>(Result))
3510 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3511 else
3512 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3513 NewTL.setSigilLoc(TL.getSigilLoc());
3514
3515 return Result;
3516}
3517
Mike Stump1eb44332009-09-09 15:08:12 +00003518template<typename Derived>
3519QualType
John McCalla2becad2009-10-21 00:40:46 +00003520TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003521 LValueReferenceTypeLoc TL) {
3522 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003523}
3524
Mike Stump1eb44332009-09-09 15:08:12 +00003525template<typename Derived>
3526QualType
John McCalla2becad2009-10-21 00:40:46 +00003527TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003528 RValueReferenceTypeLoc TL) {
3529 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003530}
Mike Stump1eb44332009-09-09 15:08:12 +00003531
Douglas Gregor577f75a2009-08-04 16:50:30 +00003532template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003533QualType
John McCalla2becad2009-10-21 00:40:46 +00003534TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003535 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003536 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003537 if (PointeeType.isNull())
3538 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003539
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003540 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3541 TypeSourceInfo* NewClsTInfo = 0;
3542 if (OldClsTInfo) {
3543 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3544 if (!NewClsTInfo)
3545 return QualType();
3546 }
3547
3548 const MemberPointerType *T = TL.getTypePtr();
3549 QualType OldClsType = QualType(T->getClass(), 0);
3550 QualType NewClsType;
3551 if (NewClsTInfo)
3552 NewClsType = NewClsTInfo->getType();
3553 else {
3554 NewClsType = getDerived().TransformType(OldClsType);
3555 if (NewClsType.isNull())
3556 return QualType();
3557 }
Mike Stump1eb44332009-09-09 15:08:12 +00003558
John McCalla2becad2009-10-21 00:40:46 +00003559 QualType Result = TL.getType();
3560 if (getDerived().AlwaysRebuild() ||
3561 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003562 NewClsType != OldClsType) {
3563 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003564 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003565 if (Result.isNull())
3566 return QualType();
3567 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003568
John McCalla2becad2009-10-21 00:40:46 +00003569 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3570 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003571 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003572
3573 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003574}
3575
Mike Stump1eb44332009-09-09 15:08:12 +00003576template<typename Derived>
3577QualType
John McCalla2becad2009-10-21 00:40:46 +00003578TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003579 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003580 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003581 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003582 if (ElementType.isNull())
3583 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003584
John McCalla2becad2009-10-21 00:40:46 +00003585 QualType Result = TL.getType();
3586 if (getDerived().AlwaysRebuild() ||
3587 ElementType != T->getElementType()) {
3588 Result = getDerived().RebuildConstantArrayType(ElementType,
3589 T->getSizeModifier(),
3590 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003591 T->getIndexTypeCVRQualifiers(),
3592 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003593 if (Result.isNull())
3594 return QualType();
3595 }
Sean Huntc3021132010-05-05 15:23:54 +00003596
John McCalla2becad2009-10-21 00:40:46 +00003597 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3598 NewTL.setLBracketLoc(TL.getLBracketLoc());
3599 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003600
John McCalla2becad2009-10-21 00:40:46 +00003601 Expr *Size = TL.getSizeExpr();
3602 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003603 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3604 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003605 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3606 }
3607 NewTL.setSizeExpr(Size);
3608
3609 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003610}
Mike Stump1eb44332009-09-09 15:08:12 +00003611
Douglas Gregor577f75a2009-08-04 16:50:30 +00003612template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003613QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003614 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003615 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003616 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003617 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003618 if (ElementType.isNull())
3619 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003620
John McCalla2becad2009-10-21 00:40:46 +00003621 QualType Result = TL.getType();
3622 if (getDerived().AlwaysRebuild() ||
3623 ElementType != T->getElementType()) {
3624 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003625 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003626 T->getIndexTypeCVRQualifiers(),
3627 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003628 if (Result.isNull())
3629 return QualType();
3630 }
Sean Huntc3021132010-05-05 15:23:54 +00003631
John McCalla2becad2009-10-21 00:40:46 +00003632 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3633 NewTL.setLBracketLoc(TL.getLBracketLoc());
3634 NewTL.setRBracketLoc(TL.getRBracketLoc());
3635 NewTL.setSizeExpr(0);
3636
3637 return Result;
3638}
3639
3640template<typename Derived>
3641QualType
3642TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003643 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003644 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003645 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3646 if (ElementType.isNull())
3647 return QualType();
3648
John McCall60d7b3a2010-08-24 06:29:42 +00003649 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003650 = getDerived().TransformExpr(T->getSizeExpr());
3651 if (SizeResult.isInvalid())
3652 return QualType();
3653
John McCall9ae2f072010-08-23 23:25:46 +00003654 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003655
3656 QualType Result = TL.getType();
3657 if (getDerived().AlwaysRebuild() ||
3658 ElementType != T->getElementType() ||
3659 Size != T->getSizeExpr()) {
3660 Result = getDerived().RebuildVariableArrayType(ElementType,
3661 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003662 Size,
John McCalla2becad2009-10-21 00:40:46 +00003663 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003664 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003665 if (Result.isNull())
3666 return QualType();
3667 }
Sean Huntc3021132010-05-05 15:23:54 +00003668
John McCalla2becad2009-10-21 00:40:46 +00003669 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3670 NewTL.setLBracketLoc(TL.getLBracketLoc());
3671 NewTL.setRBracketLoc(TL.getRBracketLoc());
3672 NewTL.setSizeExpr(Size);
3673
3674 return Result;
3675}
3676
3677template<typename Derived>
3678QualType
3679TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003680 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003681 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003682 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3683 if (ElementType.isNull())
3684 return QualType();
3685
Richard Smithf6702a32011-12-20 02:08:33 +00003686 // Array bounds are constant expressions.
3687 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3688 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003689
John McCall3b657512011-01-19 10:06:00 +00003690 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3691 Expr *origSize = TL.getSizeExpr();
3692 if (!origSize) origSize = T->getSizeExpr();
3693
3694 ExprResult sizeResult
3695 = getDerived().TransformExpr(origSize);
3696 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003697 return QualType();
3698
John McCall3b657512011-01-19 10:06:00 +00003699 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003700
3701 QualType Result = TL.getType();
3702 if (getDerived().AlwaysRebuild() ||
3703 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003704 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003705 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3706 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003707 size,
John McCalla2becad2009-10-21 00:40:46 +00003708 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003709 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003710 if (Result.isNull())
3711 return QualType();
3712 }
John McCalla2becad2009-10-21 00:40:46 +00003713
3714 // We might have any sort of array type now, but fortunately they
3715 // all have the same location layout.
3716 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3717 NewTL.setLBracketLoc(TL.getLBracketLoc());
3718 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003719 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003720
3721 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003722}
Mike Stump1eb44332009-09-09 15:08:12 +00003723
3724template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003725QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003726 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003727 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003728 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003729
3730 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003731 QualType ElementType = getDerived().TransformType(T->getElementType());
3732 if (ElementType.isNull())
3733 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003734
Richard Smithf6702a32011-12-20 02:08:33 +00003735 // Vector sizes are constant expressions.
3736 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3737 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003738
John McCall60d7b3a2010-08-24 06:29:42 +00003739 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003740 if (Size.isInvalid())
3741 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003742
John McCalla2becad2009-10-21 00:40:46 +00003743 QualType Result = TL.getType();
3744 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003745 ElementType != T->getElementType() ||
3746 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003747 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003748 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003749 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003750 if (Result.isNull())
3751 return QualType();
3752 }
John McCalla2becad2009-10-21 00:40:46 +00003753
3754 // Result might be dependent or not.
3755 if (isa<DependentSizedExtVectorType>(Result)) {
3756 DependentSizedExtVectorTypeLoc NewTL
3757 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3758 NewTL.setNameLoc(TL.getNameLoc());
3759 } else {
3760 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3761 NewTL.setNameLoc(TL.getNameLoc());
3762 }
3763
3764 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003765}
Mike Stump1eb44332009-09-09 15:08:12 +00003766
3767template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003768QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003769 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003770 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003771 QualType ElementType = getDerived().TransformType(T->getElementType());
3772 if (ElementType.isNull())
3773 return QualType();
3774
John McCalla2becad2009-10-21 00:40:46 +00003775 QualType Result = TL.getType();
3776 if (getDerived().AlwaysRebuild() ||
3777 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003778 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003779 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003780 if (Result.isNull())
3781 return QualType();
3782 }
Sean Huntc3021132010-05-05 15:23:54 +00003783
John McCalla2becad2009-10-21 00:40:46 +00003784 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3785 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003786
John McCalla2becad2009-10-21 00:40:46 +00003787 return Result;
3788}
3789
3790template<typename Derived>
3791QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003792 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003793 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003794 QualType ElementType = getDerived().TransformType(T->getElementType());
3795 if (ElementType.isNull())
3796 return QualType();
3797
3798 QualType Result = TL.getType();
3799 if (getDerived().AlwaysRebuild() ||
3800 ElementType != T->getElementType()) {
3801 Result = getDerived().RebuildExtVectorType(ElementType,
3802 T->getNumElements(),
3803 /*FIXME*/ SourceLocation());
3804 if (Result.isNull())
3805 return QualType();
3806 }
Sean Huntc3021132010-05-05 15:23:54 +00003807
John McCalla2becad2009-10-21 00:40:46 +00003808 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3809 NewTL.setNameLoc(TL.getNameLoc());
3810
3811 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003812}
Mike Stump1eb44332009-09-09 15:08:12 +00003813
3814template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003815ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003816TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003817 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003818 llvm::Optional<unsigned> NumExpansions,
3819 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003820 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003821 TypeSourceInfo *NewDI = 0;
3822
3823 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3824 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003825 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003826 TypeLoc OldTL = OldDI->getTypeLoc();
3827 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3828
3829 TypeLocBuilder TLB;
3830 TypeLoc NewTL = OldDI->getTypeLoc();
3831 TLB.reserve(NewTL.getFullDataSize());
3832
3833 QualType Result = getDerived().TransformType(TLB,
3834 OldExpansionTL.getPatternLoc());
3835 if (Result.isNull())
3836 return 0;
3837
3838 Result = RebuildPackExpansionType(Result,
3839 OldExpansionTL.getPatternLoc().getSourceRange(),
3840 OldExpansionTL.getEllipsisLoc(),
3841 NumExpansions);
3842 if (Result.isNull())
3843 return 0;
3844
3845 PackExpansionTypeLoc NewExpansionTL
3846 = TLB.push<PackExpansionTypeLoc>(Result);
3847 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3848 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3849 } else
3850 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003851 if (!NewDI)
3852 return 0;
3853
John McCallfb44de92011-05-01 22:35:37 +00003854 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003855 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003856
3857 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3858 OldParm->getDeclContext(),
3859 OldParm->getInnerLocStart(),
3860 OldParm->getLocation(),
3861 OldParm->getIdentifier(),
3862 NewDI->getType(),
3863 NewDI,
3864 OldParm->getStorageClass(),
3865 OldParm->getStorageClassAsWritten(),
3866 /* DefArg */ NULL);
3867 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3868 OldParm->getFunctionScopeIndex() + indexAdjustment);
3869 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003870}
3871
3872template<typename Derived>
3873bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003874 TransformFunctionTypeParams(SourceLocation Loc,
3875 ParmVarDecl **Params, unsigned NumParams,
3876 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003877 SmallVectorImpl<QualType> &OutParamTypes,
3878 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003879 int indexAdjustment = 0;
3880
Douglas Gregora009b592011-01-07 00:20:55 +00003881 for (unsigned i = 0; i != NumParams; ++i) {
3882 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003883 assert(OldParm->getFunctionScopeIndex() == i);
3884
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003885 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003886 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003887 if (OldParm->isParameterPack()) {
3888 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003889 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003890
Douglas Gregor603cfb42011-01-05 23:12:31 +00003891 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003892 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3893 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3894 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3895 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003896 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3897
Douglas Gregor603cfb42011-01-05 23:12:31 +00003898 // Determine whether we should expand the parameter packs.
3899 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003900 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003901 llvm::Optional<unsigned> OrigNumExpansions
3902 = ExpansionTL.getTypePtr()->getNumExpansions();
3903 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003904 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3905 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003906 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003907 ShouldExpand,
3908 RetainExpansion,
3909 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003910 return true;
3911 }
3912
3913 if (ShouldExpand) {
3914 // Expand the function parameter pack into multiple, separate
3915 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003916 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003917 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003918 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3919 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003920 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003921 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003922 OrigNumExpansions,
3923 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003924 if (!NewParm)
3925 return true;
3926
Douglas Gregora009b592011-01-07 00:20:55 +00003927 OutParamTypes.push_back(NewParm->getType());
3928 if (PVars)
3929 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003930 }
Douglas Gregord3731192011-01-10 07:32:04 +00003931
3932 // If we're supposed to retain a pack expansion, do so by temporarily
3933 // forgetting the partially-substituted parameter pack.
3934 if (RetainExpansion) {
3935 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3936 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003937 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003938 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003939 OrigNumExpansions,
3940 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00003941 if (!NewParm)
3942 return true;
3943
3944 OutParamTypes.push_back(NewParm->getType());
3945 if (PVars)
3946 PVars->push_back(NewParm);
3947 }
3948
John McCallfb44de92011-05-01 22:35:37 +00003949 // The next parameter should have the same adjustment as the
3950 // last thing we pushed, but we post-incremented indexAdjustment
3951 // on every push. Also, if we push nothing, the adjustment should
3952 // go down by one.
3953 indexAdjustment--;
3954
Douglas Gregor603cfb42011-01-05 23:12:31 +00003955 // We're done with the pack expansion.
3956 continue;
3957 }
3958
3959 // We'll substitute the parameter now without expanding the pack
3960 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00003961 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3962 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003963 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003964 NumExpansions,
3965 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003966 } else {
3967 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003968 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003969 llvm::Optional<unsigned>(),
3970 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003971 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00003972
John McCall21ef0fa2010-03-11 09:03:00 +00003973 if (!NewParm)
3974 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003975
Douglas Gregora009b592011-01-07 00:20:55 +00003976 OutParamTypes.push_back(NewParm->getType());
3977 if (PVars)
3978 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003979 continue;
3980 }
John McCall21ef0fa2010-03-11 09:03:00 +00003981
3982 // Deal with the possibility that we don't have a parameter
3983 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00003984 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00003985 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003986 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003987 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003988 if (const PackExpansionType *Expansion
3989 = dyn_cast<PackExpansionType>(OldType)) {
3990 // We have a function parameter pack that may need to be expanded.
3991 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00003992 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003993 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3994
3995 // Determine whether we should expand the parameter packs.
3996 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003997 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00003998 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003999 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00004000 ShouldExpand,
4001 RetainExpansion,
4002 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004003 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004004 }
4005
4006 if (ShouldExpand) {
4007 // Expand the function parameter pack into multiple, separate
4008 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004009 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004010 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4011 QualType NewType = getDerived().TransformType(Pattern);
4012 if (NewType.isNull())
4013 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004014
Douglas Gregora009b592011-01-07 00:20:55 +00004015 OutParamTypes.push_back(NewType);
4016 if (PVars)
4017 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004018 }
4019
4020 // We're done with the pack expansion.
4021 continue;
4022 }
4023
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004024 // If we're supposed to retain a pack expansion, do so by temporarily
4025 // forgetting the partially-substituted parameter pack.
4026 if (RetainExpansion) {
4027 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4028 QualType NewType = getDerived().TransformType(Pattern);
4029 if (NewType.isNull())
4030 return true;
4031
4032 OutParamTypes.push_back(NewType);
4033 if (PVars)
4034 PVars->push_back(0);
4035 }
Douglas Gregord3731192011-01-10 07:32:04 +00004036
Douglas Gregor603cfb42011-01-05 23:12:31 +00004037 // We'll substitute the parameter now without expanding the pack
4038 // expansion.
4039 OldType = Expansion->getPattern();
4040 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004041 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4042 NewType = getDerived().TransformType(OldType);
4043 } else {
4044 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004045 }
4046
Douglas Gregor603cfb42011-01-05 23:12:31 +00004047 if (NewType.isNull())
4048 return true;
4049
4050 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004051 NewType = getSema().Context.getPackExpansionType(NewType,
4052 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004053
Douglas Gregora009b592011-01-07 00:20:55 +00004054 OutParamTypes.push_back(NewType);
4055 if (PVars)
4056 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004057 }
4058
John McCallfb44de92011-05-01 22:35:37 +00004059#ifndef NDEBUG
4060 if (PVars) {
4061 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4062 if (ParmVarDecl *parm = (*PVars)[i])
4063 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004064 }
John McCallfb44de92011-05-01 22:35:37 +00004065#endif
4066
4067 return false;
4068}
John McCall21ef0fa2010-03-11 09:03:00 +00004069
4070template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004071QualType
John McCalla2becad2009-10-21 00:40:46 +00004072TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004073 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004074 // Transform the parameters and return type.
4075 //
4076 // We instantiate in source order, with the return type first followed by
4077 // the parameters, because users tend to expect this (even if they shouldn't
4078 // rely on it!).
4079 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00004080 // When the function has a trailing return type, we instantiate the
4081 // parameters before the return type, since the return type can then refer
4082 // to the parameters themselves (via decltype, sizeof, etc.).
4083 //
Chris Lattner686775d2011-07-20 06:58:45 +00004084 SmallVector<QualType, 4> ParamTypes;
4085 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004086 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004087
Douglas Gregordab60ad2010-10-01 18:44:50 +00004088 QualType ResultType;
4089
4090 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00004091 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4092 TL.getParmArray(),
4093 TL.getNumArgs(),
4094 TL.getTypePtr()->arg_type_begin(),
4095 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004096 return QualType();
4097
4098 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4099 if (ResultType.isNull())
4100 return QualType();
4101 }
4102 else {
4103 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4104 if (ResultType.isNull())
4105 return QualType();
4106
Douglas Gregora009b592011-01-07 00:20:55 +00004107 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4108 TL.getParmArray(),
4109 TL.getNumArgs(),
4110 TL.getTypePtr()->arg_type_begin(),
4111 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004112 return QualType();
4113 }
4114
John McCalla2becad2009-10-21 00:40:46 +00004115 QualType Result = TL.getType();
4116 if (getDerived().AlwaysRebuild() ||
4117 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004118 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004119 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4120 Result = getDerived().RebuildFunctionProtoType(ResultType,
4121 ParamTypes.data(),
4122 ParamTypes.size(),
4123 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004124 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004125 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004126 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004127 if (Result.isNull())
4128 return QualType();
4129 }
Mike Stump1eb44332009-09-09 15:08:12 +00004130
John McCalla2becad2009-10-21 00:40:46 +00004131 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004132 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4133 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004134 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004135 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4136 NewTL.setArg(i, ParamDecls[i]);
4137
4138 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004139}
Mike Stump1eb44332009-09-09 15:08:12 +00004140
Douglas Gregor577f75a2009-08-04 16:50:30 +00004141template<typename Derived>
4142QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004143 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004144 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004145 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004146 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4147 if (ResultType.isNull())
4148 return QualType();
4149
4150 QualType Result = TL.getType();
4151 if (getDerived().AlwaysRebuild() ||
4152 ResultType != T->getResultType())
4153 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4154
4155 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004156 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4157 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004158 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004159
4160 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004161}
Mike Stump1eb44332009-09-09 15:08:12 +00004162
John McCalled976492009-12-04 22:46:56 +00004163template<typename Derived> QualType
4164TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004165 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004166 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004167 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004168 if (!D)
4169 return QualType();
4170
4171 QualType Result = TL.getType();
4172 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4173 Result = getDerived().RebuildUnresolvedUsingType(D);
4174 if (Result.isNull())
4175 return QualType();
4176 }
4177
4178 // We might get an arbitrary type spec type back. We should at
4179 // least always get a type spec type, though.
4180 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4181 NewTL.setNameLoc(TL.getNameLoc());
4182
4183 return Result;
4184}
4185
Douglas Gregor577f75a2009-08-04 16:50:30 +00004186template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004187QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004188 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004189 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004190 TypedefNameDecl *Typedef
4191 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4192 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004193 if (!Typedef)
4194 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004195
John McCalla2becad2009-10-21 00:40:46 +00004196 QualType Result = TL.getType();
4197 if (getDerived().AlwaysRebuild() ||
4198 Typedef != T->getDecl()) {
4199 Result = getDerived().RebuildTypedefType(Typedef);
4200 if (Result.isNull())
4201 return QualType();
4202 }
Mike Stump1eb44332009-09-09 15:08:12 +00004203
John McCalla2becad2009-10-21 00:40:46 +00004204 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4205 NewTL.setNameLoc(TL.getNameLoc());
4206
4207 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004208}
Mike Stump1eb44332009-09-09 15:08:12 +00004209
Douglas Gregor577f75a2009-08-04 16:50:30 +00004210template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004211QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004212 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004213 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004214 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004215
John McCall60d7b3a2010-08-24 06:29:42 +00004216 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004217 if (E.isInvalid())
4218 return QualType();
4219
John McCalla2becad2009-10-21 00:40:46 +00004220 QualType Result = TL.getType();
4221 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004222 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004223 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004224 if (Result.isNull())
4225 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004226 }
John McCalla2becad2009-10-21 00:40:46 +00004227 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004228
John McCalla2becad2009-10-21 00:40:46 +00004229 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004230 NewTL.setTypeofLoc(TL.getTypeofLoc());
4231 NewTL.setLParenLoc(TL.getLParenLoc());
4232 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004233
4234 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004235}
Mike Stump1eb44332009-09-09 15:08:12 +00004236
4237template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004238QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004239 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004240 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4241 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4242 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004243 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004244
John McCalla2becad2009-10-21 00:40:46 +00004245 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004246 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4247 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004248 if (Result.isNull())
4249 return QualType();
4250 }
Mike Stump1eb44332009-09-09 15:08:12 +00004251
John McCalla2becad2009-10-21 00:40:46 +00004252 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004253 NewTL.setTypeofLoc(TL.getTypeofLoc());
4254 NewTL.setLParenLoc(TL.getLParenLoc());
4255 NewTL.setRParenLoc(TL.getRParenLoc());
4256 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004257
4258 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004259}
Mike Stump1eb44332009-09-09 15:08:12 +00004260
4261template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004262QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004263 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004264 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004265
Douglas Gregor670444e2009-08-04 22:27:00 +00004266 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004267 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004268
John McCall60d7b3a2010-08-24 06:29:42 +00004269 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004270 if (E.isInvalid())
4271 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004272
John McCalla2becad2009-10-21 00:40:46 +00004273 QualType Result = TL.getType();
4274 if (getDerived().AlwaysRebuild() ||
4275 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004276 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004277 if (Result.isNull())
4278 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004279 }
John McCalla2becad2009-10-21 00:40:46 +00004280 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004281
John McCalla2becad2009-10-21 00:40:46 +00004282 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4283 NewTL.setNameLoc(TL.getNameLoc());
4284
4285 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004286}
4287
4288template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004289QualType TreeTransform<Derived>::TransformUnaryTransformType(
4290 TypeLocBuilder &TLB,
4291 UnaryTransformTypeLoc TL) {
4292 QualType Result = TL.getType();
4293 if (Result->isDependentType()) {
4294 const UnaryTransformType *T = TL.getTypePtr();
4295 QualType NewBase =
4296 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4297 Result = getDerived().RebuildUnaryTransformType(NewBase,
4298 T->getUTTKind(),
4299 TL.getKWLoc());
4300 if (Result.isNull())
4301 return QualType();
4302 }
4303
4304 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4305 NewTL.setKWLoc(TL.getKWLoc());
4306 NewTL.setParensRange(TL.getParensRange());
4307 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4308 return Result;
4309}
4310
4311template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004312QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4313 AutoTypeLoc TL) {
4314 const AutoType *T = TL.getTypePtr();
4315 QualType OldDeduced = T->getDeducedType();
4316 QualType NewDeduced;
4317 if (!OldDeduced.isNull()) {
4318 NewDeduced = getDerived().TransformType(OldDeduced);
4319 if (NewDeduced.isNull())
4320 return QualType();
4321 }
4322
4323 QualType Result = TL.getType();
4324 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4325 Result = getDerived().RebuildAutoType(NewDeduced);
4326 if (Result.isNull())
4327 return QualType();
4328 }
4329
4330 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4331 NewTL.setNameLoc(TL.getNameLoc());
4332
4333 return Result;
4334}
4335
4336template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004337QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004338 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004339 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004340 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004341 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4342 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004343 if (!Record)
4344 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004345
John McCalla2becad2009-10-21 00:40:46 +00004346 QualType Result = TL.getType();
4347 if (getDerived().AlwaysRebuild() ||
4348 Record != T->getDecl()) {
4349 Result = getDerived().RebuildRecordType(Record);
4350 if (Result.isNull())
4351 return QualType();
4352 }
Mike Stump1eb44332009-09-09 15:08:12 +00004353
John McCalla2becad2009-10-21 00:40:46 +00004354 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4355 NewTL.setNameLoc(TL.getNameLoc());
4356
4357 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004358}
Mike Stump1eb44332009-09-09 15:08:12 +00004359
4360template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004361QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004362 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004363 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004364 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004365 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4366 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004367 if (!Enum)
4368 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004369
John McCalla2becad2009-10-21 00:40:46 +00004370 QualType Result = TL.getType();
4371 if (getDerived().AlwaysRebuild() ||
4372 Enum != T->getDecl()) {
4373 Result = getDerived().RebuildEnumType(Enum);
4374 if (Result.isNull())
4375 return QualType();
4376 }
Mike Stump1eb44332009-09-09 15:08:12 +00004377
John McCalla2becad2009-10-21 00:40:46 +00004378 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4379 NewTL.setNameLoc(TL.getNameLoc());
4380
4381 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004382}
John McCall7da24312009-09-05 00:15:47 +00004383
John McCall3cb0ebd2010-03-10 03:28:59 +00004384template<typename Derived>
4385QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4386 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004387 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004388 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4389 TL.getTypePtr()->getDecl());
4390 if (!D) return QualType();
4391
4392 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4393 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4394 return T;
4395}
4396
Douglas Gregor577f75a2009-08-04 16:50:30 +00004397template<typename Derived>
4398QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004399 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004400 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004401 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004402}
4403
Mike Stump1eb44332009-09-09 15:08:12 +00004404template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004405QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004406 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004407 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004408 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4409
4410 // Substitute into the replacement type, which itself might involve something
4411 // that needs to be transformed. This only tends to occur with default
4412 // template arguments of template template parameters.
4413 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4414 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4415 if (Replacement.isNull())
4416 return QualType();
4417
4418 // Always canonicalize the replacement type.
4419 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4420 QualType Result
4421 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4422 Replacement);
4423
4424 // Propagate type-source information.
4425 SubstTemplateTypeParmTypeLoc NewTL
4426 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4427 NewTL.setNameLoc(TL.getNameLoc());
4428 return Result;
4429
John McCall49a832b2009-10-18 09:09:24 +00004430}
4431
4432template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004433QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4434 TypeLocBuilder &TLB,
4435 SubstTemplateTypeParmPackTypeLoc TL) {
4436 return TransformTypeSpecType(TLB, TL);
4437}
4438
4439template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004440QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004441 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004442 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004443 const TemplateSpecializationType *T = TL.getTypePtr();
4444
Douglas Gregor1d752d72011-03-02 18:46:51 +00004445 // The nested-name-specifier never matters in a TemplateSpecializationType,
4446 // because we can't have a dependent nested-name-specifier anyway.
4447 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004448 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004449 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4450 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004451 if (Template.isNull())
4452 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004453
John McCall43fed0d2010-11-12 08:19:04 +00004454 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4455}
4456
Eli Friedmanb001de72011-10-06 23:00:33 +00004457template<typename Derived>
4458QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4459 AtomicTypeLoc TL) {
4460 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4461 if (ValueType.isNull())
4462 return QualType();
4463
4464 QualType Result = TL.getType();
4465 if (getDerived().AlwaysRebuild() ||
4466 ValueType != TL.getValueLoc().getType()) {
4467 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4468 if (Result.isNull())
4469 return QualType();
4470 }
4471
4472 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4473 NewTL.setKWLoc(TL.getKWLoc());
4474 NewTL.setLParenLoc(TL.getLParenLoc());
4475 NewTL.setRParenLoc(TL.getRParenLoc());
4476
4477 return Result;
4478}
4479
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004480namespace {
4481 /// \brief Simple iterator that traverses the template arguments in a
4482 /// container that provides a \c getArgLoc() member function.
4483 ///
4484 /// This iterator is intended to be used with the iterator form of
4485 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4486 template<typename ArgLocContainer>
4487 class TemplateArgumentLocContainerIterator {
4488 ArgLocContainer *Container;
4489 unsigned Index;
4490
4491 public:
4492 typedef TemplateArgumentLoc value_type;
4493 typedef TemplateArgumentLoc reference;
4494 typedef int difference_type;
4495 typedef std::input_iterator_tag iterator_category;
4496
4497 class pointer {
4498 TemplateArgumentLoc Arg;
4499
4500 public:
4501 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4502
4503 const TemplateArgumentLoc *operator->() const {
4504 return &Arg;
4505 }
4506 };
4507
4508
4509 TemplateArgumentLocContainerIterator() {}
4510
4511 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4512 unsigned Index)
4513 : Container(&Container), Index(Index) { }
4514
4515 TemplateArgumentLocContainerIterator &operator++() {
4516 ++Index;
4517 return *this;
4518 }
4519
4520 TemplateArgumentLocContainerIterator operator++(int) {
4521 TemplateArgumentLocContainerIterator Old(*this);
4522 ++(*this);
4523 return Old;
4524 }
4525
4526 TemplateArgumentLoc operator*() const {
4527 return Container->getArgLoc(Index);
4528 }
4529
4530 pointer operator->() const {
4531 return pointer(Container->getArgLoc(Index));
4532 }
4533
4534 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004535 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004536 return X.Container == Y.Container && X.Index == Y.Index;
4537 }
4538
4539 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004540 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004541 return !(X == Y);
4542 }
4543 };
4544}
4545
4546
John McCall43fed0d2010-11-12 08:19:04 +00004547template <typename Derived>
4548QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4549 TypeLocBuilder &TLB,
4550 TemplateSpecializationTypeLoc TL,
4551 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004552 TemplateArgumentListInfo NewTemplateArgs;
4553 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4554 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004555 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4556 ArgIterator;
4557 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4558 ArgIterator(TL, TL.getNumArgs()),
4559 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004560 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004561
John McCall833ca992009-10-29 08:12:44 +00004562 // FIXME: maybe don't rebuild if all the template arguments are the same.
4563
4564 QualType Result =
4565 getDerived().RebuildTemplateSpecializationType(Template,
4566 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004567 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004568
4569 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004570 // Specializations of template template parameters are represented as
4571 // TemplateSpecializationTypes, and substitution of type alias templates
4572 // within a dependent context can transform them into
4573 // DependentTemplateSpecializationTypes.
4574 if (isa<DependentTemplateSpecializationType>(Result)) {
4575 DependentTemplateSpecializationTypeLoc NewTL
4576 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4577 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4578 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4579 NewTL.setNameLoc(TL.getTemplateNameLoc());
4580 NewTL.setLAngleLoc(TL.getLAngleLoc());
4581 NewTL.setRAngleLoc(TL.getRAngleLoc());
4582 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4583 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4584 return Result;
4585 }
4586
John McCall833ca992009-10-29 08:12:44 +00004587 TemplateSpecializationTypeLoc NewTL
4588 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4589 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4590 NewTL.setLAngleLoc(TL.getLAngleLoc());
4591 NewTL.setRAngleLoc(TL.getRAngleLoc());
4592 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4593 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004594 }
Mike Stump1eb44332009-09-09 15:08:12 +00004595
John McCall833ca992009-10-29 08:12:44 +00004596 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004597}
Mike Stump1eb44332009-09-09 15:08:12 +00004598
Douglas Gregora88f09f2011-02-28 17:23:35 +00004599template <typename Derived>
4600QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4601 TypeLocBuilder &TLB,
4602 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004603 TemplateName Template,
4604 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004605 TemplateArgumentListInfo NewTemplateArgs;
4606 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4607 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4608 typedef TemplateArgumentLocContainerIterator<
4609 DependentTemplateSpecializationTypeLoc> ArgIterator;
4610 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4611 ArgIterator(TL, TL.getNumArgs()),
4612 NewTemplateArgs))
4613 return QualType();
4614
4615 // FIXME: maybe don't rebuild if all the template arguments are the same.
4616
4617 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4618 QualType Result
4619 = getSema().Context.getDependentTemplateSpecializationType(
4620 TL.getTypePtr()->getKeyword(),
4621 DTN->getQualifier(),
4622 DTN->getIdentifier(),
4623 NewTemplateArgs);
4624
4625 DependentTemplateSpecializationTypeLoc NewTL
4626 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4627 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004628
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004629 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregora88f09f2011-02-28 17:23:35 +00004630 NewTL.setNameLoc(TL.getNameLoc());
4631 NewTL.setLAngleLoc(TL.getLAngleLoc());
4632 NewTL.setRAngleLoc(TL.getRAngleLoc());
4633 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4634 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4635 return Result;
4636 }
4637
4638 QualType Result
4639 = getDerived().RebuildTemplateSpecializationType(Template,
4640 TL.getNameLoc(),
4641 NewTemplateArgs);
4642
4643 if (!Result.isNull()) {
4644 /// FIXME: Wrap this in an elaborated-type-specifier?
4645 TemplateSpecializationTypeLoc NewTL
4646 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4647 NewTL.setTemplateNameLoc(TL.getNameLoc());
4648 NewTL.setLAngleLoc(TL.getLAngleLoc());
4649 NewTL.setRAngleLoc(TL.getRAngleLoc());
4650 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4651 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4652 }
4653
4654 return Result;
4655}
4656
Mike Stump1eb44332009-09-09 15:08:12 +00004657template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004658QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004659TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004660 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004661 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004662
Douglas Gregor9e876872011-03-01 18:12:44 +00004663 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004664 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004665 if (TL.getQualifierLoc()) {
4666 QualifierLoc
4667 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4668 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004669 return QualType();
4670 }
Mike Stump1eb44332009-09-09 15:08:12 +00004671
John McCall43fed0d2010-11-12 08:19:04 +00004672 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4673 if (NamedT.isNull())
4674 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004675
Richard Smith3e4c6c42011-05-05 21:57:07 +00004676 // C++0x [dcl.type.elab]p2:
4677 // If the identifier resolves to a typedef-name or the simple-template-id
4678 // resolves to an alias template specialization, the
4679 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004680 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4681 if (const TemplateSpecializationType *TST =
4682 NamedT->getAs<TemplateSpecializationType>()) {
4683 TemplateName Template = TST->getTemplateName();
4684 if (TypeAliasTemplateDecl *TAT =
4685 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4686 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4687 diag::err_tag_reference_non_tag) << 4;
4688 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4689 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004690 }
4691 }
4692
John McCalla2becad2009-10-21 00:40:46 +00004693 QualType Result = TL.getType();
4694 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004695 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004696 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00004697 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004698 T->getKeyword(),
4699 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004700 if (Result.isNull())
4701 return QualType();
4702 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004703
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004704 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004705 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004706 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004707 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004708}
Mike Stump1eb44332009-09-09 15:08:12 +00004709
4710template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004711QualType TreeTransform<Derived>::TransformAttributedType(
4712 TypeLocBuilder &TLB,
4713 AttributedTypeLoc TL) {
4714 const AttributedType *oldType = TL.getTypePtr();
4715 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4716 if (modifiedType.isNull())
4717 return QualType();
4718
4719 QualType result = TL.getType();
4720
4721 // FIXME: dependent operand expressions?
4722 if (getDerived().AlwaysRebuild() ||
4723 modifiedType != oldType->getModifiedType()) {
4724 // TODO: this is really lame; we should really be rebuilding the
4725 // equivalent type from first principles.
4726 QualType equivalentType
4727 = getDerived().TransformType(oldType->getEquivalentType());
4728 if (equivalentType.isNull())
4729 return QualType();
4730 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4731 modifiedType,
4732 equivalentType);
4733 }
4734
4735 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4736 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4737 if (TL.hasAttrOperand())
4738 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4739 if (TL.hasAttrExprOperand())
4740 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4741 else if (TL.hasAttrEnumOperand())
4742 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4743
4744 return result;
4745}
4746
4747template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004748QualType
4749TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4750 ParenTypeLoc TL) {
4751 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4752 if (Inner.isNull())
4753 return QualType();
4754
4755 QualType Result = TL.getType();
4756 if (getDerived().AlwaysRebuild() ||
4757 Inner != TL.getInnerLoc().getType()) {
4758 Result = getDerived().RebuildParenType(Inner);
4759 if (Result.isNull())
4760 return QualType();
4761 }
4762
4763 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4764 NewTL.setLParenLoc(TL.getLParenLoc());
4765 NewTL.setRParenLoc(TL.getRParenLoc());
4766 return Result;
4767}
4768
4769template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004770QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004771 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004772 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004773
Douglas Gregor2494dd02011-03-01 01:34:45 +00004774 NestedNameSpecifierLoc QualifierLoc
4775 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4776 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004777 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004778
John McCall33500952010-06-11 00:33:02 +00004779 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004780 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCall33500952010-06-11 00:33:02 +00004781 TL.getKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004782 QualifierLoc,
4783 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004784 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004785 if (Result.isNull())
4786 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004787
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004788 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4789 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004790 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4791
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004792 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4793 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004794 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004795 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004796 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4797 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004798 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004799 NewTL.setNameLoc(TL.getNameLoc());
4800 }
John McCalla2becad2009-10-21 00:40:46 +00004801 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004802}
Mike Stump1eb44332009-09-09 15:08:12 +00004803
Douglas Gregor577f75a2009-08-04 16:50:30 +00004804template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004805QualType TreeTransform<Derived>::
4806 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004807 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004808 NestedNameSpecifierLoc QualifierLoc;
4809 if (TL.getQualifierLoc()) {
4810 QualifierLoc
4811 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4812 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004813 return QualType();
4814 }
4815
John McCall43fed0d2010-11-12 08:19:04 +00004816 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004817 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004818}
4819
4820template<typename Derived>
4821QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004822TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4823 DependentTemplateSpecializationTypeLoc TL,
4824 NestedNameSpecifierLoc QualifierLoc) {
4825 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4826
4827 TemplateArgumentListInfo NewTemplateArgs;
4828 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4829 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4830
4831 typedef TemplateArgumentLocContainerIterator<
4832 DependentTemplateSpecializationTypeLoc> ArgIterator;
4833 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4834 ArgIterator(TL, TL.getNumArgs()),
4835 NewTemplateArgs))
4836 return QualType();
4837
4838 QualType Result
4839 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4840 QualifierLoc,
4841 T->getIdentifier(),
4842 TL.getNameLoc(),
4843 NewTemplateArgs);
4844 if (Result.isNull())
4845 return QualType();
4846
4847 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4848 QualType NamedT = ElabT->getNamedType();
4849
4850 // Copy information relevant to the template specialization.
4851 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004852 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004853 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004854 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4855 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004856 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004857 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004858
4859 // Copy information relevant to the elaborated type.
4860 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4861 NewTL.setKeywordLoc(TL.getKeywordLoc());
4862 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004863 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4864 DependentTemplateSpecializationTypeLoc SpecTL
4865 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor944cdae2011-03-07 15:13:34 +00004866 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004867 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004868 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004869 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4870 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004871 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004872 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004873 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004874 TemplateSpecializationTypeLoc SpecTL
4875 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004876 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004877 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4878 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004879 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004880 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004881 }
4882 return Result;
4883}
4884
4885template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004886QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4887 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004888 QualType Pattern
4889 = getDerived().TransformType(TLB, TL.getPatternLoc());
4890 if (Pattern.isNull())
4891 return QualType();
4892
4893 QualType Result = TL.getType();
4894 if (getDerived().AlwaysRebuild() ||
4895 Pattern != TL.getPatternLoc().getType()) {
4896 Result = getDerived().RebuildPackExpansionType(Pattern,
4897 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004898 TL.getEllipsisLoc(),
4899 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004900 if (Result.isNull())
4901 return QualType();
4902 }
4903
4904 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4905 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4906 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004907}
4908
4909template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004910QualType
4911TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004912 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004913 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004914 TLB.pushFullCopy(TL);
4915 return TL.getType();
4916}
4917
4918template<typename Derived>
4919QualType
4920TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004921 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004922 // ObjCObjectType is never dependent.
4923 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004924 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004925}
Mike Stump1eb44332009-09-09 15:08:12 +00004926
4927template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004928QualType
4929TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004930 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004931 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004932 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004933 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004934}
4935
Douglas Gregor577f75a2009-08-04 16:50:30 +00004936//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004937// Statement transformation
4938//===----------------------------------------------------------------------===//
4939template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004940StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004941TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004942 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004943}
4944
4945template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004946StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004947TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4948 return getDerived().TransformCompoundStmt(S, false);
4949}
4950
4951template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004952StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004953TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004954 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004955 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004956 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004957 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004958 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4959 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004960 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004961 if (Result.isInvalid()) {
4962 // Immediately fail if this was a DeclStmt, since it's very
4963 // likely that this will cause problems for future statements.
4964 if (isa<DeclStmt>(*B))
4965 return StmtError();
4966
4967 // Otherwise, just keep processing substatements and fail later.
4968 SubStmtInvalid = true;
4969 continue;
4970 }
Mike Stump1eb44332009-09-09 15:08:12 +00004971
Douglas Gregor43959a92009-08-20 07:17:43 +00004972 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4973 Statements.push_back(Result.takeAs<Stmt>());
4974 }
Mike Stump1eb44332009-09-09 15:08:12 +00004975
John McCall7114cba2010-08-27 19:56:05 +00004976 if (SubStmtInvalid)
4977 return StmtError();
4978
Douglas Gregor43959a92009-08-20 07:17:43 +00004979 if (!getDerived().AlwaysRebuild() &&
4980 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004981 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004982
4983 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4984 move_arg(Statements),
4985 S->getRBracLoc(),
4986 IsStmtExpr);
4987}
Mike Stump1eb44332009-09-09 15:08:12 +00004988
Douglas Gregor43959a92009-08-20 07:17:43 +00004989template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004990StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004991TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004992 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00004993 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00004994 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4995 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004996
Eli Friedman264c1f82009-11-19 03:14:00 +00004997 // Transform the left-hand case value.
4998 LHS = getDerived().TransformExpr(S->getLHS());
4999 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005000 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005001
Eli Friedman264c1f82009-11-19 03:14:00 +00005002 // Transform the right-hand case value (for the GNU case-range extension).
5003 RHS = getDerived().TransformExpr(S->getRHS());
5004 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005005 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005006 }
Mike Stump1eb44332009-09-09 15:08:12 +00005007
Douglas Gregor43959a92009-08-20 07:17:43 +00005008 // Build the case statement.
5009 // Case statements are always rebuilt so that they will attached to their
5010 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005011 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005012 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005013 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005014 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005015 S->getColonLoc());
5016 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005017 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005018
Douglas Gregor43959a92009-08-20 07:17:43 +00005019 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005020 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005021 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005022 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005023
Douglas Gregor43959a92009-08-20 07:17:43 +00005024 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005025 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005026}
5027
5028template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005029StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005030TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005031 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005032 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005033 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005034 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005035
Douglas Gregor43959a92009-08-20 07:17:43 +00005036 // Default statements are always rebuilt
5037 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005038 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005039}
Mike Stump1eb44332009-09-09 15:08:12 +00005040
Douglas Gregor43959a92009-08-20 07:17:43 +00005041template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005042StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005043TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005044 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005045 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005046 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005047
Chris Lattner57ad3782011-02-17 20:34:02 +00005048 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5049 S->getDecl());
5050 if (!LD)
5051 return StmtError();
5052
5053
Douglas Gregor43959a92009-08-20 07:17:43 +00005054 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005055 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005056 cast<LabelDecl>(LD), SourceLocation(),
5057 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005058}
Mike Stump1eb44332009-09-09 15:08:12 +00005059
Douglas Gregor43959a92009-08-20 07:17:43 +00005060template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005061StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005062TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005063 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005064 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005065 VarDecl *ConditionVar = 0;
5066 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005067 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005068 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005069 getDerived().TransformDefinition(
5070 S->getConditionVariable()->getLocation(),
5071 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005072 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005073 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005074 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005075 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005076
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005077 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005078 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005079
5080 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005081 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005082 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5083 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005084 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005085 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005086
John McCall9ae2f072010-08-23 23:25:46 +00005087 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005088 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005089 }
Sean Huntc3021132010-05-05 15:23:54 +00005090
John McCall9ae2f072010-08-23 23:25:46 +00005091 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5092 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005093 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005094
Douglas Gregor43959a92009-08-20 07:17:43 +00005095 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005096 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005097 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005098 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005099
Douglas Gregor43959a92009-08-20 07:17:43 +00005100 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005101 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005102 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005103 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005104
Douglas Gregor43959a92009-08-20 07:17:43 +00005105 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005106 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005107 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005108 Then.get() == S->getThen() &&
5109 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005110 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005111
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005112 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005113 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005114 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005115}
5116
5117template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005118StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005119TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005120 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005121 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005122 VarDecl *ConditionVar = 0;
5123 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005124 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005125 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005126 getDerived().TransformDefinition(
5127 S->getConditionVariable()->getLocation(),
5128 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005129 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005130 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005131 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005132 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005133
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005134 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005135 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005136 }
Mike Stump1eb44332009-09-09 15:08:12 +00005137
Douglas Gregor43959a92009-08-20 07:17:43 +00005138 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005139 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005140 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005141 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005142 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005143 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005144
Douglas Gregor43959a92009-08-20 07:17:43 +00005145 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005146 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005147 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005148 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005149
Douglas Gregor43959a92009-08-20 07:17:43 +00005150 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005151 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5152 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005153}
Mike Stump1eb44332009-09-09 15:08:12 +00005154
Douglas Gregor43959a92009-08-20 07:17:43 +00005155template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005156StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005157TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005158 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005159 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005160 VarDecl *ConditionVar = 0;
5161 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005162 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005163 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005164 getDerived().TransformDefinition(
5165 S->getConditionVariable()->getLocation(),
5166 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005167 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005168 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005169 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005170 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005171
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005172 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005173 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005174
5175 if (S->getCond()) {
5176 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005177 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5178 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005179 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005180 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005181 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005182 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005183 }
Mike Stump1eb44332009-09-09 15:08:12 +00005184
John McCall9ae2f072010-08-23 23:25:46 +00005185 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5186 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005187 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005188
Douglas Gregor43959a92009-08-20 07:17:43 +00005189 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005190 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005191 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005192 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005193
Douglas Gregor43959a92009-08-20 07:17:43 +00005194 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005195 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005196 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005197 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005198 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005199
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005200 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005201 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005202}
Mike Stump1eb44332009-09-09 15:08:12 +00005203
Douglas Gregor43959a92009-08-20 07:17:43 +00005204template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005205StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005206TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005207 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005208 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005209 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005210 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005211
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005212 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005213 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005214 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005215 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005216
Douglas Gregor43959a92009-08-20 07:17:43 +00005217 if (!getDerived().AlwaysRebuild() &&
5218 Cond.get() == S->getCond() &&
5219 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005220 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005221
John McCall9ae2f072010-08-23 23:25:46 +00005222 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5223 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005224 S->getRParenLoc());
5225}
Mike Stump1eb44332009-09-09 15:08:12 +00005226
Douglas Gregor43959a92009-08-20 07:17:43 +00005227template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005228StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005229TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005230 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005231 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005232 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005233 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005234
Douglas Gregor43959a92009-08-20 07:17:43 +00005235 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005236 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005237 VarDecl *ConditionVar = 0;
5238 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005239 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005240 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005241 getDerived().TransformDefinition(
5242 S->getConditionVariable()->getLocation(),
5243 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005244 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005245 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005246 } else {
5247 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005248
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005249 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005250 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005251
5252 if (S->getCond()) {
5253 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005254 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5255 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005256 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005257 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005258
John McCall9ae2f072010-08-23 23:25:46 +00005259 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005260 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005261 }
Mike Stump1eb44332009-09-09 15:08:12 +00005262
John McCall9ae2f072010-08-23 23:25:46 +00005263 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5264 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005265 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005266
Douglas Gregor43959a92009-08-20 07:17:43 +00005267 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005268 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005269 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005270 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005271
John McCall9ae2f072010-08-23 23:25:46 +00005272 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5273 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005274 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005275
Douglas Gregor43959a92009-08-20 07:17:43 +00005276 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005277 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005278 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005279 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005280
Douglas Gregor43959a92009-08-20 07:17:43 +00005281 if (!getDerived().AlwaysRebuild() &&
5282 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005283 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005284 Inc.get() == S->getInc() &&
5285 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005286 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005287
Douglas Gregor43959a92009-08-20 07:17:43 +00005288 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005289 Init.get(), FullCond, ConditionVar,
5290 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005291}
5292
5293template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005294StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005295TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005296 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5297 S->getLabel());
5298 if (!LD)
5299 return StmtError();
5300
Douglas Gregor43959a92009-08-20 07:17:43 +00005301 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005302 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005303 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005304}
5305
5306template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005307StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005308TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005309 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005310 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005311 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005312
Douglas Gregor43959a92009-08-20 07:17:43 +00005313 if (!getDerived().AlwaysRebuild() &&
5314 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005315 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005316
5317 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005318 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005319}
5320
5321template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005322StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005323TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005324 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005325}
Mike Stump1eb44332009-09-09 15:08:12 +00005326
Douglas Gregor43959a92009-08-20 07:17:43 +00005327template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005328StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005329TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005330 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005331}
Mike Stump1eb44332009-09-09 15:08:12 +00005332
Douglas Gregor43959a92009-08-20 07:17:43 +00005333template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005334StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005335TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005336 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005337 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005338 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005339
Mike Stump1eb44332009-09-09 15:08:12 +00005340 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005341 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005342 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005343}
Mike Stump1eb44332009-09-09 15:08:12 +00005344
Douglas Gregor43959a92009-08-20 07:17:43 +00005345template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005346StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005347TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005348 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005349 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005350 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5351 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005352 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5353 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005354 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005355 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005356
Douglas Gregor43959a92009-08-20 07:17:43 +00005357 if (Transformed != *D)
5358 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005359
Douglas Gregor43959a92009-08-20 07:17:43 +00005360 Decls.push_back(Transformed);
5361 }
Mike Stump1eb44332009-09-09 15:08:12 +00005362
Douglas Gregor43959a92009-08-20 07:17:43 +00005363 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005364 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005365
5366 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005367 S->getStartLoc(), S->getEndLoc());
5368}
Mike Stump1eb44332009-09-09 15:08:12 +00005369
Douglas Gregor43959a92009-08-20 07:17:43 +00005370template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005371StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005372TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005373
John McCallca0408f2010-08-23 06:44:23 +00005374 ASTOwningVector<Expr*> Constraints(getSema());
5375 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005376 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005377
John McCall60d7b3a2010-08-24 06:29:42 +00005378 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005379 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005380
5381 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005382
Anders Carlsson703e3942010-01-24 05:50:09 +00005383 // Go through the outputs.
5384 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005385 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005386
Anders Carlsson703e3942010-01-24 05:50:09 +00005387 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005388 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005389
Anders Carlsson703e3942010-01-24 05:50:09 +00005390 // Transform the output expr.
5391 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005392 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005393 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005394 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005395
Anders Carlsson703e3942010-01-24 05:50:09 +00005396 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005397
John McCall9ae2f072010-08-23 23:25:46 +00005398 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005399 }
Sean Huntc3021132010-05-05 15:23:54 +00005400
Anders Carlsson703e3942010-01-24 05:50:09 +00005401 // Go through the inputs.
5402 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005403 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005404
Anders Carlsson703e3942010-01-24 05:50:09 +00005405 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005406 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005407
Anders Carlsson703e3942010-01-24 05:50:09 +00005408 // Transform the input expr.
5409 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005410 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005411 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005412 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005413
Anders Carlsson703e3942010-01-24 05:50:09 +00005414 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005415
John McCall9ae2f072010-08-23 23:25:46 +00005416 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005417 }
Sean Huntc3021132010-05-05 15:23:54 +00005418
Anders Carlsson703e3942010-01-24 05:50:09 +00005419 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005420 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005421
5422 // Go through the clobbers.
5423 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005424 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005425
5426 // No need to transform the asm string literal.
5427 AsmString = SemaRef.Owned(S->getAsmString());
5428
5429 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5430 S->isSimple(),
5431 S->isVolatile(),
5432 S->getNumOutputs(),
5433 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005434 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005435 move_arg(Constraints),
5436 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005437 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005438 move_arg(Clobbers),
5439 S->getRParenLoc(),
5440 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005441}
5442
5443
5444template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005445StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005446TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005447 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005448 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005449 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005450 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005451
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005452 // Transform the @catch statements (if present).
5453 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005454 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005455 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005456 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005457 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005458 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005459 if (Catch.get() != S->getCatchStmt(I))
5460 AnyCatchChanged = true;
5461 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005462 }
Sean Huntc3021132010-05-05 15:23:54 +00005463
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005464 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005465 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005466 if (S->getFinallyStmt()) {
5467 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5468 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005469 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005470 }
5471
5472 // If nothing changed, just retain this statement.
5473 if (!getDerived().AlwaysRebuild() &&
5474 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005475 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005476 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005477 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005478
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005479 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005480 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5481 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005482}
Mike Stump1eb44332009-09-09 15:08:12 +00005483
Douglas Gregor43959a92009-08-20 07:17:43 +00005484template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005485StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005486TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005487 // Transform the @catch parameter, if there is one.
5488 VarDecl *Var = 0;
5489 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5490 TypeSourceInfo *TSInfo = 0;
5491 if (FromVar->getTypeSourceInfo()) {
5492 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5493 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005494 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005495 }
Sean Huntc3021132010-05-05 15:23:54 +00005496
Douglas Gregorbe270a02010-04-26 17:57:08 +00005497 QualType T;
5498 if (TSInfo)
5499 T = TSInfo->getType();
5500 else {
5501 T = getDerived().TransformType(FromVar->getType());
5502 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005503 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005504 }
Sean Huntc3021132010-05-05 15:23:54 +00005505
Douglas Gregorbe270a02010-04-26 17:57:08 +00005506 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5507 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005508 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005509 }
Sean Huntc3021132010-05-05 15:23:54 +00005510
John McCall60d7b3a2010-08-24 06:29:42 +00005511 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005512 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005513 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005514
5515 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005516 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005517 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005518}
Mike Stump1eb44332009-09-09 15:08:12 +00005519
Douglas Gregor43959a92009-08-20 07:17:43 +00005520template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005521StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005522TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005523 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005524 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005525 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005526 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005527
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005528 // If nothing changed, just retain this statement.
5529 if (!getDerived().AlwaysRebuild() &&
5530 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005531 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005532
5533 // Build a new statement.
5534 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005535 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005536}
Mike Stump1eb44332009-09-09 15:08:12 +00005537
Douglas Gregor43959a92009-08-20 07:17:43 +00005538template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005539StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005540TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005541 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005542 if (S->getThrowExpr()) {
5543 Operand = getDerived().TransformExpr(S->getThrowExpr());
5544 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005545 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005546 }
Sean Huntc3021132010-05-05 15:23:54 +00005547
Douglas Gregord1377b22010-04-22 21:44:01 +00005548 if (!getDerived().AlwaysRebuild() &&
5549 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005550 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005551
John McCall9ae2f072010-08-23 23:25:46 +00005552 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005553}
Mike Stump1eb44332009-09-09 15:08:12 +00005554
Douglas Gregor43959a92009-08-20 07:17:43 +00005555template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005556StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005557TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005558 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005559 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005560 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005561 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005562 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005563 Object =
5564 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5565 Object.get());
5566 if (Object.isInvalid())
5567 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005568
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005569 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005570 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005571 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005572 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005573
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005574 // If nothing change, just retain the current statement.
5575 if (!getDerived().AlwaysRebuild() &&
5576 Object.get() == S->getSynchExpr() &&
5577 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005578 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005579
5580 // Build a new statement.
5581 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005582 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005583}
5584
5585template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005586StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005587TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5588 ObjCAutoreleasePoolStmt *S) {
5589 // Transform the body.
5590 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5591 if (Body.isInvalid())
5592 return StmtError();
5593
5594 // If nothing changed, just retain this statement.
5595 if (!getDerived().AlwaysRebuild() &&
5596 Body.get() == S->getSubStmt())
5597 return SemaRef.Owned(S);
5598
5599 // Build a new statement.
5600 return getDerived().RebuildObjCAutoreleasePoolStmt(
5601 S->getAtLoc(), Body.get());
5602}
5603
5604template<typename Derived>
5605StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005606TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005607 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005608 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005609 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005610 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005611 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005612
Douglas Gregorc3203e72010-04-22 23:10:45 +00005613 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005614 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005615 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005616 return StmtError();
John McCall990567c2011-07-27 01:07:15 +00005617 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5618 Collection.take());
5619 if (Collection.isInvalid())
5620 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005621
Douglas Gregorc3203e72010-04-22 23:10:45 +00005622 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005623 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005624 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005625 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005626
Douglas Gregorc3203e72010-04-22 23:10:45 +00005627 // If nothing changed, just retain this statement.
5628 if (!getDerived().AlwaysRebuild() &&
5629 Element.get() == S->getElement() &&
5630 Collection.get() == S->getCollection() &&
5631 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005632 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005633
Douglas Gregorc3203e72010-04-22 23:10:45 +00005634 // Build a new statement.
5635 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5636 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005637 Element.get(),
5638 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005639 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005640 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005641}
5642
5643
5644template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005645StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005646TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5647 // Transform the exception declaration, if any.
5648 VarDecl *Var = 0;
5649 if (S->getExceptionDecl()) {
5650 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005651 TypeSourceInfo *T = getDerived().TransformType(
5652 ExceptionDecl->getTypeSourceInfo());
5653 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005654 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005655
Douglas Gregor83cb9422010-09-09 17:09:21 +00005656 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005657 ExceptionDecl->getInnerLocStart(),
5658 ExceptionDecl->getLocation(),
5659 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005660 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005661 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005662 }
Mike Stump1eb44332009-09-09 15:08:12 +00005663
Douglas Gregor43959a92009-08-20 07:17:43 +00005664 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005665 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005666 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005667 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005668
Douglas Gregor43959a92009-08-20 07:17:43 +00005669 if (!getDerived().AlwaysRebuild() &&
5670 !Var &&
5671 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005672 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005673
5674 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5675 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005676 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005677}
Mike Stump1eb44332009-09-09 15:08:12 +00005678
Douglas Gregor43959a92009-08-20 07:17:43 +00005679template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005680StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005681TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5682 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005683 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005684 = getDerived().TransformCompoundStmt(S->getTryBlock());
5685 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005686 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005687
Douglas Gregor43959a92009-08-20 07:17:43 +00005688 // Transform the handlers.
5689 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005690 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005691 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005692 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005693 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5694 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005695 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005696
Douglas Gregor43959a92009-08-20 07:17:43 +00005697 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5698 Handlers.push_back(Handler.takeAs<Stmt>());
5699 }
Mike Stump1eb44332009-09-09 15:08:12 +00005700
Douglas Gregor43959a92009-08-20 07:17:43 +00005701 if (!getDerived().AlwaysRebuild() &&
5702 TryBlock.get() == S->getTryBlock() &&
5703 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005704 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005705
John McCall9ae2f072010-08-23 23:25:46 +00005706 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005707 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005708}
Mike Stump1eb44332009-09-09 15:08:12 +00005709
Richard Smithad762fc2011-04-14 22:09:26 +00005710template<typename Derived>
5711StmtResult
5712TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5713 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5714 if (Range.isInvalid())
5715 return StmtError();
5716
5717 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5718 if (BeginEnd.isInvalid())
5719 return StmtError();
5720
5721 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5722 if (Cond.isInvalid())
5723 return StmtError();
5724
5725 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5726 if (Inc.isInvalid())
5727 return StmtError();
5728
5729 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5730 if (LoopVar.isInvalid())
5731 return StmtError();
5732
5733 StmtResult NewStmt = S;
5734 if (getDerived().AlwaysRebuild() ||
5735 Range.get() != S->getRangeStmt() ||
5736 BeginEnd.get() != S->getBeginEndStmt() ||
5737 Cond.get() != S->getCond() ||
5738 Inc.get() != S->getInc() ||
5739 LoopVar.get() != S->getLoopVarStmt())
5740 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5741 S->getColonLoc(), Range.get(),
5742 BeginEnd.get(), Cond.get(),
5743 Inc.get(), LoopVar.get(),
5744 S->getRParenLoc());
5745
5746 StmtResult Body = getDerived().TransformStmt(S->getBody());
5747 if (Body.isInvalid())
5748 return StmtError();
5749
5750 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5751 // it now so we have a new statement to attach the body to.
5752 if (Body.get() != S->getBody() && NewStmt.get() == S)
5753 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5754 S->getColonLoc(), Range.get(),
5755 BeginEnd.get(), Cond.get(),
5756 Inc.get(), LoopVar.get(),
5757 S->getRParenLoc());
5758
5759 if (NewStmt.get() == S)
5760 return SemaRef.Owned(S);
5761
5762 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5763}
5764
John Wiegley28bbe4b2011-04-28 01:08:34 +00005765template<typename Derived>
5766StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005767TreeTransform<Derived>::TransformMSDependentExistsStmt(
5768 MSDependentExistsStmt *S) {
5769 // Transform the nested-name-specifier, if any.
5770 NestedNameSpecifierLoc QualifierLoc;
5771 if (S->getQualifierLoc()) {
5772 QualifierLoc
5773 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5774 if (!QualifierLoc)
5775 return StmtError();
5776 }
5777
5778 // Transform the declaration name.
5779 DeclarationNameInfo NameInfo = S->getNameInfo();
5780 if (NameInfo.getName()) {
5781 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5782 if (!NameInfo.getName())
5783 return StmtError();
5784 }
5785
5786 // Check whether anything changed.
5787 if (!getDerived().AlwaysRebuild() &&
5788 QualifierLoc == S->getQualifierLoc() &&
5789 NameInfo.getName() == S->getNameInfo().getName())
5790 return S;
5791
5792 // Determine whether this name exists, if we can.
5793 CXXScopeSpec SS;
5794 SS.Adopt(QualifierLoc);
5795 bool Dependent = false;
5796 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5797 case Sema::IER_Exists:
5798 if (S->isIfExists())
5799 break;
5800
5801 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5802
5803 case Sema::IER_DoesNotExist:
5804 if (S->isIfNotExists())
5805 break;
5806
5807 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5808
5809 case Sema::IER_Dependent:
5810 Dependent = true;
5811 break;
Douglas Gregor65019ac2011-10-25 03:44:56 +00005812
5813 case Sema::IER_Error:
5814 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005815 }
5816
5817 // We need to continue with the instantiation, so do so now.
5818 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5819 if (SubStmt.isInvalid())
5820 return StmtError();
5821
5822 // If we have resolved the name, just transform to the substatement.
5823 if (!Dependent)
5824 return SubStmt;
5825
5826 // The name is still dependent, so build a dependent expression again.
5827 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5828 S->isIfExists(),
5829 QualifierLoc,
5830 NameInfo,
5831 SubStmt.get());
5832}
5833
5834template<typename Derived>
5835StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00005836TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5837 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5838 if(TryBlock.isInvalid()) return StmtError();
5839
5840 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5841 if(!getDerived().AlwaysRebuild() &&
5842 TryBlock.get() == S->getTryBlock() &&
5843 Handler.get() == S->getHandler())
5844 return SemaRef.Owned(S);
5845
5846 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5847 S->getTryLoc(),
5848 TryBlock.take(),
5849 Handler.take());
5850}
5851
5852template<typename Derived>
5853StmtResult
5854TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5855 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5856 if(Block.isInvalid()) return StmtError();
5857
5858 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5859 Block.take());
5860}
5861
5862template<typename Derived>
5863StmtResult
5864TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5865 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5866 if(FilterExpr.isInvalid()) return StmtError();
5867
5868 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5869 if(Block.isInvalid()) return StmtError();
5870
5871 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5872 FilterExpr.take(),
5873 Block.take());
5874}
5875
5876template<typename Derived>
5877StmtResult
5878TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5879 if(isa<SEHFinallyStmt>(Handler))
5880 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5881 else
5882 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5883}
5884
Douglas Gregor43959a92009-08-20 07:17:43 +00005885//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005886// Expression transformation
5887//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005888template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005889ExprResult
John McCall454feb92009-12-08 09:21:05 +00005890TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005891 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005892}
Mike Stump1eb44332009-09-09 15:08:12 +00005893
5894template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005895ExprResult
John McCall454feb92009-12-08 09:21:05 +00005896TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005897 NestedNameSpecifierLoc QualifierLoc;
5898 if (E->getQualifierLoc()) {
5899 QualifierLoc
5900 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5901 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005902 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005903 }
John McCalldbd872f2009-12-08 09:08:17 +00005904
5905 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005906 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5907 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005908 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005909 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005910
John McCallec8045d2010-08-17 21:27:17 +00005911 DeclarationNameInfo NameInfo = E->getNameInfo();
5912 if (NameInfo.getName()) {
5913 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5914 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005915 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005916 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005917
5918 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00005919 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00005920 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005921 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00005922 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005923
5924 // Mark it referenced in the new context regardless.
5925 // FIXME: this is a bit instantiation-specific.
5926 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5927
John McCall3fa5cae2010-10-26 07:05:15 +00005928 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00005929 }
John McCalldbd872f2009-12-08 09:08:17 +00005930
5931 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00005932 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005933 TemplateArgs = &TransArgs;
5934 TransArgs.setLAngleLoc(E->getLAngleLoc());
5935 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005936 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5937 E->getNumTemplateArgs(),
5938 TransArgs))
5939 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00005940 }
5941
Douglas Gregor40d96a62011-02-28 21:54:11 +00005942 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5943 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005944}
Mike Stump1eb44332009-09-09 15:08:12 +00005945
Douglas Gregorb98b1992009-08-11 05:31:07 +00005946template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005947ExprResult
John McCall454feb92009-12-08 09:21:05 +00005948TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005949 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005950}
Mike Stump1eb44332009-09-09 15:08:12 +00005951
Douglas Gregorb98b1992009-08-11 05:31:07 +00005952template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005953ExprResult
John McCall454feb92009-12-08 09:21:05 +00005954TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005955 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005956}
Mike Stump1eb44332009-09-09 15:08:12 +00005957
Douglas Gregorb98b1992009-08-11 05:31:07 +00005958template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005959ExprResult
John McCall454feb92009-12-08 09:21:05 +00005960TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005961 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005962}
Mike Stump1eb44332009-09-09 15:08:12 +00005963
Douglas Gregorb98b1992009-08-11 05:31:07 +00005964template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005965ExprResult
John McCall454feb92009-12-08 09:21:05 +00005966TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005967 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005968}
Mike Stump1eb44332009-09-09 15:08:12 +00005969
Douglas Gregorb98b1992009-08-11 05:31:07 +00005970template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005971ExprResult
John McCall454feb92009-12-08 09:21:05 +00005972TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005973 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005974}
5975
5976template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005977ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00005978TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5979 ExprResult ControllingExpr =
5980 getDerived().TransformExpr(E->getControllingExpr());
5981 if (ControllingExpr.isInvalid())
5982 return ExprError();
5983
Chris Lattner686775d2011-07-20 06:58:45 +00005984 SmallVector<Expr *, 4> AssocExprs;
5985 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00005986 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5987 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5988 if (TS) {
5989 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5990 if (!AssocType)
5991 return ExprError();
5992 AssocTypes.push_back(AssocType);
5993 } else {
5994 AssocTypes.push_back(0);
5995 }
5996
5997 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5998 if (AssocExpr.isInvalid())
5999 return ExprError();
6000 AssocExprs.push_back(AssocExpr.release());
6001 }
6002
6003 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6004 E->getDefaultLoc(),
6005 E->getRParenLoc(),
6006 ControllingExpr.release(),
6007 AssocTypes.data(),
6008 AssocExprs.data(),
6009 E->getNumAssocs());
6010}
6011
6012template<typename Derived>
6013ExprResult
John McCall454feb92009-12-08 09:21:05 +00006014TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006015 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006016 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006017 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006018
Douglas Gregorb98b1992009-08-11 05:31:07 +00006019 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006020 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006021
John McCall9ae2f072010-08-23 23:25:46 +00006022 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006023 E->getRParen());
6024}
6025
Mike Stump1eb44332009-09-09 15:08:12 +00006026template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006027ExprResult
John McCall454feb92009-12-08 09:21:05 +00006028TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006029 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006030 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006031 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006032
Douglas Gregorb98b1992009-08-11 05:31:07 +00006033 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006034 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006035
Douglas Gregorb98b1992009-08-11 05:31:07 +00006036 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6037 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006038 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006039}
Mike Stump1eb44332009-09-09 15:08:12 +00006040
Douglas Gregorb98b1992009-08-11 05:31:07 +00006041template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006042ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006043TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6044 // Transform the type.
6045 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6046 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006047 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006048
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006049 // Transform all of the components into components similar to what the
6050 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00006051 // FIXME: It would be slightly more efficient in the non-dependent case to
6052 // just map FieldDecls, rather than requiring the rebuilder to look for
6053 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006054 // template code that we don't care.
6055 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006056 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006057 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006058 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006059 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6060 const Node &ON = E->getComponent(I);
6061 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006062 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006063 Comp.LocStart = ON.getSourceRange().getBegin();
6064 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006065 switch (ON.getKind()) {
6066 case Node::Array: {
6067 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006068 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006069 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006070 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006071
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006072 ExprChanged = ExprChanged || Index.get() != FromIndex;
6073 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006074 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006075 break;
6076 }
Sean Huntc3021132010-05-05 15:23:54 +00006077
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006078 case Node::Field:
6079 case Node::Identifier:
6080 Comp.isBrackets = false;
6081 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006082 if (!Comp.U.IdentInfo)
6083 continue;
Sean Huntc3021132010-05-05 15:23:54 +00006084
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006085 break;
Sean Huntc3021132010-05-05 15:23:54 +00006086
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006087 case Node::Base:
6088 // Will be recomputed during the rebuild.
6089 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006090 }
Sean Huntc3021132010-05-05 15:23:54 +00006091
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006092 Components.push_back(Comp);
6093 }
Sean Huntc3021132010-05-05 15:23:54 +00006094
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006095 // If nothing changed, retain the existing expression.
6096 if (!getDerived().AlwaysRebuild() &&
6097 Type == E->getTypeSourceInfo() &&
6098 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006099 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006100
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006101 // Build a new offsetof expression.
6102 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6103 Components.data(), Components.size(),
6104 E->getRParenLoc());
6105}
6106
6107template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006108ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006109TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6110 assert(getDerived().AlreadyTransformed(E->getType()) &&
6111 "opaque value expression requires transformation");
6112 return SemaRef.Owned(E);
6113}
6114
6115template<typename Derived>
6116ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006117TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006118 // Rebuild the syntactic form. The original syntactic form has
6119 // opaque-value expressions in it, so strip those away and rebuild
6120 // the result. This is a really awful way of doing this, but the
6121 // better solution (rebuilding the semantic expressions and
6122 // rebinding OVEs as necessary) doesn't work; we'd need
6123 // TreeTransform to not strip away implicit conversions.
6124 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6125 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006126 if (result.isInvalid()) return ExprError();
6127
6128 // If that gives us a pseudo-object result back, the pseudo-object
6129 // expression must have been an lvalue-to-rvalue conversion which we
6130 // should reapply.
6131 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6132 result = SemaRef.checkPseudoObjectRValue(result.take());
6133
6134 return result;
6135}
6136
6137template<typename Derived>
6138ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006139TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6140 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006141 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006142 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006143
John McCalla93c9342009-12-07 02:54:59 +00006144 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006145 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006146 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006147
John McCall5ab75172009-11-04 07:28:41 +00006148 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006149 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006150
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006151 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6152 E->getKind(),
6153 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006154 }
Mike Stump1eb44332009-09-09 15:08:12 +00006155
John McCall60d7b3a2010-08-24 06:29:42 +00006156 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00006157 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006158 // C++0x [expr.sizeof]p1:
6159 // The operand is either an expression, which is an unevaluated operand
6160 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00006161 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006162
Douglas Gregorb98b1992009-08-11 05:31:07 +00006163 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6164 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006165 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006166
Douglas Gregorb98b1992009-08-11 05:31:07 +00006167 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006168 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006169 }
Mike Stump1eb44332009-09-09 15:08:12 +00006170
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006171 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6172 E->getOperatorLoc(),
6173 E->getKind(),
6174 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006175}
Mike Stump1eb44332009-09-09 15:08:12 +00006176
Douglas Gregorb98b1992009-08-11 05:31:07 +00006177template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006178ExprResult
John McCall454feb92009-12-08 09:21:05 +00006179TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006180 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006181 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006182 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006183
John McCall60d7b3a2010-08-24 06:29:42 +00006184 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006185 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006186 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006187
6188
Douglas Gregorb98b1992009-08-11 05:31:07 +00006189 if (!getDerived().AlwaysRebuild() &&
6190 LHS.get() == E->getLHS() &&
6191 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006192 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006193
John McCall9ae2f072010-08-23 23:25:46 +00006194 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006195 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006196 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006197 E->getRBracketLoc());
6198}
Mike Stump1eb44332009-09-09 15:08:12 +00006199
6200template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006201ExprResult
John McCall454feb92009-12-08 09:21:05 +00006202TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006203 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006204 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006205 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006206 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006207
6208 // Transform arguments.
6209 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006210 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006211 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6212 &ArgChanged))
6213 return ExprError();
6214
Douglas Gregorb98b1992009-08-11 05:31:07 +00006215 if (!getDerived().AlwaysRebuild() &&
6216 Callee.get() == E->getCallee() &&
6217 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006218 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump1eb44332009-09-09 15:08:12 +00006219
Douglas Gregorb98b1992009-08-11 05:31:07 +00006220 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006221 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006222 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006223 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006224 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006225 E->getRParenLoc());
6226}
Mike Stump1eb44332009-09-09 15:08:12 +00006227
6228template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006229ExprResult
John McCall454feb92009-12-08 09:21:05 +00006230TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006231 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006232 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006233 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006234
Douglas Gregor40d96a62011-02-28 21:54:11 +00006235 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006236 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006237 QualifierLoc
6238 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6239
6240 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006241 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006242 }
Mike Stump1eb44332009-09-09 15:08:12 +00006243
Eli Friedmanf595cc42009-12-04 06:40:45 +00006244 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006245 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6246 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006247 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006248 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006249
John McCall6bb80172010-03-30 21:47:33 +00006250 NamedDecl *FoundDecl = E->getFoundDecl();
6251 if (FoundDecl == E->getMemberDecl()) {
6252 FoundDecl = Member;
6253 } else {
6254 FoundDecl = cast_or_null<NamedDecl>(
6255 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6256 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006257 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006258 }
6259
Douglas Gregorb98b1992009-08-11 05:31:07 +00006260 if (!getDerived().AlwaysRebuild() &&
6261 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006262 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006263 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006264 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006265 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006266
Anders Carlsson1f240322009-12-22 05:24:09 +00006267 // Mark it referenced in the new context regardless.
6268 // FIXME: this is a bit instantiation-specific.
6269 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00006270 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006271 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006272
John McCalld5532b62009-11-23 01:53:49 +00006273 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006274 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006275 TransArgs.setLAngleLoc(E->getLAngleLoc());
6276 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006277 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6278 E->getNumTemplateArgs(),
6279 TransArgs))
6280 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006281 }
Sean Huntc3021132010-05-05 15:23:54 +00006282
Douglas Gregorb98b1992009-08-11 05:31:07 +00006283 // FIXME: Bogus source location for the operator
6284 SourceLocation FakeOperatorLoc
6285 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6286
John McCallc2233c52010-01-15 08:34:02 +00006287 // FIXME: to do this check properly, we will need to preserve the
6288 // first-qualifier-in-scope here, just in case we had a dependent
6289 // base (and therefore couldn't do the check) and a
6290 // nested-name-qualifier (and therefore could do the lookup).
6291 NamedDecl *FirstQualifierInScope = 0;
6292
John McCall9ae2f072010-08-23 23:25:46 +00006293 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006294 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006295 QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006296 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006297 Member,
John McCall6bb80172010-03-30 21:47:33 +00006298 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006299 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006300 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006301 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006302}
Mike Stump1eb44332009-09-09 15:08:12 +00006303
Douglas Gregorb98b1992009-08-11 05:31:07 +00006304template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006305ExprResult
John McCall454feb92009-12-08 09:21:05 +00006306TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006307 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006308 if (LHS.isInvalid())
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 RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006312 if (RHS.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() &&
6316 LHS.get() == E->getLHS() &&
6317 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006318 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006319
Douglas Gregorb98b1992009-08-11 05:31:07 +00006320 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006321 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006322}
6323
Mike Stump1eb44332009-09-09 15:08:12 +00006324template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006325ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006326TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006327 CompoundAssignOperator *E) {
6328 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006329}
Mike Stump1eb44332009-09-09 15:08:12 +00006330
Douglas Gregorb98b1992009-08-11 05:31:07 +00006331template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006332ExprResult TreeTransform<Derived>::
6333TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6334 // Just rebuild the common and RHS expressions and see whether we
6335 // get any changes.
6336
6337 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6338 if (commonExpr.isInvalid())
6339 return ExprError();
6340
6341 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6342 if (rhs.isInvalid())
6343 return ExprError();
6344
6345 if (!getDerived().AlwaysRebuild() &&
6346 commonExpr.get() == e->getCommon() &&
6347 rhs.get() == e->getFalseExpr())
6348 return SemaRef.Owned(e);
6349
6350 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6351 e->getQuestionLoc(),
6352 0,
6353 e->getColonLoc(),
6354 rhs.get());
6355}
6356
6357template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006358ExprResult
John McCall454feb92009-12-08 09:21:05 +00006359TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006360 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006361 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006362 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006363
John McCall60d7b3a2010-08-24 06:29:42 +00006364 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006365 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006366 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006367
John McCall60d7b3a2010-08-24 06:29:42 +00006368 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006369 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006370 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006371
Douglas Gregorb98b1992009-08-11 05:31:07 +00006372 if (!getDerived().AlwaysRebuild() &&
6373 Cond.get() == E->getCond() &&
6374 LHS.get() == E->getLHS() &&
6375 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006376 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006377
John McCall9ae2f072010-08-23 23:25:46 +00006378 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006379 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006380 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006381 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006382 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006383}
Mike Stump1eb44332009-09-09 15:08:12 +00006384
6385template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006386ExprResult
John McCall454feb92009-12-08 09:21:05 +00006387TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006388 // Implicit casts are eliminated during transformation, since they
6389 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006390 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006391}
Mike Stump1eb44332009-09-09 15:08:12 +00006392
Douglas Gregorb98b1992009-08-11 05:31:07 +00006393template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006394ExprResult
John McCall454feb92009-12-08 09:21:05 +00006395TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006396 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6397 if (!Type)
6398 return ExprError();
6399
John McCall60d7b3a2010-08-24 06:29:42 +00006400 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006401 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006402 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006403 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006404
Douglas Gregorb98b1992009-08-11 05:31:07 +00006405 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006406 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006407 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006408 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006409
John McCall9d125032010-01-15 18:39:57 +00006410 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006411 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006412 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006413 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006414}
Mike Stump1eb44332009-09-09 15:08:12 +00006415
Douglas Gregorb98b1992009-08-11 05:31:07 +00006416template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006417ExprResult
John McCall454feb92009-12-08 09:21:05 +00006418TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006419 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6420 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6421 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006422 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006423
John McCall60d7b3a2010-08-24 06:29:42 +00006424 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006425 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006426 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006427
Douglas Gregorb98b1992009-08-11 05:31:07 +00006428 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006429 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006430 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006431 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006432
John McCall1d7d8d62010-01-19 22:33:45 +00006433 // Note: the expression type doesn't necessarily match the
6434 // type-as-written, but that's okay, because it should always be
6435 // derivable from the initializer.
6436
John McCall42f56b52010-01-18 19:35:47 +00006437 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006438 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006439 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006440}
Mike Stump1eb44332009-09-09 15:08:12 +00006441
Douglas Gregorb98b1992009-08-11 05:31:07 +00006442template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006443ExprResult
John McCall454feb92009-12-08 09:21:05 +00006444TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006445 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006446 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006447 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006448
Douglas Gregorb98b1992009-08-11 05:31:07 +00006449 if (!getDerived().AlwaysRebuild() &&
6450 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006451 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006452
Douglas Gregorb98b1992009-08-11 05:31:07 +00006453 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006454 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006455 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006456 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006457 E->getAccessorLoc(),
6458 E->getAccessor());
6459}
Mike Stump1eb44332009-09-09 15:08:12 +00006460
Douglas Gregorb98b1992009-08-11 05:31:07 +00006461template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006462ExprResult
John McCall454feb92009-12-08 09:21:05 +00006463TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006464 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006465
John McCallca0408f2010-08-23 06:44:23 +00006466 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006467 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6468 Inits, &InitChanged))
6469 return ExprError();
6470
Douglas Gregorb98b1992009-08-11 05:31:07 +00006471 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006472 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006473
Douglas Gregorb98b1992009-08-11 05:31:07 +00006474 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006475 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006476}
Mike Stump1eb44332009-09-09 15:08:12 +00006477
Douglas Gregorb98b1992009-08-11 05:31:07 +00006478template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006479ExprResult
John McCall454feb92009-12-08 09:21:05 +00006480TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006481 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006482
Douglas Gregor43959a92009-08-20 07:17:43 +00006483 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006484 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006485 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006486 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006487
Douglas Gregor43959a92009-08-20 07:17:43 +00006488 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006489 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006490 bool ExprChanged = false;
6491 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6492 DEnd = E->designators_end();
6493 D != DEnd; ++D) {
6494 if (D->isFieldDesignator()) {
6495 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6496 D->getDotLoc(),
6497 D->getFieldLoc()));
6498 continue;
6499 }
Mike Stump1eb44332009-09-09 15:08:12 +00006500
Douglas Gregorb98b1992009-08-11 05:31:07 +00006501 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006502 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006503 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006504 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006505
6506 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006507 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006508
Douglas Gregorb98b1992009-08-11 05:31:07 +00006509 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6510 ArrayExprs.push_back(Index.release());
6511 continue;
6512 }
Mike Stump1eb44332009-09-09 15:08:12 +00006513
Douglas Gregorb98b1992009-08-11 05:31:07 +00006514 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006515 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006516 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6517 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006518 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006519
John McCall60d7b3a2010-08-24 06:29:42 +00006520 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006521 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006522 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006523
6524 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006525 End.get(),
6526 D->getLBracketLoc(),
6527 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006528
Douglas Gregorb98b1992009-08-11 05:31:07 +00006529 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6530 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006531
Douglas Gregorb98b1992009-08-11 05:31:07 +00006532 ArrayExprs.push_back(Start.release());
6533 ArrayExprs.push_back(End.release());
6534 }
Mike Stump1eb44332009-09-09 15:08:12 +00006535
Douglas Gregorb98b1992009-08-11 05:31:07 +00006536 if (!getDerived().AlwaysRebuild() &&
6537 Init.get() == E->getInit() &&
6538 !ExprChanged)
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().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6542 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006543 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006544}
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
Douglas Gregorb98b1992009-08-11 05:31:07 +00006548TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006549 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006550 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006551
Douglas Gregor5557b252009-10-28 00:29:27 +00006552 // FIXME: Will we ever have proper type location here? Will we actually
6553 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006554 QualType T = getDerived().TransformType(E->getType());
6555 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006556 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006557
Douglas Gregorb98b1992009-08-11 05:31:07 +00006558 if (!getDerived().AlwaysRebuild() &&
6559 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006560 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006561
Douglas Gregorb98b1992009-08-11 05:31:07 +00006562 return getDerived().RebuildImplicitValueInitExpr(T);
6563}
Mike Stump1eb44332009-09-09 15:08:12 +00006564
Douglas Gregorb98b1992009-08-11 05:31:07 +00006565template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006566ExprResult
John McCall454feb92009-12-08 09:21:05 +00006567TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006568 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6569 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006570 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006571
John McCall60d7b3a2010-08-24 06:29:42 +00006572 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006573 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006574 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006575
Douglas Gregorb98b1992009-08-11 05:31:07 +00006576 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006577 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006578 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006579 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006580
John McCall9ae2f072010-08-23 23:25:46 +00006581 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006582 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006583}
6584
6585template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006586ExprResult
John McCall454feb92009-12-08 09:21:05 +00006587TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006588 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006589 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006590 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6591 &ArgumentChanged))
6592 return ExprError();
6593
Douglas Gregorb98b1992009-08-11 05:31:07 +00006594 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6595 move_arg(Inits),
6596 E->getRParenLoc());
6597}
Mike Stump1eb44332009-09-09 15:08:12 +00006598
Douglas Gregorb98b1992009-08-11 05:31:07 +00006599/// \brief Transform an address-of-label expression.
6600///
6601/// By default, the transformation of an address-of-label expression always
6602/// rebuilds the expression, so that the label identifier can be resolved to
6603/// the corresponding label statement by semantic analysis.
6604template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006605ExprResult
John McCall454feb92009-12-08 09:21:05 +00006606TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006607 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6608 E->getLabel());
6609 if (!LD)
6610 return ExprError();
6611
Douglas Gregorb98b1992009-08-11 05:31:07 +00006612 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006613 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006614}
Mike Stump1eb44332009-09-09 15:08:12 +00006615
6616template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006617ExprResult
John McCall454feb92009-12-08 09:21:05 +00006618TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006619 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006620 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6621 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006622 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006623
Douglas Gregorb98b1992009-08-11 05:31:07 +00006624 if (!getDerived().AlwaysRebuild() &&
6625 SubStmt.get() == E->getSubStmt())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006626 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006627
6628 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006629 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006630 E->getRParenLoc());
6631}
Mike Stump1eb44332009-09-09 15:08:12 +00006632
Douglas Gregorb98b1992009-08-11 05:31:07 +00006633template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006634ExprResult
John McCall454feb92009-12-08 09:21:05 +00006635TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006636 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006637 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006638 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006639
John McCall60d7b3a2010-08-24 06:29:42 +00006640 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006641 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006642 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006643
John McCall60d7b3a2010-08-24 06:29:42 +00006644 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006645 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006646 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006647
Douglas Gregorb98b1992009-08-11 05:31:07 +00006648 if (!getDerived().AlwaysRebuild() &&
6649 Cond.get() == E->getCond() &&
6650 LHS.get() == E->getLHS() &&
6651 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006652 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006653
Douglas Gregorb98b1992009-08-11 05:31:07 +00006654 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006655 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006656 E->getRParenLoc());
6657}
Mike Stump1eb44332009-09-09 15:08:12 +00006658
Douglas Gregorb98b1992009-08-11 05:31:07 +00006659template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006660ExprResult
John McCall454feb92009-12-08 09:21:05 +00006661TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006662 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006663}
6664
6665template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006666ExprResult
John McCall454feb92009-12-08 09:21:05 +00006667TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006668 switch (E->getOperator()) {
6669 case OO_New:
6670 case OO_Delete:
6671 case OO_Array_New:
6672 case OO_Array_Delete:
6673 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00006674 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006675
Douglas Gregor668d6d92009-12-13 20:44:55 +00006676 case OO_Call: {
6677 // This is a call to an object's operator().
6678 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6679
6680 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006681 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006682 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006683 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006684
6685 // FIXME: Poor location information
6686 SourceLocation FakeLParenLoc
6687 = SemaRef.PP.getLocForEndOfToken(
6688 static_cast<Expr *>(Object.get())->getLocEnd());
6689
6690 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006691 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006692 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6693 Args))
6694 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006695
John McCall9ae2f072010-08-23 23:25:46 +00006696 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006697 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006698 E->getLocEnd());
6699 }
6700
6701#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6702 case OO_##Name:
6703#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6704#include "clang/Basic/OperatorKinds.def"
6705 case OO_Subscript:
6706 // Handled below.
6707 break;
6708
6709 case OO_Conditional:
6710 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00006711 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006712
6713 case OO_None:
6714 case NUM_OVERLOADED_OPERATORS:
6715 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00006716 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006717 }
6718
John McCall60d7b3a2010-08-24 06:29:42 +00006719 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006720 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006721 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006722
John McCall60d7b3a2010-08-24 06:29:42 +00006723 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006724 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006725 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006726
John McCall60d7b3a2010-08-24 06:29:42 +00006727 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006728 if (E->getNumArgs() == 2) {
6729 Second = getDerived().TransformExpr(E->getArg(1));
6730 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006731 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006732 }
Mike Stump1eb44332009-09-09 15:08:12 +00006733
Douglas Gregorb98b1992009-08-11 05:31:07 +00006734 if (!getDerived().AlwaysRebuild() &&
6735 Callee.get() == E->getCallee() &&
6736 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006737 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006738 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006739
Douglas Gregorb98b1992009-08-11 05:31:07 +00006740 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6741 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006742 Callee.get(),
6743 First.get(),
6744 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006745}
Mike Stump1eb44332009-09-09 15:08:12 +00006746
Douglas Gregorb98b1992009-08-11 05:31:07 +00006747template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006748ExprResult
John McCall454feb92009-12-08 09:21:05 +00006749TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6750 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006751}
Mike Stump1eb44332009-09-09 15:08:12 +00006752
Douglas Gregorb98b1992009-08-11 05:31:07 +00006753template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006754ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006755TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6756 // Transform the callee.
6757 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6758 if (Callee.isInvalid())
6759 return ExprError();
6760
6761 // Transform exec config.
6762 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6763 if (EC.isInvalid())
6764 return ExprError();
6765
6766 // Transform arguments.
6767 bool ArgChanged = false;
6768 ASTOwningVector<Expr*> Args(SemaRef);
6769 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6770 &ArgChanged))
6771 return ExprError();
6772
6773 if (!getDerived().AlwaysRebuild() &&
6774 Callee.get() == E->getCallee() &&
6775 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006776 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006777
6778 // FIXME: Wrong source location information for the '('.
6779 SourceLocation FakeLParenLoc
6780 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6781 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6782 move_arg(Args),
6783 E->getRParenLoc(), EC.get());
6784}
6785
6786template<typename Derived>
6787ExprResult
John McCall454feb92009-12-08 09:21:05 +00006788TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006789 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6790 if (!Type)
6791 return ExprError();
6792
John McCall60d7b3a2010-08-24 06:29:42 +00006793 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006794 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006795 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006796 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006797
Douglas Gregorb98b1992009-08-11 05:31:07 +00006798 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006799 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006800 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006801 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006802
Douglas Gregorb98b1992009-08-11 05:31:07 +00006803 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006804 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006805 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6806 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6807 SourceLocation FakeRParenLoc
6808 = SemaRef.PP.getLocForEndOfToken(
6809 E->getSubExpr()->getSourceRange().getEnd());
6810 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006811 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006812 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006813 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006814 FakeRAngleLoc,
6815 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006816 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006817 FakeRParenLoc);
6818}
Mike Stump1eb44332009-09-09 15:08:12 +00006819
Douglas Gregorb98b1992009-08-11 05:31:07 +00006820template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006821ExprResult
John McCall454feb92009-12-08 09:21:05 +00006822TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6823 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006824}
Mike Stump1eb44332009-09-09 15:08:12 +00006825
6826template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006827ExprResult
John McCall454feb92009-12-08 09:21:05 +00006828TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6829 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006830}
6831
Douglas Gregorb98b1992009-08-11 05:31:07 +00006832template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006833ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006834TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006835 CXXReinterpretCastExpr *E) {
6836 return getDerived().TransformCXXNamedCastExpr(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
John McCall454feb92009-12-08 09:21:05 +00006841TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6842 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006843}
Mike Stump1eb44332009-09-09 15:08:12 +00006844
Douglas Gregorb98b1992009-08-11 05:31:07 +00006845template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006846ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006847TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006848 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006849 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6850 if (!Type)
6851 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006852
John McCall60d7b3a2010-08-24 06:29:42 +00006853 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006854 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006855 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006856 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006857
Douglas Gregorb98b1992009-08-11 05:31:07 +00006858 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006859 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006860 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006861 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006862
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006863 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006864 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006865 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006866 E->getRParenLoc());
6867}
Mike Stump1eb44332009-09-09 15:08:12 +00006868
Douglas Gregorb98b1992009-08-11 05:31:07 +00006869template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006870ExprResult
John McCall454feb92009-12-08 09:21:05 +00006871TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006872 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006873 TypeSourceInfo *TInfo
6874 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6875 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006876 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006877
Douglas Gregorb98b1992009-08-11 05:31:07 +00006878 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006879 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006880 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006881
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006882 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6883 E->getLocStart(),
6884 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006885 E->getLocEnd());
6886 }
Mike Stump1eb44332009-09-09 15:08:12 +00006887
Eli Friedmanef331b72012-01-20 01:26:23 +00006888 // We don't know whether the subexpression is potentially evaluated until
6889 // after we perform semantic analysis. We speculatively assume it is
6890 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00006891 // potentially evaluated.
Eli Friedmanef331b72012-01-20 01:26:23 +00006892 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006893
John McCall60d7b3a2010-08-24 06:29:42 +00006894 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006895 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006896 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006897
Douglas Gregorb98b1992009-08-11 05:31:07 +00006898 if (!getDerived().AlwaysRebuild() &&
6899 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006900 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006901
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006902 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6903 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006904 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006905 E->getLocEnd());
6906}
6907
6908template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006909ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00006910TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6911 if (E->isTypeOperand()) {
6912 TypeSourceInfo *TInfo
6913 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6914 if (!TInfo)
6915 return ExprError();
6916
6917 if (!getDerived().AlwaysRebuild() &&
6918 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006919 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006920
Douglas Gregor3c52a212011-03-06 17:40:41 +00006921 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00006922 E->getLocStart(),
6923 TInfo,
6924 E->getLocEnd());
6925 }
6926
Francois Pichet01b7c302010-09-08 12:20:18 +00006927 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6928
6929 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6930 if (SubExpr.isInvalid())
6931 return ExprError();
6932
6933 if (!getDerived().AlwaysRebuild() &&
6934 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006935 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006936
6937 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6938 E->getLocStart(),
6939 SubExpr.get(),
6940 E->getLocEnd());
6941}
6942
6943template<typename Derived>
6944ExprResult
John McCall454feb92009-12-08 09:21:05 +00006945TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006946 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006947}
Mike Stump1eb44332009-09-09 15:08:12 +00006948
Douglas Gregorb98b1992009-08-11 05:31:07 +00006949template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006950ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006951TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00006952 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006953 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006954}
Mike Stump1eb44332009-09-09 15:08:12 +00006955
Douglas Gregorb98b1992009-08-11 05:31:07 +00006956template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006957ExprResult
John McCall454feb92009-12-08 09:21:05 +00006958TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006959 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00006960 QualType T;
6961 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
6962 T = MD->getThisType(getSema().Context);
6963 else
6964 T = getSema().Context.getPointerType(
6965 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00006966
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006967 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006968 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006969
Douglas Gregor828a1972010-01-07 23:12:05 +00006970 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006971}
Mike Stump1eb44332009-09-09 15:08:12 +00006972
Douglas Gregorb98b1992009-08-11 05:31:07 +00006973template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006974ExprResult
John McCall454feb92009-12-08 09:21:05 +00006975TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006976 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006977 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006978 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006979
Douglas Gregorb98b1992009-08-11 05:31:07 +00006980 if (!getDerived().AlwaysRebuild() &&
6981 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006982 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006983
Douglas Gregorbca01b42011-07-06 22:04:06 +00006984 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
6985 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006986}
Mike Stump1eb44332009-09-09 15:08:12 +00006987
Douglas Gregorb98b1992009-08-11 05:31:07 +00006988template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006989ExprResult
John McCall454feb92009-12-08 09:21:05 +00006990TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006991 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006992 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6993 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006994 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00006995 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006996
Chandler Carruth53cb6f82010-02-08 06:42:49 +00006997 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006998 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00006999 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007000
Douglas Gregor036aed12009-12-23 23:03:06 +00007001 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007002}
Mike Stump1eb44332009-09-09 15:08:12 +00007003
Douglas Gregorb98b1992009-08-11 05:31:07 +00007004template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007005ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007006TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7007 CXXScalarValueInitExpr *E) {
7008 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7009 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007010 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00007011
Douglas Gregorb98b1992009-08-11 05:31:07 +00007012 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007013 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007014 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007015
Douglas Gregorab6677e2010-09-08 00:15:04 +00007016 return getDerived().RebuildCXXScalarValueInitExpr(T,
7017 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007018 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007019}
Mike Stump1eb44332009-09-09 15:08:12 +00007020
Douglas Gregorb98b1992009-08-11 05:31:07 +00007021template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007022ExprResult
John McCall454feb92009-12-08 09:21:05 +00007023TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007024 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007025 TypeSourceInfo *AllocTypeInfo
7026 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7027 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007028 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007029
Douglas Gregorb98b1992009-08-11 05:31:07 +00007030 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007031 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007032 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007033 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007034
Douglas Gregorb98b1992009-08-11 05:31:07 +00007035 // Transform the placement arguments (if any).
7036 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007037 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007038 if (getDerived().TransformExprs(E->getPlacementArgs(),
7039 E->getNumPlacementArgs(), true,
7040 PlacementArgs, &ArgumentChanged))
7041 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007042
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007043 // Transform the constructor arguments (if any).
7044 // As an annoying corner case, we may have introduced an implicit value-
7045 // initialization expression when allocating a new array, which we implicitly
7046 // drop. It will be re-created during type checking.
John McCallca0408f2010-08-23 06:44:23 +00007047 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007048 if (!(E->isArray() && E->getNumConstructorArgs() == 1 &&
7049 isa<ImplicitValueInitExpr>(E->getConstructorArgs()[0])) &&
7050 TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007051 ConstructorArgs, &ArgumentChanged))
7052 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007053
Douglas Gregor1af74512010-02-26 00:38:10 +00007054 // Transform constructor, new operator, and delete operator.
7055 CXXConstructorDecl *Constructor = 0;
7056 if (E->getConstructor()) {
7057 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007058 getDerived().TransformDecl(E->getLocStart(),
7059 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007060 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007061 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007062 }
7063
7064 FunctionDecl *OperatorNew = 0;
7065 if (E->getOperatorNew()) {
7066 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007067 getDerived().TransformDecl(E->getLocStart(),
7068 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007069 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007070 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007071 }
7072
7073 FunctionDecl *OperatorDelete = 0;
7074 if (E->getOperatorDelete()) {
7075 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007076 getDerived().TransformDecl(E->getLocStart(),
7077 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007078 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007079 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007080 }
Sean Huntc3021132010-05-05 15:23:54 +00007081
Douglas Gregorb98b1992009-08-11 05:31:07 +00007082 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007083 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007084 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007085 Constructor == E->getConstructor() &&
7086 OperatorNew == E->getOperatorNew() &&
7087 OperatorDelete == E->getOperatorDelete() &&
7088 !ArgumentChanged) {
7089 // Mark any declarations we need as referenced.
7090 // FIXME: instantiation-specific.
7091 if (Constructor)
7092 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
7093 if (OperatorNew)
7094 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
7095 if (OperatorDelete)
7096 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007097
7098 if (E->isArray() && Constructor &&
7099 !E->getAllocatedType()->isDependentType()) {
7100 QualType ElementType
7101 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7102 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7103 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7104 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
7105 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Destructor);
7106 }
7107 }
7108 }
7109
John McCall3fa5cae2010-10-26 07:05:15 +00007110 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007111 }
Mike Stump1eb44332009-09-09 15:08:12 +00007112
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007113 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007114 if (!ArraySize.get()) {
7115 // If no array size was specified, but the new expression was
7116 // instantiated with an array type (e.g., "new T" where T is
7117 // instantiated with "int[4]"), extract the outer bound from the
7118 // array type as our array size. We do this with constant and
7119 // dependently-sized array types.
7120 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7121 if (!ArrayT) {
7122 // Do nothing
7123 } else if (const ConstantArrayType *ConsArrayT
7124 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00007125 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007126 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7127 ConsArrayT->getSize(),
7128 SemaRef.Context.getSizeType(),
7129 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007130 AllocType = ConsArrayT->getElementType();
7131 } else if (const DependentSizedArrayType *DepArrayT
7132 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7133 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007134 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007135 AllocType = DepArrayT->getElementType();
7136 }
7137 }
7138 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007139
Douglas Gregorb98b1992009-08-11 05:31:07 +00007140 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7141 E->isGlobalNew(),
7142 /*FIXME:*/E->getLocStart(),
7143 move_arg(PlacementArgs),
7144 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007145 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007146 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007147 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007148 ArraySize.get(),
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007149 E->getConstructorLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007150 move_arg(ConstructorArgs),
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007151 E->getConstructorRParen());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007152}
Mike Stump1eb44332009-09-09 15:08:12 +00007153
Douglas Gregorb98b1992009-08-11 05:31:07 +00007154template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007155ExprResult
John McCall454feb92009-12-08 09:21:05 +00007156TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007157 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007158 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007159 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007160
Douglas Gregor1af74512010-02-26 00:38:10 +00007161 // Transform the delete operator, if known.
7162 FunctionDecl *OperatorDelete = 0;
7163 if (E->getOperatorDelete()) {
7164 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007165 getDerived().TransformDecl(E->getLocStart(),
7166 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007167 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007168 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007169 }
Sean Huntc3021132010-05-05 15:23:54 +00007170
Douglas Gregorb98b1992009-08-11 05:31:07 +00007171 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007172 Operand.get() == E->getArgument() &&
7173 OperatorDelete == E->getOperatorDelete()) {
7174 // Mark any declarations we need as referenced.
7175 // FIXME: instantiation-specific.
7176 if (OperatorDelete)
7177 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007178
7179 if (!E->getArgument()->isTypeDependent()) {
7180 QualType Destroyed = SemaRef.Context.getBaseElementType(
7181 E->getDestroyedType());
7182 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7183 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
7184 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
7185 SemaRef.LookupDestructor(Record));
7186 }
7187 }
7188
John McCall3fa5cae2010-10-26 07:05:15 +00007189 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007190 }
Mike Stump1eb44332009-09-09 15:08:12 +00007191
Douglas Gregorb98b1992009-08-11 05:31:07 +00007192 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7193 E->isGlobalDelete(),
7194 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007195 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007196}
Mike Stump1eb44332009-09-09 15:08:12 +00007197
Douglas Gregorb98b1992009-08-11 05:31:07 +00007198template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007199ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007200TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007201 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007202 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007203 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007204 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007205
John McCallb3d87482010-08-24 05:47:05 +00007206 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007207 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007208 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007209 E->getOperatorLoc(),
7210 E->isArrow()? tok::arrow : tok::period,
7211 ObjectTypePtr,
7212 MayBePseudoDestructor);
7213 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007214 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007215
John McCallb3d87482010-08-24 05:47:05 +00007216 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007217 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7218 if (QualifierLoc) {
7219 QualifierLoc
7220 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7221 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007222 return ExprError();
7223 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007224 CXXScopeSpec SS;
7225 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007226
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007227 PseudoDestructorTypeStorage Destroyed;
7228 if (E->getDestroyedTypeInfo()) {
7229 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007230 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007231 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007232 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007233 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007234 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007235 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007236 // We aren't likely to be able to resolve the identifier down to a type
7237 // now anyway, so just retain the identifier.
7238 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7239 E->getDestroyedTypeLoc());
7240 } else {
7241 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007242 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007243 *E->getDestroyedTypeIdentifier(),
7244 E->getDestroyedTypeLoc(),
7245 /*Scope=*/0,
7246 SS, ObjectTypePtr,
7247 false);
7248 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007249 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007250
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007251 Destroyed
7252 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7253 E->getDestroyedTypeLoc());
7254 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007255
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007256 TypeSourceInfo *ScopeTypeInfo = 0;
7257 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007258 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007259 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007260 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007261 }
Sean Huntc3021132010-05-05 15:23:54 +00007262
John McCall9ae2f072010-08-23 23:25:46 +00007263 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007264 E->getOperatorLoc(),
7265 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007266 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007267 ScopeTypeInfo,
7268 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007269 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007270 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007271}
Mike Stump1eb44332009-09-09 15:08:12 +00007272
Douglas Gregora71d8192009-09-04 17:36:40 +00007273template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007274ExprResult
John McCallba135432009-11-21 08:51:07 +00007275TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007276 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007277 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7278 Sema::LookupOrdinaryName);
7279
7280 // Transform all the decls.
7281 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7282 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007283 NamedDecl *InstD = static_cast<NamedDecl*>(
7284 getDerived().TransformDecl(Old->getNameLoc(),
7285 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007286 if (!InstD) {
7287 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7288 // This can happen because of dependent hiding.
7289 if (isa<UsingShadowDecl>(*I))
7290 continue;
7291 else
John McCallf312b1e2010-08-26 23:41:50 +00007292 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007293 }
John McCallf7a1a742009-11-24 19:00:30 +00007294
7295 // Expand using declarations.
7296 if (isa<UsingDecl>(InstD)) {
7297 UsingDecl *UD = cast<UsingDecl>(InstD);
7298 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7299 E = UD->shadow_end(); I != E; ++I)
7300 R.addDecl(*I);
7301 continue;
7302 }
7303
7304 R.addDecl(InstD);
7305 }
7306
7307 // Resolve a kind, but don't do any further analysis. If it's
7308 // ambiguous, the callee needs to deal with it.
7309 R.resolveKind();
7310
7311 // Rebuild the nested-name qualifier, if present.
7312 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007313 if (Old->getQualifierLoc()) {
7314 NestedNameSpecifierLoc QualifierLoc
7315 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7316 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007317 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007318
Douglas Gregor4c9be892011-02-28 20:01:57 +00007319 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007320 }
7321
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007322 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007323 CXXRecordDecl *NamingClass
7324 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7325 Old->getNameLoc(),
7326 Old->getNamingClass()));
7327 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007328 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007329
Douglas Gregor66c45152010-04-27 16:10:10 +00007330 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007331 }
7332
7333 // If we have no template arguments, it's a normal declaration name.
7334 if (!Old->hasExplicitTemplateArgs())
7335 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7336
7337 // If we have template arguments, rebuild them, then rebuild the
7338 // templateid expression.
7339 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007340 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7341 Old->getNumTemplateArgs(),
7342 TransArgs))
7343 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007344
7345 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7346 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007347}
Mike Stump1eb44332009-09-09 15:08:12 +00007348
Douglas Gregorb98b1992009-08-11 05:31:07 +00007349template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007350ExprResult
John McCall454feb92009-12-08 09:21:05 +00007351TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007352 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7353 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007354 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007355
Douglas Gregorb98b1992009-08-11 05:31:07 +00007356 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007357 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007358 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007359
Mike Stump1eb44332009-09-09 15:08:12 +00007360 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007361 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007362 T,
7363 E->getLocEnd());
7364}
Mike Stump1eb44332009-09-09 15:08:12 +00007365
Douglas Gregorb98b1992009-08-11 05:31:07 +00007366template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007367ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007368TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7369 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7370 if (!LhsT)
7371 return ExprError();
7372
7373 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7374 if (!RhsT)
7375 return ExprError();
7376
7377 if (!getDerived().AlwaysRebuild() &&
7378 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7379 return SemaRef.Owned(E);
7380
7381 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7382 E->getLocStart(),
7383 LhsT, RhsT,
7384 E->getLocEnd());
7385}
7386
7387template<typename Derived>
7388ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007389TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7390 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7391 if (!T)
7392 return ExprError();
7393
7394 if (!getDerived().AlwaysRebuild() &&
7395 T == E->getQueriedTypeSourceInfo())
7396 return SemaRef.Owned(E);
7397
7398 ExprResult SubExpr;
7399 {
7400 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7401 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7402 if (SubExpr.isInvalid())
7403 return ExprError();
7404
7405 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7406 return SemaRef.Owned(E);
7407 }
7408
7409 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7410 E->getLocStart(),
7411 T,
7412 SubExpr.get(),
7413 E->getLocEnd());
7414}
7415
7416template<typename Derived>
7417ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007418TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7419 ExprResult SubExpr;
7420 {
7421 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7422 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7423 if (SubExpr.isInvalid())
7424 return ExprError();
7425
7426 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7427 return SemaRef.Owned(E);
7428 }
7429
7430 return getDerived().RebuildExpressionTrait(
7431 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7432}
7433
7434template<typename Derived>
7435ExprResult
John McCall865d4472009-11-19 22:55:06 +00007436TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007437 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007438 NestedNameSpecifierLoc QualifierLoc
7439 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7440 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007441 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007442
John McCall43fed0d2010-11-12 08:19:04 +00007443 // TODO: If this is a conversion-function-id, verify that the
7444 // destination type name (if present) resolves the same way after
7445 // instantiation as it did in the local scope.
7446
Abramo Bagnara25777432010-08-11 22:01:17 +00007447 DeclarationNameInfo NameInfo
7448 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7449 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007450 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007451
John McCallf7a1a742009-11-24 19:00:30 +00007452 if (!E->hasExplicitTemplateArgs()) {
7453 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007454 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007455 // Note: it is sufficient to compare the Name component of NameInfo:
7456 // if name has not changed, DNLoc has not changed either.
7457 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007458 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007459
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007460 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007461 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007462 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007463 }
John McCalld5532b62009-11-23 01:53:49 +00007464
7465 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007466 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7467 E->getNumTemplateArgs(),
7468 TransArgs))
7469 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007470
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007471 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007472 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007473 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007474}
7475
7476template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007477ExprResult
John McCall454feb92009-12-08 09:21:05 +00007478TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007479 // CXXConstructExprs are always implicit, so when we have a
7480 // 1-argument construction we just transform that argument.
7481 if (E->getNumArgs() == 1 ||
7482 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7483 return getDerived().TransformExpr(E->getArg(0));
7484
Douglas Gregorb98b1992009-08-11 05:31:07 +00007485 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7486
7487 QualType T = getDerived().TransformType(E->getType());
7488 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007489 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007490
7491 CXXConstructorDecl *Constructor
7492 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007493 getDerived().TransformDecl(E->getLocStart(),
7494 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007495 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007496 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007497
Douglas Gregorb98b1992009-08-11 05:31:07 +00007498 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007499 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007500 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7501 &ArgumentChanged))
7502 return ExprError();
7503
Douglas Gregorb98b1992009-08-11 05:31:07 +00007504 if (!getDerived().AlwaysRebuild() &&
7505 T == E->getType() &&
7506 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007507 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007508 // Mark the constructor as referenced.
7509 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00007510 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007511 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007512 }
Mike Stump1eb44332009-09-09 15:08:12 +00007513
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007514 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7515 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007516 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007517 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007518 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007519 E->getConstructionKind(),
7520 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007521}
Mike Stump1eb44332009-09-09 15:08:12 +00007522
Douglas Gregorb98b1992009-08-11 05:31:07 +00007523/// \brief Transform a C++ temporary-binding expression.
7524///
Douglas Gregor51326552009-12-24 18:51:59 +00007525/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7526/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007527template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007528ExprResult
John McCall454feb92009-12-08 09:21:05 +00007529TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007530 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007531}
Mike Stump1eb44332009-09-09 15:08:12 +00007532
John McCall4765fa02010-12-06 08:20:24 +00007533/// \brief Transform a C++ expression that contains cleanups that should
7534/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007535///
John McCall4765fa02010-12-06 08:20:24 +00007536/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007537/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007538template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007539ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007540TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007541 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007542}
Mike Stump1eb44332009-09-09 15:08:12 +00007543
Douglas Gregorb98b1992009-08-11 05:31:07 +00007544template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007545ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007546TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007547 CXXTemporaryObjectExpr *E) {
7548 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7549 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007550 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007551
Douglas Gregorb98b1992009-08-11 05:31:07 +00007552 CXXConstructorDecl *Constructor
7553 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007554 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007555 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007556 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007557 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007558
Douglas Gregorb98b1992009-08-11 05:31:07 +00007559 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007560 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007561 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007562 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7563 &ArgumentChanged))
7564 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007565
Douglas Gregorb98b1992009-08-11 05:31:07 +00007566 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007567 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007568 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007569 !ArgumentChanged) {
7570 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00007571 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007572 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007573 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007574
7575 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7576 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007577 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007578 E->getLocEnd());
7579}
Mike Stump1eb44332009-09-09 15:08:12 +00007580
Douglas Gregorb98b1992009-08-11 05:31:07 +00007581template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007582ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007583TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007584 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007585 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7586 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007587 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007588
Douglas Gregorb98b1992009-08-11 05:31:07 +00007589 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007590 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007591 Args.reserve(E->arg_size());
7592 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7593 &ArgumentChanged))
7594 return ExprError();
7595
Douglas Gregorb98b1992009-08-11 05:31:07 +00007596 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007597 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007598 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007599 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007600
Douglas Gregorb98b1992009-08-11 05:31:07 +00007601 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00007602 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007603 E->getLParenLoc(),
7604 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007605 E->getRParenLoc());
7606}
Mike Stump1eb44332009-09-09 15:08:12 +00007607
Douglas Gregorb98b1992009-08-11 05:31:07 +00007608template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007609ExprResult
John McCall865d4472009-11-19 22:55:06 +00007610TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007611 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007612 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007613 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007614 Expr *OldBase;
7615 QualType BaseType;
7616 QualType ObjectType;
7617 if (!E->isImplicitAccess()) {
7618 OldBase = E->getBase();
7619 Base = getDerived().TransformExpr(OldBase);
7620 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007621 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007622
John McCallaa81e162009-12-01 22:10:20 +00007623 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00007624 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00007625 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007626 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007627 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00007628 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00007629 ObjectTy,
7630 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00007631 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007632 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007633
John McCallb3d87482010-08-24 05:47:05 +00007634 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00007635 BaseType = ((Expr*) Base.get())->getType();
7636 } else {
7637 OldBase = 0;
7638 BaseType = getDerived().TransformType(E->getBaseType());
7639 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7640 }
Mike Stump1eb44332009-09-09 15:08:12 +00007641
Douglas Gregor6cd21982009-10-20 05:58:46 +00007642 // Transform the first part of the nested-name-specifier that qualifies
7643 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00007644 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00007645 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007646 E->getFirstQualifierFoundInScope(),
7647 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00007648
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007649 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00007650 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007651 QualifierLoc
7652 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7653 ObjectType,
7654 FirstQualifierInScope);
7655 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007656 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00007657 }
Mike Stump1eb44332009-09-09 15:08:12 +00007658
John McCall43fed0d2010-11-12 08:19:04 +00007659 // TODO: If this is a conversion-function-id, verify that the
7660 // destination type name (if present) resolves the same way after
7661 // instantiation as it did in the local scope.
7662
Abramo Bagnara25777432010-08-11 22:01:17 +00007663 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00007664 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00007665 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007666 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007667
John McCallaa81e162009-12-01 22:10:20 +00007668 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007669 // This is a reference to a member without an explicitly-specified
7670 // template argument list. Optimize for this common case.
7671 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00007672 Base.get() == OldBase &&
7673 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007674 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007675 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007676 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00007677 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007678
John McCall9ae2f072010-08-23 23:25:46 +00007679 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007680 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007681 E->isArrow(),
7682 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007683 QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00007684 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007685 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007686 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007687 }
7688
John McCalld5532b62009-11-23 01:53:49 +00007689 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007690 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7691 E->getNumTemplateArgs(),
7692 TransArgs))
7693 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007694
John McCall9ae2f072010-08-23 23:25:46 +00007695 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007696 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007697 E->isArrow(),
7698 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007699 QualifierLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007700 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007701 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007702 &TransArgs);
7703}
7704
7705template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007706ExprResult
John McCall454feb92009-12-08 09:21:05 +00007707TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00007708 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007709 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007710 QualType BaseType;
7711 if (!Old->isImplicitAccess()) {
7712 Base = getDerived().TransformExpr(Old->getBase());
7713 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007714 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00007715 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
7716 Old->isArrow());
7717 if (Base.isInvalid())
7718 return ExprError();
7719 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00007720 } else {
7721 BaseType = getDerived().TransformType(Old->getBaseType());
7722 }
John McCall129e2df2009-11-30 22:42:35 +00007723
Douglas Gregor4c9be892011-02-28 20:01:57 +00007724 NestedNameSpecifierLoc QualifierLoc;
7725 if (Old->getQualifierLoc()) {
7726 QualifierLoc
7727 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7728 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007729 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007730 }
7731
Abramo Bagnara25777432010-08-11 22:01:17 +00007732 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00007733 Sema::LookupOrdinaryName);
7734
7735 // Transform all the decls.
7736 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7737 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007738 NamedDecl *InstD = static_cast<NamedDecl*>(
7739 getDerived().TransformDecl(Old->getMemberLoc(),
7740 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007741 if (!InstD) {
7742 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7743 // This can happen because of dependent hiding.
7744 if (isa<UsingShadowDecl>(*I))
7745 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007746 else {
7747 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007748 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007749 }
John McCall9f54ad42009-12-10 09:41:52 +00007750 }
John McCall129e2df2009-11-30 22:42:35 +00007751
7752 // Expand using declarations.
7753 if (isa<UsingDecl>(InstD)) {
7754 UsingDecl *UD = cast<UsingDecl>(InstD);
7755 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7756 E = UD->shadow_end(); I != E; ++I)
7757 R.addDecl(*I);
7758 continue;
7759 }
7760
7761 R.addDecl(InstD);
7762 }
7763
7764 R.resolveKind();
7765
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007766 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00007767 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00007768 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007769 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00007770 Old->getMemberLoc(),
7771 Old->getNamingClass()));
7772 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007773 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007774
Douglas Gregor66c45152010-04-27 16:10:10 +00007775 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007776 }
Sean Huntc3021132010-05-05 15:23:54 +00007777
John McCall129e2df2009-11-30 22:42:35 +00007778 TemplateArgumentListInfo TransArgs;
7779 if (Old->hasExplicitTemplateArgs()) {
7780 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7781 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007782 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7783 Old->getNumTemplateArgs(),
7784 TransArgs))
7785 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007786 }
John McCallc2233c52010-01-15 08:34:02 +00007787
7788 // FIXME: to do this check properly, we will need to preserve the
7789 // first-qualifier-in-scope here, just in case we had a dependent
7790 // base (and therefore couldn't do the check) and a
7791 // nested-name-qualifier (and therefore could do the lookup).
7792 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00007793
John McCall9ae2f072010-08-23 23:25:46 +00007794 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007795 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00007796 Old->getOperatorLoc(),
7797 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00007798 QualifierLoc,
John McCallc2233c52010-01-15 08:34:02 +00007799 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00007800 R,
7801 (Old->hasExplicitTemplateArgs()
7802 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007803}
7804
7805template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007806ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00007807TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00007808 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00007809 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7810 if (SubExpr.isInvalid())
7811 return ExprError();
7812
7813 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007814 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00007815
7816 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7817}
7818
7819template<typename Derived>
7820ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00007821TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00007822 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7823 if (Pattern.isInvalid())
7824 return ExprError();
7825
7826 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7827 return SemaRef.Owned(E);
7828
Douglas Gregor67fd1252011-01-14 21:20:45 +00007829 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7830 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00007831}
Douglas Gregoree8aff02011-01-04 17:33:58 +00007832
7833template<typename Derived>
7834ExprResult
7835TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7836 // If E is not value-dependent, then nothing will change when we transform it.
7837 // Note: This is an instantiation-centric view.
7838 if (!E->isValueDependent())
7839 return SemaRef.Owned(E);
7840
7841 // Note: None of the implementations of TryExpandParameterPacks can ever
7842 // produce a diagnostic when given only a single unexpanded parameter pack,
7843 // so
7844 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7845 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00007846 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00007847 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00007848 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00007849 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00007850 ShouldExpand, RetainExpansion,
7851 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00007852 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00007853
Douglas Gregor089e8932011-10-10 18:59:29 +00007854 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00007855 return SemaRef.Owned(E);
Douglas Gregor089e8932011-10-10 18:59:29 +00007856
7857 NamedDecl *Pack = E->getPack();
7858 if (!ShouldExpand) {
7859 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
7860 Pack));
7861 if (!Pack)
7862 return ExprError();
7863 }
7864
Douglas Gregoree8aff02011-01-04 17:33:58 +00007865
7866 // We now know the length of the parameter pack, so build a new expression
7867 // that stores that length.
Douglas Gregor089e8932011-10-10 18:59:29 +00007868 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregoree8aff02011-01-04 17:33:58 +00007869 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00007870 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00007871}
7872
Douglas Gregorbe230c32011-01-03 17:17:50 +00007873template<typename Derived>
7874ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00007875TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7876 SubstNonTypeTemplateParmPackExpr *E) {
7877 // Default behavior is to do nothing with this transformation.
7878 return SemaRef.Owned(E);
7879}
7880
7881template<typename Derived>
7882ExprResult
John McCall91a57552011-07-15 05:09:51 +00007883TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
7884 SubstNonTypeTemplateParmExpr *E) {
7885 // Default behavior is to do nothing with this transformation.
7886 return SemaRef.Owned(E);
7887}
7888
7889template<typename Derived>
7890ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00007891TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
7892 MaterializeTemporaryExpr *E) {
7893 return getDerived().TransformExpr(E->GetTemporaryExpr());
7894}
7895
7896template<typename Derived>
7897ExprResult
John McCall454feb92009-12-08 09:21:05 +00007898TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007899 return SemaRef.Owned(E);
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>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00007905 TypeSourceInfo *EncodedTypeInfo
7906 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7907 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007908 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007909
Douglas Gregorb98b1992009-08-11 05:31:07 +00007910 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00007911 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007912 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007913
7914 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00007915 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007916 E->getRParenLoc());
7917}
Mike Stump1eb44332009-09-09 15:08:12 +00007918
Douglas Gregorb98b1992009-08-11 05:31:07 +00007919template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00007920ExprResult TreeTransform<Derived>::
7921TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7922 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7923 if (result.isInvalid()) return ExprError();
7924 Expr *subExpr = result.take();
7925
7926 if (!getDerived().AlwaysRebuild() &&
7927 subExpr == E->getSubExpr())
7928 return SemaRef.Owned(E);
7929
7930 return SemaRef.Owned(new(SemaRef.Context)
7931 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7932}
7933
7934template<typename Derived>
7935ExprResult TreeTransform<Derived>::
7936TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7937 TypeSourceInfo *TSInfo
7938 = getDerived().TransformType(E->getTypeInfoAsWritten());
7939 if (!TSInfo)
7940 return ExprError();
7941
7942 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7943 if (Result.isInvalid())
7944 return ExprError();
7945
7946 if (!getDerived().AlwaysRebuild() &&
7947 TSInfo == E->getTypeInfoAsWritten() &&
7948 Result.get() == E->getSubExpr())
7949 return SemaRef.Owned(E);
7950
7951 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
7952 E->getBridgeKeywordLoc(), TSInfo,
7953 Result.get());
7954}
7955
7956template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007957ExprResult
John McCall454feb92009-12-08 09:21:05 +00007958TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00007959 // Transform arguments.
7960 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007961 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007962 Args.reserve(E->getNumArgs());
7963 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7964 &ArgChanged))
7965 return ExprError();
7966
Douglas Gregor92e986e2010-04-22 16:44:27 +00007967 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7968 // Class message: transform the receiver type.
7969 TypeSourceInfo *ReceiverTypeInfo
7970 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7971 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007972 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007973
Douglas Gregor92e986e2010-04-22 16:44:27 +00007974 // If nothing changed, just retain the existing message send.
7975 if (!getDerived().AlwaysRebuild() &&
7976 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007977 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00007978
7979 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00007980 SmallVector<SourceLocation, 16> SelLocs;
7981 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00007982 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7983 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00007984 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00007985 E->getMethodDecl(),
7986 E->getLeftLoc(),
7987 move_arg(Args),
7988 E->getRightLoc());
7989 }
7990
7991 // Instance message: transform the receiver
7992 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7993 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00007994 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00007995 = getDerived().TransformExpr(E->getInstanceReceiver());
7996 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007997 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00007998
7999 // If nothing changed, just retain the existing message send.
8000 if (!getDerived().AlwaysRebuild() &&
8001 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008002 return SemaRef.MaybeBindToTemporary(E);
Sean Huntc3021132010-05-05 15:23:54 +00008003
Douglas Gregor92e986e2010-04-22 16:44:27 +00008004 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008005 SmallVector<SourceLocation, 16> SelLocs;
8006 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008007 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008008 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008009 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008010 E->getMethodDecl(),
8011 E->getLeftLoc(),
8012 move_arg(Args),
8013 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008014}
8015
Mike Stump1eb44332009-09-09 15:08:12 +00008016template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008017ExprResult
John McCall454feb92009-12-08 09:21:05 +00008018TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008019 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008020}
8021
Mike Stump1eb44332009-09-09 15:08:12 +00008022template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008023ExprResult
John McCall454feb92009-12-08 09:21:05 +00008024TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008025 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008026}
8027
Mike Stump1eb44332009-09-09 15:08:12 +00008028template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008029ExprResult
John McCall454feb92009-12-08 09:21:05 +00008030TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008031 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008032 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008033 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008034 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008035
8036 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008037
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008038 // If nothing changed, just retain the existing expression.
8039 if (!getDerived().AlwaysRebuild() &&
8040 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008041 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008042
John McCall9ae2f072010-08-23 23:25:46 +00008043 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008044 E->getLocation(),
8045 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008046}
8047
Mike Stump1eb44332009-09-09 15:08:12 +00008048template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008049ExprResult
John McCall454feb92009-12-08 09:21:05 +00008050TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008051 // 'super' and types never change. Property never changes. Just
8052 // retain the existing expression.
8053 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008054 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00008055
Douglas Gregore3303542010-04-26 20:47:02 +00008056 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008057 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008058 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008059 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008060
Douglas Gregore3303542010-04-26 20:47:02 +00008061 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008062
Douglas Gregore3303542010-04-26 20:47:02 +00008063 // If nothing changed, just retain the existing expression.
8064 if (!getDerived().AlwaysRebuild() &&
8065 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008066 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008067
John McCall12f78a62010-12-02 01:19:52 +00008068 if (E->isExplicitProperty())
8069 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8070 E->getExplicitProperty(),
8071 E->getLocation());
8072
8073 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008074 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008075 E->getImplicitPropertyGetter(),
8076 E->getImplicitPropertySetter(),
8077 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008078}
8079
Mike Stump1eb44332009-09-09 15:08:12 +00008080template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008081ExprResult
John McCall454feb92009-12-08 09:21:05 +00008082TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008083 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008084 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008085 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008086 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008087
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008088 // If nothing changed, just retain the existing expression.
8089 if (!getDerived().AlwaysRebuild() &&
8090 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008091 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008092
John McCall9ae2f072010-08-23 23:25:46 +00008093 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008094 E->isArrow());
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>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008100 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008101 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008102 SubExprs.reserve(E->getNumSubExprs());
8103 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8104 SubExprs, &ArgumentChanged))
8105 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008106
Douglas Gregorb98b1992009-08-11 05:31:07 +00008107 if (!getDerived().AlwaysRebuild() &&
8108 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008109 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008110
Douglas Gregorb98b1992009-08-11 05:31:07 +00008111 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8112 move_arg(SubExprs),
8113 E->getRParenLoc());
8114}
8115
Mike Stump1eb44332009-09-09 15:08:12 +00008116template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008117ExprResult
John McCall454feb92009-12-08 09:21:05 +00008118TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008119 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008120
John McCallc6ac9c32011-02-04 18:33:18 +00008121 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8122 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8123
8124 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008125 blockScope->TheDecl->setBlockMissingReturnType(
8126 oldBlock->blockMissingReturnType());
Fariborz Jahanianff365592011-05-05 17:18:12 +00008127
Chris Lattner686775d2011-07-20 06:58:45 +00008128 SmallVector<ParmVarDecl*, 4> params;
8129 SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008130
8131 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008132 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8133 oldBlock->param_begin(),
8134 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008135 0, paramTypes, &params)) {
8136 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008137 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008138 }
John McCallc6ac9c32011-02-04 18:33:18 +00008139
8140 const FunctionType *exprFunctionType = E->getFunctionType();
8141 QualType exprResultType = exprFunctionType->getResultType();
8142 if (!exprResultType.isNull()) {
8143 if (!exprResultType->isDependentType())
8144 blockScope->ReturnType = exprResultType;
8145 else if (exprResultType != getSema().Context.DependentTy)
8146 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008147 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00008148
8149 // If the return type has not been determined yet, leave it as a dependent
8150 // type; it'll get set when we process the body.
John McCallc6ac9c32011-02-04 18:33:18 +00008151 if (blockScope->ReturnType.isNull())
8152 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregora779d9c2011-01-19 21:32:01 +00008153
8154 // Don't allow returning a objc interface by value.
John McCallc6ac9c32011-02-04 18:33:18 +00008155 if (blockScope->ReturnType->isObjCObjectType()) {
8156 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00008157 diag::err_object_cannot_be_passed_returned_by_value)
John McCallc6ac9c32011-02-04 18:33:18 +00008158 << 0 << blockScope->ReturnType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008159 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008160 return ExprError();
8161 }
John McCall711c52b2011-01-05 12:14:39 +00008162
John McCallc6ac9c32011-02-04 18:33:18 +00008163 QualType functionType = getDerived().RebuildFunctionProtoType(
8164 blockScope->ReturnType,
8165 paramTypes.data(),
8166 paramTypes.size(),
8167 oldBlock->isVariadic(),
Douglas Gregorc938c162011-01-26 05:01:58 +00008168 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008169 exprFunctionType->getExtInfo());
8170 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008171
8172 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008173 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008174 blockScope->TheDecl->setParams(params);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008175
8176 // If the return type wasn't explicitly set, it will have been marked as a
8177 // dependent type (DependentTy); clear out the return type setting so
8178 // we will deduce the return type when type-checking the block's body.
John McCallc6ac9c32011-02-04 18:33:18 +00008179 if (blockScope->ReturnType == getSema().Context.DependentTy)
8180 blockScope->ReturnType = QualType();
Douglas Gregora779d9c2011-01-19 21:32:01 +00008181
John McCall711c52b2011-01-05 12:14:39 +00008182 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008183 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008184 if (body.isInvalid()) {
8185 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008186 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008187 }
John McCall711c52b2011-01-05 12:14:39 +00008188
John McCallc6ac9c32011-02-04 18:33:18 +00008189#ifndef NDEBUG
8190 // In builds with assertions, make sure that we captured everything we
8191 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008192 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8193 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8194 e = oldBlock->capture_end(); i != e; ++i) {
8195 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008196
Douglas Gregorfc921372011-05-20 15:32:55 +00008197 // Ignore parameter packs.
8198 if (isa<ParmVarDecl>(oldCapture) &&
8199 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8200 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008201
Douglas Gregorfc921372011-05-20 15:32:55 +00008202 VarDecl *newCapture =
8203 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8204 oldCapture));
8205 assert(blockScope->CaptureMap.count(newCapture));
8206 }
John McCallc6ac9c32011-02-04 18:33:18 +00008207 }
8208#endif
8209
8210 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8211 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008212}
8213
Mike Stump1eb44332009-09-09 15:08:12 +00008214template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008215ExprResult
John McCall454feb92009-12-08 09:21:05 +00008216TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008217 ValueDecl *ND
8218 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8219 E->getDecl()));
8220 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00008221 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00008222
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008223 if (!getDerived().AlwaysRebuild() &&
8224 ND == E->getDecl()) {
8225 // Mark it referenced in the new context regardless.
8226 // FIXME: this is a bit instantiation-specific.
8227 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
8228
John McCall3fa5cae2010-10-26 07:05:15 +00008229 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008230 }
8231
Abramo Bagnara25777432010-08-11 22:01:17 +00008232 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregor40d96a62011-02-28 21:54:11 +00008233 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnara25777432010-08-11 22:01:17 +00008234 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008235}
Mike Stump1eb44332009-09-09 15:08:12 +00008236
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008237template<typename Derived>
8238ExprResult
8239TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008240 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008241}
Eli Friedman276b0612011-10-11 02:20:01 +00008242
8243template<typename Derived>
8244ExprResult
8245TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008246 QualType RetTy = getDerived().TransformType(E->getType());
8247 bool ArgumentChanged = false;
8248 ASTOwningVector<Expr*> SubExprs(SemaRef);
8249 SubExprs.reserve(E->getNumSubExprs());
8250 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8251 SubExprs, &ArgumentChanged))
8252 return ExprError();
8253
8254 if (!getDerived().AlwaysRebuild() &&
8255 !ArgumentChanged)
8256 return SemaRef.Owned(E);
8257
8258 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8259 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008260}
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008261
Douglas Gregorb98b1992009-08-11 05:31:07 +00008262//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008263// Type reconstruction
8264//===----------------------------------------------------------------------===//
8265
Mike Stump1eb44332009-09-09 15:08:12 +00008266template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008267QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8268 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008269 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008270 getDerived().getBaseEntity());
8271}
8272
Mike Stump1eb44332009-09-09 15:08:12 +00008273template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008274QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8275 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008276 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008277 getDerived().getBaseEntity());
8278}
8279
Mike Stump1eb44332009-09-09 15:08:12 +00008280template<typename Derived>
8281QualType
John McCall85737a72009-10-30 00:06:24 +00008282TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8283 bool WrittenAsLValue,
8284 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008285 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008286 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008287}
8288
8289template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008290QualType
John McCall85737a72009-10-30 00:06:24 +00008291TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8292 QualType ClassType,
8293 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008294 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008295 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008296}
8297
8298template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008299QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008300TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8301 ArrayType::ArraySizeModifier SizeMod,
8302 const llvm::APInt *Size,
8303 Expr *SizeExpr,
8304 unsigned IndexTypeQuals,
8305 SourceRange BracketsRange) {
8306 if (SizeExpr || !Size)
8307 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8308 IndexTypeQuals, BracketsRange,
8309 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008310
8311 QualType Types[] = {
8312 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8313 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8314 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008315 };
8316 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8317 QualType SizeType;
8318 for (unsigned I = 0; I != NumTypes; ++I)
8319 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8320 SizeType = Types[I];
8321 break;
8322 }
Mike Stump1eb44332009-09-09 15:08:12 +00008323
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008324 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
8325 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00008326 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008327 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008328 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008329}
Mike Stump1eb44332009-09-09 15:08:12 +00008330
Douglas Gregor577f75a2009-08-04 16:50:30 +00008331template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008332QualType
8333TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008334 ArrayType::ArraySizeModifier SizeMod,
8335 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008336 unsigned IndexTypeQuals,
8337 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008338 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008339 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008340}
8341
8342template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008343QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008344TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008345 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008346 unsigned IndexTypeQuals,
8347 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008348 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008349 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008350}
Mike Stump1eb44332009-09-09 15:08:12 +00008351
Douglas Gregor577f75a2009-08-04 16:50:30 +00008352template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008353QualType
8354TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008355 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008356 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008357 unsigned IndexTypeQuals,
8358 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008359 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008360 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008361 IndexTypeQuals, BracketsRange);
8362}
8363
8364template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008365QualType
8366TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008367 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008368 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008369 unsigned IndexTypeQuals,
8370 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008371 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008372 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008373 IndexTypeQuals, BracketsRange);
8374}
8375
8376template<typename Derived>
8377QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008378 unsigned NumElements,
8379 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008380 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008381 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008382}
Mike Stump1eb44332009-09-09 15:08:12 +00008383
Douglas Gregor577f75a2009-08-04 16:50:30 +00008384template<typename Derived>
8385QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8386 unsigned NumElements,
8387 SourceLocation AttributeLoc) {
8388 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8389 NumElements, true);
8390 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008391 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8392 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008393 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008394}
Mike Stump1eb44332009-09-09 15:08:12 +00008395
Douglas Gregor577f75a2009-08-04 16:50:30 +00008396template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008397QualType
8398TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008399 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008400 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008401 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008402}
Mike Stump1eb44332009-09-09 15:08:12 +00008403
Douglas Gregor577f75a2009-08-04 16:50:30 +00008404template<typename Derived>
8405QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00008406 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008407 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00008408 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00008409 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00008410 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00008411 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00008412 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregorc938c162011-01-26 05:01:58 +00008413 Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008414 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00008415 getDerived().getBaseEntity(),
8416 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008417}
Mike Stump1eb44332009-09-09 15:08:12 +00008418
Douglas Gregor577f75a2009-08-04 16:50:30 +00008419template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00008420QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8421 return SemaRef.Context.getFunctionNoProtoType(T);
8422}
8423
8424template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00008425QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8426 assert(D && "no decl found");
8427 if (D->isInvalidDecl()) return QualType();
8428
Douglas Gregor92e986e2010-04-22 16:44:27 +00008429 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00008430 TypeDecl *Ty;
8431 if (isa<UsingDecl>(D)) {
8432 UsingDecl *Using = cast<UsingDecl>(D);
8433 assert(Using->isTypeName() &&
8434 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8435
8436 // A valid resolved using typename decl points to exactly one type decl.
8437 assert(++Using->shadow_begin() == Using->shadow_end());
8438 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00008439
John McCalled976492009-12-04 22:46:56 +00008440 } else {
8441 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8442 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8443 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8444 }
8445
8446 return SemaRef.Context.getTypeDeclType(Ty);
8447}
8448
8449template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008450QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8451 SourceLocation Loc) {
8452 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008453}
8454
8455template<typename Derived>
8456QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8457 return SemaRef.Context.getTypeOfType(Underlying);
8458}
8459
8460template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008461QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8462 SourceLocation Loc) {
8463 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008464}
8465
8466template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00008467QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8468 UnaryTransformType::UTTKind UKind,
8469 SourceLocation Loc) {
8470 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8471}
8472
8473template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00008474QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00008475 TemplateName Template,
8476 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00008477 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00008478 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008479}
Mike Stump1eb44332009-09-09 15:08:12 +00008480
Douglas Gregordcee1a12009-08-06 05:28:30 +00008481template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00008482QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
8483 SourceLocation KWLoc) {
8484 return SemaRef.BuildAtomicType(ValueType, KWLoc);
8485}
8486
8487template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008488TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008489TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00008490 bool TemplateKW,
8491 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008492 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00008493 Template);
8494}
8495
8496template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008497TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008498TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8499 const IdentifierInfo &Name,
8500 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00008501 QualType ObjectType,
8502 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008503 UnqualifiedId TemplateName;
8504 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008505 Sema::TemplateTy Template;
8506 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008507 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008508 SS,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008509 TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00008510 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008511 /*EnteringContext=*/false,
8512 Template);
John McCall43fed0d2010-11-12 08:19:04 +00008513 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00008514}
Mike Stump1eb44332009-09-09 15:08:12 +00008515
Douglas Gregorb98b1992009-08-11 05:31:07 +00008516template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008517TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008518TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008519 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008520 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008521 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008522 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008523 // FIXME: Bogus location information.
8524 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8525 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008526 Sema::TemplateTy Template;
8527 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008528 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008529 SS,
8530 Name,
John McCallb3d87482010-08-24 05:47:05 +00008531 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008532 /*EnteringContext=*/false,
8533 Template);
8534 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008535}
Sean Huntc3021132010-05-05 15:23:54 +00008536
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008537template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008538ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008539TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8540 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00008541 Expr *OrigCallee,
8542 Expr *First,
8543 Expr *Second) {
8544 Expr *Callee = OrigCallee->IgnoreParenCasts();
8545 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00008546
Douglas Gregorb98b1992009-08-11 05:31:07 +00008547 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00008548 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00008549 if (!First->getType()->isOverloadableType() &&
8550 !Second->getType()->isOverloadableType())
8551 return getSema().CreateBuiltinArraySubscriptExpr(First,
8552 Callee->getLocStart(),
8553 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00008554 } else if (Op == OO_Arrow) {
8555 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00008556 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8557 } else if (Second == 0 || isPostIncDec) {
8558 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008559 // The argument is not of overloadable type, so try to create a
8560 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00008561 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008562 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00008563
John McCall9ae2f072010-08-23 23:25:46 +00008564 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008565 }
8566 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008567 if (!First->getType()->isOverloadableType() &&
8568 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008569 // Neither of the arguments is an overloadable type, so try to
8570 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00008571 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008572 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00008573 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008574 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008575 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008576
Douglas Gregorb98b1992009-08-11 05:31:07 +00008577 return move(Result);
8578 }
8579 }
Mike Stump1eb44332009-09-09 15:08:12 +00008580
8581 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00008582 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00008583 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00008584
John McCall9ae2f072010-08-23 23:25:46 +00008585 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00008586 assert(ULE->requiresADL());
8587
8588 // FIXME: Do we have to check
8589 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00008590 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00008591 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008592 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00008593 }
Mike Stump1eb44332009-09-09 15:08:12 +00008594
Douglas Gregorb98b1992009-08-11 05:31:07 +00008595 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00008596 Expr *Args[2] = { First, Second };
8597 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00008598
Douglas Gregorb98b1992009-08-11 05:31:07 +00008599 // Create the overloaded operator invocation for unary operators.
8600 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00008601 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008602 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00008603 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008604 }
Mike Stump1eb44332009-09-09 15:08:12 +00008605
Douglas Gregor5b8968c2011-07-15 16:25:15 +00008606 if (Op == OO_Subscript) {
8607 SourceLocation LBrace;
8608 SourceLocation RBrace;
8609
8610 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
8611 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
8612 LBrace = SourceLocation::getFromRawEncoding(
8613 NameLoc.CXXOperatorName.BeginOpNameLoc);
8614 RBrace = SourceLocation::getFromRawEncoding(
8615 NameLoc.CXXOperatorName.EndOpNameLoc);
8616 } else {
8617 LBrace = Callee->getLocStart();
8618 RBrace = OpLoc;
8619 }
8620
8621 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
8622 First, Second);
8623 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00008624
Douglas Gregorb98b1992009-08-11 05:31:07 +00008625 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00008626 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008627 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00008628 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8629 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008630 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008631
Mike Stump1eb44332009-09-09 15:08:12 +00008632 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008633}
Mike Stump1eb44332009-09-09 15:08:12 +00008634
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008635template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008636ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00008637TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008638 SourceLocation OperatorLoc,
8639 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00008640 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008641 TypeSourceInfo *ScopeType,
8642 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008643 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008644 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00008645 QualType BaseType = Base->getType();
8646 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008647 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00008648 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00008649 !BaseType->getAs<PointerType>()->getPointeeType()
8650 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008651 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00008652 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008653 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008654 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008655 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008656 /*FIXME?*/true);
8657 }
Abramo Bagnara25777432010-08-11 22:01:17 +00008658
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008659 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00008660 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8661 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8662 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8663 NameInfo.setNamedTypeInfo(DestroyedType);
8664
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008665 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00008666
John McCall9ae2f072010-08-23 23:25:46 +00008667 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008668 OperatorLoc, isArrow,
8669 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00008670 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008671 /*TemplateArgs*/ 0);
8672}
8673
Douglas Gregor577f75a2009-08-04 16:50:30 +00008674} // end namespace clang
8675
8676#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H