blob: 4908e883b83642ebf79cab93cd179e2178042cf9 [file] [log] [blame]
Chris Lattner57ad3782011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner57ad3782011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattner57ad3782011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregor577f75a2009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
John McCall2d887082010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregore737f502010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor8491ffe2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregordcee1a12009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCall781472f2010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Richard Smith3e4c6c42011-05-05 21:57:07 +000024#include "clang/AST/DeclTemplate.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000025#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000026#include "clang/AST/ExprCXX.h"
27#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000028#include "clang/AST/Stmt.h"
29#include "clang/AST/StmtCXX.h"
30#include "clang/AST/StmtObjC.h"
John McCall19510852010-08-20 18:27:03 +000031#include "clang/Sema/Ownership.h"
32#include "clang/Sema/Designator.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000033#include "clang/Lex/Preprocessor.h"
David Blaikiea71f9d02011-09-22 02:34:54 +000034#include "llvm/ADT/ArrayRef.h"
John McCalla2becad2009-10-21 00:40:46 +000035#include "llvm/Support/ErrorHandling.h"
Douglas Gregor7e44e3f2010-12-02 00:05:49 +000036#include "TypeLocBuilder.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCall781472f2010-08-25 08:40:02 +000040using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000041
Douglas Gregor577f75a2009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump1eb44332009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump1eb44332009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor9151c112011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
101
102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
106
107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
111
Douglas Gregor577f75a2009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000114
Mike Stump1eb44332009-09-09 15:08:12 +0000115public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000116 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000117 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000118
Douglas Gregor577f75a2009-08-04 16:50:30 +0000119 /// \brief Retrieves a reference to the derived class.
120 Derived &getDerived() { return static_cast<Derived&>(*this); }
121
122 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000123 const Derived &getDerived() const {
124 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000125 }
126
John McCall60d7b3a2010-08-24 06:29:42 +0000127 static inline ExprResult Owned(Expr *E) { return E; }
128 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000129
Douglas Gregor577f75a2009-08-04 16:50:30 +0000130 /// \brief Retrieves a reference to the semantic analysis object used for
131 /// this tree transform.
132 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000133
Douglas Gregor577f75a2009-08-04 16:50:30 +0000134 /// \brief Whether the transformation should always rebuild AST nodes, even
135 /// if none of the children have changed.
136 ///
137 /// Subclasses may override this function to specify when the transformation
138 /// should rebuild all AST nodes.
139 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000140
Douglas Gregor577f75a2009-08-04 16:50:30 +0000141 /// \brief Returns the location of the entity being transformed, if that
142 /// information was not available elsewhere in the AST.
143 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000144 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000145 /// provide an alternative implementation that provides better location
146 /// information.
147 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000148
Douglas Gregor577f75a2009-08-04 16:50:30 +0000149 /// \brief Returns the name of the entity being transformed, if that
150 /// information was not available elsewhere in the AST.
151 ///
152 /// By default, returns an empty name. Subclasses can provide an alternative
153 /// implementation with a more precise name.
154 DeclarationName getBaseEntity() { return DeclarationName(); }
155
Douglas Gregorb98b1992009-08-11 05:31:07 +0000156 /// \brief Sets the "base" location and entity when that
157 /// information is known based on another transformation.
158 ///
159 /// By default, the source location and entity are ignored. Subclasses can
160 /// override this function to provide a customized implementation.
161 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000162
Douglas Gregorb98b1992009-08-11 05:31:07 +0000163 /// \brief RAII object that temporarily sets the base location and entity
164 /// used for reporting diagnostics in types.
165 class TemporaryBase {
166 TreeTransform &Self;
167 SourceLocation OldLocation;
168 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000169
Douglas Gregorb98b1992009-08-11 05:31:07 +0000170 public:
171 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000172 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000173 OldLocation = Self.getDerived().getBaseLocation();
174 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregorae201f72011-01-25 17:51:48 +0000175
176 if (Location.isValid())
177 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000178 }
Mike Stump1eb44332009-09-09 15:08:12 +0000179
Douglas Gregorb98b1992009-08-11 05:31:07 +0000180 ~TemporaryBase() {
181 Self.getDerived().setBase(OldLocation, OldEntity);
182 }
183 };
Mike Stump1eb44332009-09-09 15:08:12 +0000184
185 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000186 /// transformed.
187 ///
188 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000189 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000190 /// not change. For example, template instantiation need not traverse
191 /// non-dependent types.
192 bool AlreadyTransformed(QualType T) {
193 return T.isNull();
194 }
195
Douglas Gregor6eef5192009-12-14 19:27:10 +0000196 /// \brief Determine whether the given call argument should be dropped, e.g.,
197 /// because it is a default argument.
198 ///
199 /// Subclasses can provide an alternative implementation of this routine to
200 /// determine which kinds of call arguments get dropped. By default,
201 /// CXXDefaultArgument nodes are dropped (prior to transformation).
202 bool DropCallArgument(Expr *E) {
203 return E->isDefaultArgument();
204 }
Sean Huntc3021132010-05-05 15:23:54 +0000205
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000206 /// \brief Determine whether we should expand a pack expansion with the
207 /// given set of parameter packs into separate arguments by repeatedly
208 /// transforming the pattern.
209 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000210 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000211 /// Subclasses can override this routine to provide different behavior.
212 ///
213 /// \param EllipsisLoc The location of the ellipsis that identifies the
214 /// pack expansion.
215 ///
216 /// \param PatternRange The source range that covers the entire pattern of
217 /// the pack expansion.
218 ///
219 /// \param Unexpanded The set of unexpanded parameter packs within the
220 /// pattern.
221 ///
222 /// \param NumUnexpanded The number of unexpanded parameter packs in
223 /// \p Unexpanded.
224 ///
225 /// \param ShouldExpand Will be set to \c true if the transformer should
226 /// expand the corresponding pack expansions into separate arguments. When
227 /// set, \c NumExpansions must also be set.
228 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000229 /// \param RetainExpansion Whether the caller should add an unexpanded
230 /// pack expansion after all of the expanded arguments. This is used
231 /// when extending explicitly-specified template argument packs per
232 /// C++0x [temp.arg.explicit]p9.
233 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000234 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000235 /// the expanded form of the corresponding pack expansion. This is both an
236 /// input and an output parameter, which can be set by the caller if the
237 /// number of expansions is known a priori (e.g., due to a prior substitution)
238 /// and will be set by the callee when the number of expansions is known.
239 /// The callee must set this value when \c ShouldExpand is \c true; it may
240 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000241 ///
242 /// \returns true if an error occurred (e.g., because the parameter packs
243 /// are to be instantiated with arguments of different lengths), false
244 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
245 /// must be set.
246 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
247 SourceRange PatternRange,
David Blaikiea71f9d02011-09-22 02:34:54 +0000248 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000249 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000250 bool &RetainExpansion,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000251 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000252 ShouldExpand = false;
253 return false;
254 }
255
Douglas Gregord3731192011-01-10 07:32:04 +0000256 /// \brief "Forget" about the partially-substituted pack template argument,
257 /// when performing an instantiation that must preserve the parameter pack
258 /// use.
259 ///
260 /// This routine is meant to be overridden by the template instantiator.
261 TemplateArgument ForgetPartiallySubstitutedPack() {
262 return TemplateArgument();
263 }
264
265 /// \brief "Remember" the partially-substituted pack template argument
266 /// after performing an instantiation that must preserve the parameter pack
267 /// use.
268 ///
269 /// This routine is meant to be overridden by the template instantiator.
270 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
271
Douglas Gregor12c9c002011-01-07 16:43:16 +0000272 /// \brief Note to the derived class when a function parameter pack is
273 /// being expanded.
274 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
275
Douglas Gregor577f75a2009-08-04 16:50:30 +0000276 /// \brief Transforms the given type into another type.
277 ///
John McCalla2becad2009-10-21 00:40:46 +0000278 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000279 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000280 /// function. This is expensive, but we don't mind, because
281 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000282 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000283 ///
284 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000285 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000286
John McCalla2becad2009-10-21 00:40:46 +0000287 /// \brief Transforms the given type-with-location into a new
288 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000289 ///
John McCalla2becad2009-10-21 00:40:46 +0000290 /// By default, this routine transforms a type by delegating to the
291 /// appropriate TransformXXXType to build a new type. Subclasses
292 /// may override this function (to take over all type
293 /// transformations) or some set of the TransformXXXType functions
294 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000295 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000296
297 /// \brief Transform the given type-with-location into a new
298 /// type, collecting location information in the given builder
299 /// as necessary.
300 ///
John McCall43fed0d2010-11-12 08:19:04 +0000301 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000302
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000303 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000304 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000305 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000306 /// appropriate TransformXXXStmt function to transform a specific kind of
307 /// statement or the TransformExpr() function to transform an expression.
308 /// Subclasses may override this function to transform statements using some
309 /// other mechanism.
310 ///
311 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000312 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000313
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000314 /// \brief Transform the given expression.
315 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000316 /// By default, this routine transforms an expression by delegating to the
317 /// appropriate TransformXXXExpr function to build a new expression.
318 /// Subclasses may override this function to transform expressions using some
319 /// other mechanism.
320 ///
321 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000322 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000323
Douglas Gregoraa165f82011-01-03 19:04:46 +0000324 /// \brief Transform the given list of expressions.
325 ///
326 /// This routine transforms a list of expressions by invoking
327 /// \c TransformExpr() for each subexpression. However, it also provides
328 /// support for variadic templates by expanding any pack expansions (if the
329 /// derived class permits such expansion) along the way. When pack expansions
330 /// are present, the number of outputs may not equal the number of inputs.
331 ///
332 /// \param Inputs The set of expressions to be transformed.
333 ///
334 /// \param NumInputs The number of expressions in \c Inputs.
335 ///
336 /// \param IsCall If \c true, then this transform is being performed on
337 /// function-call arguments, and any arguments that should be dropped, will
338 /// be.
339 ///
340 /// \param Outputs The transformed input expressions will be added to this
341 /// vector.
342 ///
343 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
344 /// due to transformation.
345 ///
346 /// \returns true if an error occurred, false otherwise.
347 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +0000348 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000349 bool *ArgChanged = 0);
350
Douglas Gregor577f75a2009-08-04 16:50:30 +0000351 /// \brief Transform the given declaration, which is referenced from a type
352 /// or expression.
353 ///
Douglas Gregordcee1a12009-08-06 05:28:30 +0000354 /// By default, acts as the identity function on declarations. Subclasses
355 /// may override this function to provide alternate behavior.
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000356 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregor43959a92009-08-20 07:17:43 +0000357
358 /// \brief Transform the definition of the given declaration.
359 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000360 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000361 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000362 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
363 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000364 }
Mike Stump1eb44332009-09-09 15:08:12 +0000365
Douglas Gregor6cd21982009-10-20 05:58:46 +0000366 /// \brief Transform the given declaration, which was the first part of a
367 /// nested-name-specifier in a member access expression.
368 ///
Sean Huntc3021132010-05-05 15:23:54 +0000369 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000370 /// identifier in a nested-name-specifier of a member access expression, e.g.,
371 /// the \c T in \c x->T::member
372 ///
373 /// By default, invokes TransformDecl() to transform the declaration.
374 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000375 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
376 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000377 }
Sean Huntc3021132010-05-05 15:23:54 +0000378
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000379 /// \brief Transform the given nested-name-specifier with source-location
380 /// information.
381 ///
382 /// By default, transforms all of the types and declarations within the
383 /// nested-name-specifier. Subclasses may override this function to provide
384 /// alternate behavior.
385 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
386 NestedNameSpecifierLoc NNS,
387 QualType ObjectType = QualType(),
388 NamedDecl *FirstQualifierInScope = 0);
389
Douglas Gregor81499bb2009-09-03 22:13:48 +0000390 /// \brief Transform the given declaration name.
391 ///
392 /// By default, transforms the types of conversion function, constructor,
393 /// and destructor names and then (if needed) rebuilds the declaration name.
394 /// Identifiers and selectors are returned unmodified. Sublcasses may
395 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000396 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000397 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000398
Douglas Gregor577f75a2009-08-04 16:50:30 +0000399 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000400 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000401 /// \param SS The nested-name-specifier that qualifies the template
402 /// name. This nested-name-specifier must already have been transformed.
403 ///
404 /// \param Name The template name to transform.
405 ///
406 /// \param NameLoc The source location of the template name.
407 ///
408 /// \param ObjectType If we're translating a template name within a member
409 /// access expression, this is the type of the object whose member template
410 /// is being referenced.
411 ///
412 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
413 /// also refers to a name within the current (lexical) scope, this is the
414 /// declaration it refers to.
415 ///
416 /// By default, transforms the template name by transforming the declarations
417 /// and nested-name-specifiers that occur within the template name.
418 /// Subclasses may override this function to provide alternate behavior.
419 TemplateName TransformTemplateName(CXXScopeSpec &SS,
420 TemplateName Name,
421 SourceLocation NameLoc,
422 QualType ObjectType = QualType(),
423 NamedDecl *FirstQualifierInScope = 0);
424
Douglas Gregor577f75a2009-08-04 16:50:30 +0000425 /// \brief Transform the given template argument.
426 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000427 /// By default, this operation transforms the type, expression, or
428 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000429 /// new template argument from the transformed result. Subclasses may
430 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000431 ///
432 /// Returns true if there was an error.
433 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
434 TemplateArgumentLoc &Output);
435
Douglas Gregorfcc12532010-12-20 17:31:10 +0000436 /// \brief Transform the given set of template arguments.
437 ///
438 /// By default, this operation transforms all of the template arguments
439 /// in the input set using \c TransformTemplateArgument(), and appends
440 /// the transformed arguments to the output list.
441 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000442 /// Note that this overload of \c TransformTemplateArguments() is merely
443 /// a convenience function. Subclasses that wish to override this behavior
444 /// should override the iterator-based member template version.
445 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000446 /// \param Inputs The set of template arguments to be transformed.
447 ///
448 /// \param NumInputs The number of template arguments in \p Inputs.
449 ///
450 /// \param Outputs The set of transformed template arguments output by this
451 /// routine.
452 ///
453 /// Returns true if an error occurred.
454 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
455 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000456 TemplateArgumentListInfo &Outputs) {
457 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
458 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000459
460 /// \brief Transform the given set of template arguments.
461 ///
462 /// By default, this operation transforms all of the template arguments
463 /// in the input set using \c TransformTemplateArgument(), and appends
464 /// the transformed arguments to the output list.
465 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000466 /// \param First An iterator to the first template argument.
467 ///
468 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000469 ///
470 /// \param Outputs The set of transformed template arguments output by this
471 /// routine.
472 ///
473 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000474 template<typename InputIterator>
475 bool TransformTemplateArguments(InputIterator First,
476 InputIterator Last,
477 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000478
John McCall833ca992009-10-29 08:12:44 +0000479 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
480 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
481 TemplateArgumentLoc &ArgLoc);
482
John McCalla93c9342009-12-07 02:54:59 +0000483 /// \brief Fakes up a TypeSourceInfo for a type.
484 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
485 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000486 getDerived().getBaseLocation());
487 }
Mike Stump1eb44332009-09-09 15:08:12 +0000488
John McCalla2becad2009-10-21 00:40:46 +0000489#define ABSTRACT_TYPELOC(CLASS, PARENT)
490#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000491 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000492#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000493
John Wiegley28bbe4b2011-04-28 01:08:34 +0000494 StmtResult
495 TransformSEHHandler(Stmt *Handler);
496
John McCall43fed0d2010-11-12 08:19:04 +0000497 QualType
498 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
499 TemplateSpecializationTypeLoc TL,
500 TemplateName Template);
501
502 QualType
503 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
504 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000505 TemplateName Template,
506 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000507
508 QualType
509 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000510 DependentTemplateSpecializationTypeLoc TL,
511 NestedNameSpecifierLoc QualifierLoc);
512
John McCall21ef0fa2010-03-11 09:03:00 +0000513 /// \brief Transforms the parameters of a function type into the
514 /// given vectors.
515 ///
516 /// The result vectors should be kept in sync; null entries in the
517 /// variables vector are acceptable.
518 ///
519 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000520 bool TransformFunctionTypeParams(SourceLocation Loc,
521 ParmVarDecl **Params, unsigned NumParams,
522 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000523 SmallVectorImpl<QualType> &PTypes,
524 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000525
526 /// \brief Transforms a single function-type parameter. Return null
527 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000528 ///
529 /// \param indexAdjustment - A number to add to the parameter's
530 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000531 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000532 int indexAdjustment,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000533 llvm::Optional<unsigned> NumExpansions);
John McCall21ef0fa2010-03-11 09:03:00 +0000534
John McCall43fed0d2010-11-12 08:19:04 +0000535 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000536
John McCall60d7b3a2010-08-24 06:29:42 +0000537 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
538 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000539
Douglas Gregor43959a92009-08-20 07:17:43 +0000540#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000541 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000542#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000543 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000544#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000545#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000546
Douglas Gregor577f75a2009-08-04 16:50:30 +0000547 /// \brief Build a new pointer type given its pointee type.
548 ///
549 /// By default, performs semantic analysis when building the pointer type.
550 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000551 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000552
553 /// \brief Build a new block pointer type given its pointee type.
554 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000555 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000556 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000557 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000558
John McCall85737a72009-10-30 00:06:24 +0000559 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000560 ///
John McCall85737a72009-10-30 00:06:24 +0000561 /// By default, performs semantic analysis when building the
562 /// reference type. Subclasses may override this routine to provide
563 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000564 ///
John McCall85737a72009-10-30 00:06:24 +0000565 /// \param LValue whether the type was written with an lvalue sigil
566 /// or an rvalue sigil.
567 QualType RebuildReferenceType(QualType ReferentType,
568 bool LValue,
569 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000570
Douglas Gregor577f75a2009-08-04 16:50:30 +0000571 /// \brief Build a new member pointer type given the pointee type and the
572 /// class type it refers into.
573 ///
574 /// By default, performs semantic analysis when building the member pointer
575 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000576 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
577 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000578
Douglas Gregor577f75a2009-08-04 16:50:30 +0000579 /// \brief Build a new array type given the element type, size
580 /// modifier, size of the array (if known), size expression, and index type
581 /// qualifiers.
582 ///
583 /// By default, performs semantic analysis when building the array type.
584 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000585 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000586 QualType RebuildArrayType(QualType ElementType,
587 ArrayType::ArraySizeModifier SizeMod,
588 const llvm::APInt *Size,
589 Expr *SizeExpr,
590 unsigned IndexTypeQuals,
591 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000592
Douglas Gregor577f75a2009-08-04 16:50:30 +0000593 /// \brief Build a new constant array type given the element type, size
594 /// modifier, (known) size of the array, and index type qualifiers.
595 ///
596 /// By default, performs semantic analysis when building the array type.
597 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000598 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000599 ArrayType::ArraySizeModifier SizeMod,
600 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000601 unsigned IndexTypeQuals,
602 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000603
Douglas Gregor577f75a2009-08-04 16:50:30 +0000604 /// \brief Build a new incomplete array type given the element type, size
605 /// modifier, and index type qualifiers.
606 ///
607 /// By default, performs semantic analysis when building the array type.
608 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000609 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000610 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000611 unsigned IndexTypeQuals,
612 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000613
Mike Stump1eb44332009-09-09 15:08:12 +0000614 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000615 /// size modifier, size expression, and index type qualifiers.
616 ///
617 /// By default, performs semantic analysis when building the array type.
618 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000619 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000620 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000621 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000622 unsigned IndexTypeQuals,
623 SourceRange BracketsRange);
624
Mike Stump1eb44332009-09-09 15:08:12 +0000625 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000626 /// size modifier, size expression, and index type qualifiers.
627 ///
628 /// By default, performs semantic analysis when building the array type.
629 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000630 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000631 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000632 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000633 unsigned IndexTypeQuals,
634 SourceRange BracketsRange);
635
636 /// \brief Build a new vector type given the element type and
637 /// number of elements.
638 ///
639 /// By default, performs semantic analysis when building the vector type.
640 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000641 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000642 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000643
Douglas Gregor577f75a2009-08-04 16:50:30 +0000644 /// \brief Build a new extended vector type given the element type and
645 /// number of elements.
646 ///
647 /// By default, performs semantic analysis when building the vector type.
648 /// Subclasses may override this routine to provide different behavior.
649 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
650 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000651
652 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000653 /// given the element type and number of elements.
654 ///
655 /// By default, performs semantic analysis when building the vector type.
656 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000657 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000658 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000659 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000660
Douglas Gregor577f75a2009-08-04 16:50:30 +0000661 /// \brief Build a new function type.
662 ///
663 /// By default, performs semantic analysis when building the function type.
664 /// Subclasses may override this routine to provide different behavior.
665 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000666 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000667 unsigned NumParamTypes,
Eli Friedmanfa869542010-08-05 02:54:05 +0000668 bool Variadic, unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000669 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000670 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000671
John McCalla2becad2009-10-21 00:40:46 +0000672 /// \brief Build a new unprototyped function type.
673 QualType RebuildFunctionNoProtoType(QualType ResultType);
674
John McCalled976492009-12-04 22:46:56 +0000675 /// \brief Rebuild an unresolved typename type, given the decl that
676 /// the UnresolvedUsingTypenameDecl was transformed to.
677 QualType RebuildUnresolvedUsingType(Decl *D);
678
Douglas Gregor577f75a2009-08-04 16:50:30 +0000679 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000680 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000681 return SemaRef.Context.getTypeDeclType(Typedef);
682 }
683
684 /// \brief Build a new class/struct/union type.
685 QualType RebuildRecordType(RecordDecl *Record) {
686 return SemaRef.Context.getTypeDeclType(Record);
687 }
688
689 /// \brief Build a new Enum type.
690 QualType RebuildEnumType(EnumDecl *Enum) {
691 return SemaRef.Context.getTypeDeclType(Enum);
692 }
John McCall7da24312009-09-05 00:15:47 +0000693
Mike Stump1eb44332009-09-09 15:08:12 +0000694 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000695 ///
696 /// By default, performs semantic analysis when building the typeof type.
697 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000698 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000699
Mike Stump1eb44332009-09-09 15:08:12 +0000700 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000701 ///
702 /// By default, builds a new TypeOfType with the given underlying type.
703 QualType RebuildTypeOfType(QualType Underlying);
704
Sean Huntca63c202011-05-24 22:41:36 +0000705 /// \brief Build a new unary transform type.
706 QualType RebuildUnaryTransformType(QualType BaseType,
707 UnaryTransformType::UTTKind UKind,
708 SourceLocation Loc);
709
Mike Stump1eb44332009-09-09 15:08:12 +0000710 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000711 ///
712 /// By default, performs semantic analysis when building the decltype type.
713 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000714 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000715
Richard Smith34b41d92011-02-20 03:19:35 +0000716 /// \brief Build a new C++0x auto type.
717 ///
718 /// By default, builds a new AutoType with the given deduced type.
719 QualType RebuildAutoType(QualType Deduced) {
720 return SemaRef.Context.getAutoType(Deduced);
721 }
722
Douglas Gregor577f75a2009-08-04 16:50:30 +0000723 /// \brief Build a new template specialization type.
724 ///
725 /// By default, performs semantic analysis when building the template
726 /// specialization type. Subclasses may override this routine to provide
727 /// different behavior.
728 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000729 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000730 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000731
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000732 /// \brief Build a new parenthesized type.
733 ///
734 /// By default, builds a new ParenType type from the inner type.
735 /// Subclasses may override this routine to provide different behavior.
736 QualType RebuildParenType(QualType InnerType) {
737 return SemaRef.Context.getParenType(InnerType);
738 }
739
Douglas Gregor577f75a2009-08-04 16:50:30 +0000740 /// \brief Build a new qualified name type.
741 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000742 /// By default, builds a new ElaboratedType type from the keyword,
743 /// the nested-name-specifier and the named type.
744 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000745 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
746 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000747 NestedNameSpecifierLoc QualifierLoc,
748 QualType Named) {
749 return SemaRef.Context.getElaboratedType(Keyword,
750 QualifierLoc.getNestedNameSpecifier(),
751 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000752 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000753
754 /// \brief Build a new typename type that refers to a template-id.
755 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000756 /// By default, builds a new DependentNameType type from the
757 /// nested-name-specifier and the given type. Subclasses may override
758 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000759 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000760 ElaboratedTypeKeyword Keyword,
761 NestedNameSpecifierLoc QualifierLoc,
762 const IdentifierInfo *Name,
763 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000764 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000765 // Rebuild the template name.
766 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000767 CXXScopeSpec SS;
768 SS.Adopt(QualifierLoc);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000769 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000770 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000771
772 if (InstName.isNull())
773 return QualType();
774
775 // If it's still dependent, make a dependent specialization.
776 if (InstName.getAsDependentTemplateName())
777 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
778 QualifierLoc.getNestedNameSpecifier(),
779 Name,
780 Args);
781
782 // Otherwise, make an elaborated type wrapping a non-dependent
783 // specialization.
784 QualType T =
785 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
786 if (T.isNull()) return QualType();
787
788 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
789 return T;
790
791 return SemaRef.Context.getElaboratedType(Keyword,
792 QualifierLoc.getNestedNameSpecifier(),
793 T);
794 }
795
Douglas Gregor577f75a2009-08-04 16:50:30 +0000796 /// \brief Build a new typename type that refers to an identifier.
797 ///
798 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000799 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000800 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000801 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000802 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000803 NestedNameSpecifierLoc QualifierLoc,
804 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000805 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000806 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000807 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000808
Douglas Gregor2494dd02011-03-01 01:34:45 +0000809 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000810 // If the name is still dependent, just build a new dependent name type.
811 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor2494dd02011-03-01 01:34:45 +0000812 return SemaRef.Context.getDependentNameType(Keyword,
813 QualifierLoc.getNestedNameSpecifier(),
814 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000815 }
816
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000817 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000818 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000819 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000820
821 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
822
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000823 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000824 // into a non-dependent elaborated-type-specifier. Find the tag we're
825 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000826 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000827 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
828 if (!DC)
829 return QualType();
830
John McCall56138762010-05-27 06:40:31 +0000831 if (SemaRef.RequireCompleteDeclContext(SS, DC))
832 return QualType();
833
Douglas Gregor40336422010-03-31 22:19:08 +0000834 TagDecl *Tag = 0;
835 SemaRef.LookupQualifiedName(Result, DC);
836 switch (Result.getResultKind()) {
837 case LookupResult::NotFound:
838 case LookupResult::NotFoundInCurrentInstantiation:
839 break;
Sean Huntc3021132010-05-05 15:23:54 +0000840
Douglas Gregor40336422010-03-31 22:19:08 +0000841 case LookupResult::Found:
842 Tag = Result.getAsSingle<TagDecl>();
843 break;
Sean Huntc3021132010-05-05 15:23:54 +0000844
Douglas Gregor40336422010-03-31 22:19:08 +0000845 case LookupResult::FoundOverloaded:
846 case LookupResult::FoundUnresolvedValue:
847 llvm_unreachable("Tag lookup cannot find non-tags");
848 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000849
Douglas Gregor40336422010-03-31 22:19:08 +0000850 case LookupResult::Ambiguous:
851 // Let the LookupResult structure handle ambiguities.
852 return QualType();
853 }
854
855 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000856 // Check where the name exists but isn't a tag type and use that to emit
857 // better diagnostics.
858 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
859 SemaRef.LookupQualifiedName(Result, DC);
860 switch (Result.getResultKind()) {
861 case LookupResult::Found:
862 case LookupResult::FoundOverloaded:
863 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000864 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000865 unsigned Kind = 0;
866 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000867 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
868 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000869 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
870 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
871 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000872 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000873 default:
874 // FIXME: Would be nice to highlight just the source range.
875 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
876 << Kind << Id << DC;
877 break;
878 }
Douglas Gregor40336422010-03-31 22:19:08 +0000879 return QualType();
880 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000881
Richard Trieubbf34c02011-06-10 03:11:26 +0000882 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
883 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000884 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000885 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
886 return QualType();
887 }
888
889 // Build the elaborated-type-specifier type.
890 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor2494dd02011-03-01 01:34:45 +0000891 return SemaRef.Context.getElaboratedType(Keyword,
892 QualifierLoc.getNestedNameSpecifier(),
893 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000894 }
Mike Stump1eb44332009-09-09 15:08:12 +0000895
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000896 /// \brief Build a new pack expansion type.
897 ///
898 /// By default, builds a new PackExpansionType type from the given pattern.
899 /// Subclasses may override this routine to provide different behavior.
900 QualType RebuildPackExpansionType(QualType Pattern,
901 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000902 SourceLocation EllipsisLoc,
903 llvm::Optional<unsigned> NumExpansions) {
904 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
905 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000906 }
907
Eli Friedmanb001de72011-10-06 23:00:33 +0000908 /// \brief Build a new atomic type given its value type.
909 ///
910 /// By default, performs semantic analysis when building the atomic type.
911 /// Subclasses may override this routine to provide different behavior.
912 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
913
Douglas Gregord1067e52009-08-06 06:41:21 +0000914 /// \brief Build a new template name given a nested name specifier, a flag
915 /// indicating whether the "template" keyword was provided, and the template
916 /// that the template name refers to.
917 ///
918 /// By default, builds the new template name directly. Subclasses may override
919 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000920 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000921 bool TemplateKW,
922 TemplateDecl *Template);
923
Douglas Gregord1067e52009-08-06 06:41:21 +0000924 /// \brief Build a new template name given a nested name specifier and the
925 /// name that is referred to as a template.
926 ///
927 /// By default, performs semantic analysis to determine whether the name can
928 /// be resolved to a specific template, then builds the appropriate kind of
929 /// template name. Subclasses may override this routine to provide different
930 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000931 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
932 const IdentifierInfo &Name,
933 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000934 QualType ObjectType,
935 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000936
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000937 /// \brief Build a new template name given a nested name specifier and the
938 /// overloaded operator name that is referred to as a template.
939 ///
940 /// By default, performs semantic analysis to determine whether the name can
941 /// be resolved to a specific template, then builds the appropriate kind of
942 /// template name. Subclasses may override this routine to provide different
943 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000944 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000945 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000946 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000947 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000948
949 /// \brief Build a new template name given a template template parameter pack
950 /// and the
951 ///
952 /// By default, performs semantic analysis to determine whether the name can
953 /// be resolved to a specific template, then builds the appropriate kind of
954 /// template name. Subclasses may override this routine to provide different
955 /// behavior.
956 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
957 const TemplateArgument &ArgPack) {
958 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
959 }
960
Douglas Gregor43959a92009-08-20 07:17:43 +0000961 /// \brief Build a new compound statement.
962 ///
963 /// By default, performs semantic analysis to build the new statement.
964 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000965 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000966 MultiStmtArg Statements,
967 SourceLocation RBraceLoc,
968 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000969 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +0000970 IsStmtExpr);
971 }
972
973 /// \brief Build a new case statement.
974 ///
975 /// By default, performs semantic analysis to build the new statement.
976 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000977 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000978 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000979 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000980 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000981 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000982 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000983 ColonLoc);
984 }
Mike Stump1eb44332009-09-09 15:08:12 +0000985
Douglas Gregor43959a92009-08-20 07:17:43 +0000986 /// \brief Attach the body to a new case statement.
987 ///
988 /// By default, performs semantic analysis to build the new statement.
989 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000990 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000991 getSema().ActOnCaseStmtBody(S, Body);
992 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000993 }
Mike Stump1eb44332009-09-09 15:08:12 +0000994
Douglas Gregor43959a92009-08-20 07:17:43 +0000995 /// \brief Build a new default statement.
996 ///
997 /// By default, performs semantic analysis to build the new statement.
998 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000999 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001000 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001001 Stmt *SubStmt) {
1002 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001003 /*CurScope=*/0);
1004 }
Mike Stump1eb44332009-09-09 15:08:12 +00001005
Douglas Gregor43959a92009-08-20 07:17:43 +00001006 /// \brief Build a new label statement.
1007 ///
1008 /// By default, performs semantic analysis to build the new statement.
1009 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001010 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1011 SourceLocation ColonLoc, Stmt *SubStmt) {
1012 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001013 }
Mike Stump1eb44332009-09-09 15:08:12 +00001014
Douglas Gregor43959a92009-08-20 07:17:43 +00001015 /// \brief Build a new "if" statement.
1016 ///
1017 /// By default, performs semantic analysis to build the new statement.
1018 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001019 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattner57ad3782011-02-17 20:34:02 +00001020 VarDecl *CondVar, Stmt *Then,
1021 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001022 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001023 }
Mike Stump1eb44332009-09-09 15:08:12 +00001024
Douglas Gregor43959a92009-08-20 07:17:43 +00001025 /// \brief Start building a new switch statement.
1026 ///
1027 /// By default, performs semantic analysis to build the new statement.
1028 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001029 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001030 Expr *Cond, VarDecl *CondVar) {
John McCall9ae2f072010-08-23 23:25:46 +00001031 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001032 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001033 }
Mike Stump1eb44332009-09-09 15:08:12 +00001034
Douglas Gregor43959a92009-08-20 07:17:43 +00001035 /// \brief Attach the body to the switch statement.
1036 ///
1037 /// By default, performs semantic analysis to build the new statement.
1038 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001039 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001040 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001041 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001042 }
1043
1044 /// \brief Build a new while statement.
1045 ///
1046 /// By default, performs semantic analysis to build the new statement.
1047 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001048 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1049 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001050 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001051 }
Mike Stump1eb44332009-09-09 15:08:12 +00001052
Douglas Gregor43959a92009-08-20 07:17:43 +00001053 /// \brief Build a new do-while statement.
1054 ///
1055 /// By default, performs semantic analysis to build the new statement.
1056 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001057 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001058 SourceLocation WhileLoc, SourceLocation LParenLoc,
1059 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001060 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1061 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001062 }
1063
1064 /// \brief Build a new for statement.
1065 ///
1066 /// By default, performs semantic analysis to build the new statement.
1067 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001068 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1069 Stmt *Init, Sema::FullExprArg Cond,
1070 VarDecl *CondVar, Sema::FullExprArg Inc,
1071 SourceLocation RParenLoc, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001072 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001073 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001074 }
Mike Stump1eb44332009-09-09 15:08:12 +00001075
Douglas Gregor43959a92009-08-20 07:17:43 +00001076 /// \brief Build a new goto statement.
1077 ///
1078 /// By default, performs semantic analysis to build the new statement.
1079 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001080 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1081 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001082 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001083 }
1084
1085 /// \brief Build a new indirect goto statement.
1086 ///
1087 /// By default, performs semantic analysis to build the new statement.
1088 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001089 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001090 SourceLocation StarLoc,
1091 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001092 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001093 }
Mike Stump1eb44332009-09-09 15:08:12 +00001094
Douglas Gregor43959a92009-08-20 07:17:43 +00001095 /// \brief Build a new return statement.
1096 ///
1097 /// By default, performs semantic analysis to build the new statement.
1098 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001099 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001100 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001101 }
Mike Stump1eb44332009-09-09 15:08:12 +00001102
Douglas Gregor43959a92009-08-20 07:17:43 +00001103 /// \brief Build a new declaration statement.
1104 ///
1105 /// By default, performs semantic analysis to build the new statement.
1106 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001107 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001108 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001109 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001110 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1111 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001112 }
Mike Stump1eb44332009-09-09 15:08:12 +00001113
Anders Carlsson703e3942010-01-24 05:50:09 +00001114 /// \brief Build a new inline asm statement.
1115 ///
1116 /// By default, performs semantic analysis to build the new statement.
1117 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001118 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001119 bool IsSimple,
1120 bool IsVolatile,
1121 unsigned NumOutputs,
1122 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001123 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001124 MultiExprArg Constraints,
1125 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001126 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001127 MultiExprArg Clobbers,
1128 SourceLocation RParenLoc,
1129 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001130 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001131 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001132 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001133 RParenLoc, MSAsm);
1134 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001135
1136 /// \brief Build a new Objective-C @try statement.
1137 ///
1138 /// By default, performs semantic analysis to build the new statement.
1139 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001140 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001141 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001142 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001143 Stmt *Finally) {
1144 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1145 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001146 }
1147
Douglas Gregorbe270a02010-04-26 17:57:08 +00001148 /// \brief Rebuild an Objective-C exception declaration.
1149 ///
1150 /// By default, performs semantic analysis to build the new declaration.
1151 /// Subclasses may override this routine to provide different behavior.
1152 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1153 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001154 return getSema().BuildObjCExceptionDecl(TInfo, T,
1155 ExceptionDecl->getInnerLocStart(),
1156 ExceptionDecl->getLocation(),
1157 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001158 }
Sean Huntc3021132010-05-05 15:23:54 +00001159
Douglas Gregorbe270a02010-04-26 17:57:08 +00001160 /// \brief Build a new Objective-C @catch statement.
1161 ///
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001164 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001165 SourceLocation RParenLoc,
1166 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001167 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001168 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001169 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001170 }
Sean Huntc3021132010-05-05 15:23:54 +00001171
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001172 /// \brief Build a new Objective-C @finally statement.
1173 ///
1174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001176 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001177 Stmt *Body) {
1178 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001179 }
Sean Huntc3021132010-05-05 15:23:54 +00001180
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001181 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001182 ///
1183 /// By default, performs semantic analysis to build the new statement.
1184 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001185 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001186 Expr *Operand) {
1187 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001188 }
Sean Huntc3021132010-05-05 15:23:54 +00001189
John McCall07524032011-07-27 21:50:02 +00001190 /// \brief Rebuild the operand to an Objective-C @synchronized statement.
1191 ///
1192 /// By default, performs semantic analysis to build the new statement.
1193 /// Subclasses may override this routine to provide different behavior.
1194 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1195 Expr *object) {
1196 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1197 }
1198
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001199 /// \brief Build a new Objective-C @synchronized statement.
1200 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001201 /// By default, performs semantic analysis to build the new statement.
1202 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001203 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001204 Expr *Object, Stmt *Body) {
1205 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001206 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001207
John McCallf85e1932011-06-15 23:02:42 +00001208 /// \brief Build a new Objective-C @autoreleasepool statement.
1209 ///
1210 /// By default, performs semantic analysis to build the new statement.
1211 /// Subclasses may override this routine to provide different behavior.
1212 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1213 Stmt *Body) {
1214 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1215 }
John McCall990567c2011-07-27 01:07:15 +00001216
1217 /// \brief Build the collection operand to a new Objective-C fast
1218 /// enumeration statement.
1219 ///
1220 /// By default, performs semantic analysis to build the new statement.
1221 /// Subclasses may override this routine to provide different behavior.
1222 ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc,
1223 Expr *collection) {
1224 return getSema().ActOnObjCForCollectionOperand(forLoc, collection);
1225 }
John McCallf85e1932011-06-15 23:02:42 +00001226
Douglas Gregorc3203e72010-04-22 23:10:45 +00001227 /// \brief Build a new Objective-C fast enumeration statement.
1228 ///
1229 /// By default, performs semantic analysis to build the new statement.
1230 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001231 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001232 SourceLocation LParenLoc,
1233 Stmt *Element,
1234 Expr *Collection,
1235 SourceLocation RParenLoc,
1236 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001237 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001238 Element,
1239 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001240 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001241 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001242 }
Sean Huntc3021132010-05-05 15:23:54 +00001243
Douglas Gregor43959a92009-08-20 07:17:43 +00001244 /// \brief Build a new C++ exception declaration.
1245 ///
1246 /// By default, performs semantic analysis to build the new decaration.
1247 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001248 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001249 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001250 SourceLocation StartLoc,
1251 SourceLocation IdLoc,
1252 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001253 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1254 StartLoc, IdLoc, Id);
1255 if (Var)
1256 getSema().CurContext->addDecl(Var);
1257 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001258 }
1259
1260 /// \brief Build a new C++ catch statement.
1261 ///
1262 /// By default, performs semantic analysis to build the new statement.
1263 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001264 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001265 VarDecl *ExceptionDecl,
1266 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001267 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1268 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001269 }
Mike Stump1eb44332009-09-09 15:08:12 +00001270
Douglas Gregor43959a92009-08-20 07:17:43 +00001271 /// \brief Build a new C++ try statement.
1272 ///
1273 /// By default, performs semantic analysis to build the new statement.
1274 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001275 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001276 Stmt *TryBlock,
1277 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001278 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001279 }
Mike Stump1eb44332009-09-09 15:08:12 +00001280
Richard Smithad762fc2011-04-14 22:09:26 +00001281 /// \brief Build a new C++0x range-based for statement.
1282 ///
1283 /// By default, performs semantic analysis to build the new statement.
1284 /// Subclasses may override this routine to provide different behavior.
1285 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1286 SourceLocation ColonLoc,
1287 Stmt *Range, Stmt *BeginEnd,
1288 Expr *Cond, Expr *Inc,
1289 Stmt *LoopVar,
1290 SourceLocation RParenLoc) {
1291 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1292 Cond, Inc, LoopVar, RParenLoc);
1293 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001294
1295 /// \brief Build a new C++0x range-based for statement.
1296 ///
1297 /// By default, performs semantic analysis to build the new statement.
1298 /// Subclasses may override this routine to provide different behavior.
1299 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
1300 bool IsIfExists,
1301 NestedNameSpecifierLoc QualifierLoc,
1302 DeclarationNameInfo NameInfo,
1303 Stmt *Nested) {
1304 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1305 QualifierLoc, NameInfo, Nested);
1306 }
1307
Richard Smithad762fc2011-04-14 22:09:26 +00001308 /// \brief Attach body to a C++0x range-based for statement.
1309 ///
1310 /// By default, performs semantic analysis to finish the new statement.
1311 /// Subclasses may override this routine to provide different behavior.
1312 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1313 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1314 }
1315
John Wiegley28bbe4b2011-04-28 01:08:34 +00001316 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1317 SourceLocation TryLoc,
1318 Stmt *TryBlock,
1319 Stmt *Handler) {
1320 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1321 }
1322
1323 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1324 Expr *FilterExpr,
1325 Stmt *Block) {
1326 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1327 }
1328
1329 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1330 Stmt *Block) {
1331 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1332 }
1333
Douglas Gregorb98b1992009-08-11 05:31:07 +00001334 /// \brief Build a new expression that references a declaration.
1335 ///
1336 /// By default, performs semantic analysis to build the new expression.
1337 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001338 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001339 LookupResult &R,
1340 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001341 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1342 }
1343
1344
1345 /// \brief Build a new expression that references a declaration.
1346 ///
1347 /// By default, performs semantic analysis to build the new expression.
1348 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001349 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001350 ValueDecl *VD,
1351 const DeclarationNameInfo &NameInfo,
1352 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001353 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001354 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001355
1356 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001357
1358 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001359 }
Mike Stump1eb44332009-09-09 15:08:12 +00001360
Douglas Gregorb98b1992009-08-11 05:31:07 +00001361 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001362 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001363 /// By default, performs semantic analysis to build the new expression.
1364 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001365 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001366 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001367 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001368 }
1369
Douglas Gregora71d8192009-09-04 17:36:40 +00001370 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001371 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001372 /// By default, performs semantic analysis to build the new expression.
1373 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001374 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001375 SourceLocation OperatorLoc,
1376 bool isArrow,
1377 CXXScopeSpec &SS,
1378 TypeSourceInfo *ScopeType,
1379 SourceLocation CCLoc,
1380 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001381 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001382
Douglas Gregorb98b1992009-08-11 05:31:07 +00001383 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001384 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001385 /// By default, performs semantic analysis to build the new expression.
1386 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001387 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001388 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001389 Expr *SubExpr) {
1390 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001391 }
Mike Stump1eb44332009-09-09 15:08:12 +00001392
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001393 /// \brief Build a new builtin offsetof expression.
1394 ///
1395 /// By default, performs semantic analysis to build the new expression.
1396 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001397 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001398 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001399 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001400 unsigned NumComponents,
1401 SourceLocation RParenLoc) {
1402 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1403 NumComponents, RParenLoc);
1404 }
Sean Huntc3021132010-05-05 15:23:54 +00001405
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001406 /// \brief Build a new sizeof, alignof or vec_step expression with a
1407 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001408 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001409 /// By default, performs semantic analysis to build the new expression.
1410 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001411 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1412 SourceLocation OpLoc,
1413 UnaryExprOrTypeTrait ExprKind,
1414 SourceRange R) {
1415 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001416 }
1417
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001418 /// \brief Build a new sizeof, alignof or vec step expression with an
1419 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001420 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001421 /// By default, performs semantic analysis to build the new expression.
1422 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001423 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1424 UnaryExprOrTypeTrait ExprKind,
1425 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001426 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001427 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001428 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001429 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001430
Douglas Gregorb98b1992009-08-11 05:31:07 +00001431 return move(Result);
1432 }
Mike Stump1eb44332009-09-09 15:08:12 +00001433
Douglas Gregorb98b1992009-08-11 05:31:07 +00001434 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001435 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001436 /// By default, performs semantic analysis to build the new expression.
1437 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001438 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001439 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001440 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001441 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001442 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1443 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001444 RBracketLoc);
1445 }
1446
1447 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001448 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001449 /// By default, performs semantic analysis to build the new expression.
1450 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001451 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001452 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001453 SourceLocation RParenLoc,
1454 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001455 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001456 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001457 }
1458
1459 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001460 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001461 /// By default, performs semantic analysis to build the new expression.
1462 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001463 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001464 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001465 NestedNameSpecifierLoc QualifierLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001466 const DeclarationNameInfo &MemberNameInfo,
1467 ValueDecl *Member,
1468 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001469 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001470 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001471 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1472 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001473 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001474 // We have a reference to an unnamed field. This is always the
1475 // base of an anonymous struct/union member access, i.e. the
1476 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001477 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001478 assert(Member->getType()->isRecordType() &&
1479 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001480
Richard Smith9138b4e2011-10-26 19:06:56 +00001481 BaseResult =
1482 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001483 QualifierLoc.getNestedNameSpecifier(),
1484 FoundDecl, Member);
1485 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001486 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001487 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001488 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001489 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001490 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001491 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001492 cast<FieldDecl>(Member)->getType(),
1493 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001494 return getSema().Owned(ME);
1495 }
Mike Stump1eb44332009-09-09 15:08:12 +00001496
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001497 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001498 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001499
John Wiegley429bb272011-04-08 18:41:53 +00001500 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001501 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001502
John McCall6bb80172010-03-30 21:47:33 +00001503 // FIXME: this involves duplicating earlier analysis in a lot of
1504 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001505 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001506 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001507 R.resolveKind();
1508
John McCall9ae2f072010-08-23 23:25:46 +00001509 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001510 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001511 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001512 }
Mike Stump1eb44332009-09-09 15:08:12 +00001513
Douglas Gregorb98b1992009-08-11 05:31:07 +00001514 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001515 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001516 /// By default, performs semantic analysis to build the new expression.
1517 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001518 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001519 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001520 Expr *LHS, Expr *RHS) {
1521 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001522 }
1523
1524 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001525 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001526 /// By default, performs semantic analysis to build the new expression.
1527 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001528 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001529 SourceLocation QuestionLoc,
1530 Expr *LHS,
1531 SourceLocation ColonLoc,
1532 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001533 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1534 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001535 }
1536
Douglas Gregorb98b1992009-08-11 05:31:07 +00001537 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001538 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001539 /// By default, performs semantic analysis to build the new expression.
1540 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001541 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001542 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001543 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001544 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001545 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001546 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001547 }
Mike Stump1eb44332009-09-09 15:08:12 +00001548
Douglas Gregorb98b1992009-08-11 05:31:07 +00001549 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001550 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001551 /// By default, performs semantic analysis to build the new expression.
1552 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001553 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001554 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001555 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001556 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001557 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001558 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001559 }
Mike Stump1eb44332009-09-09 15:08:12 +00001560
Douglas Gregorb98b1992009-08-11 05:31:07 +00001561 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001562 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001563 /// By default, performs semantic analysis to build the new expression.
1564 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001565 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001566 SourceLocation OpLoc,
1567 SourceLocation AccessorLoc,
1568 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001569
John McCall129e2df2009-11-30 22:42:35 +00001570 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001571 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001572 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001573 OpLoc, /*IsArrow*/ false,
1574 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001575 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001576 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001577 }
Mike Stump1eb44332009-09-09 15:08:12 +00001578
Douglas Gregorb98b1992009-08-11 05:31:07 +00001579 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001580 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001581 /// By default, performs semantic analysis to build the new expression.
1582 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001583 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001584 MultiExprArg Inits,
1585 SourceLocation RBraceLoc,
1586 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001587 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001588 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1589 if (Result.isInvalid() || ResultTy->isDependentType())
1590 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001591
Douglas Gregore48319a2009-11-09 17:16:50 +00001592 // Patch in the result type we were given, which may have been computed
1593 // when the initial InitListExpr was built.
1594 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1595 ILE->setType(ResultTy);
1596 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001597 }
Mike Stump1eb44332009-09-09 15:08:12 +00001598
Douglas Gregorb98b1992009-08-11 05:31:07 +00001599 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001600 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001601 /// By default, performs semantic analysis to build the new expression.
1602 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001603 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001604 MultiExprArg ArrayExprs,
1605 SourceLocation EqualOrColonLoc,
1606 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001607 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001608 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001609 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001610 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001611 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001612 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001613
Douglas Gregorb98b1992009-08-11 05:31:07 +00001614 ArrayExprs.release();
1615 return move(Result);
1616 }
Mike Stump1eb44332009-09-09 15:08:12 +00001617
Douglas Gregorb98b1992009-08-11 05:31:07 +00001618 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001619 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001620 /// By default, builds the implicit value initialization without performing
1621 /// any semantic analysis. Subclasses may override this routine to provide
1622 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001623 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001624 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1625 }
Mike Stump1eb44332009-09-09 15:08:12 +00001626
Douglas Gregorb98b1992009-08-11 05:31:07 +00001627 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001628 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001629 /// By default, performs semantic analysis to build the new expression.
1630 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001631 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001632 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001633 SourceLocation RParenLoc) {
1634 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001635 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001636 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001637 }
1638
1639 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001640 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001641 /// By default, performs semantic analysis to build the new expression.
1642 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001643 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001644 MultiExprArg SubExprs,
1645 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001646 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001647 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001648 }
Mike Stump1eb44332009-09-09 15:08:12 +00001649
Douglas Gregorb98b1992009-08-11 05:31:07 +00001650 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001651 ///
1652 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 /// rather than attempting to map the label statement itself.
1654 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001655 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001656 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001657 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001658 }
Mike Stump1eb44332009-09-09 15:08:12 +00001659
Douglas Gregorb98b1992009-08-11 05:31:07 +00001660 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001661 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001662 /// By default, performs semantic analysis to build the new expression.
1663 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001664 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001665 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001666 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001667 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001668 }
Mike Stump1eb44332009-09-09 15:08:12 +00001669
Douglas Gregorb98b1992009-08-11 05:31:07 +00001670 /// \brief Build a new __builtin_choose_expr expression.
1671 ///
1672 /// By default, performs semantic analysis to build the new expression.
1673 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001674 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001675 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001676 SourceLocation RParenLoc) {
1677 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001678 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001679 RParenLoc);
1680 }
Mike Stump1eb44332009-09-09 15:08:12 +00001681
Peter Collingbournef111d932011-04-15 00:35:48 +00001682 /// \brief Build a new generic selection expression.
1683 ///
1684 /// By default, performs semantic analysis to build the new expression.
1685 /// Subclasses may override this routine to provide different behavior.
1686 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1687 SourceLocation DefaultLoc,
1688 SourceLocation RParenLoc,
1689 Expr *ControllingExpr,
1690 TypeSourceInfo **Types,
1691 Expr **Exprs,
1692 unsigned NumAssocs) {
1693 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1694 ControllingExpr, Types, Exprs,
1695 NumAssocs);
1696 }
1697
Douglas Gregorb98b1992009-08-11 05:31:07 +00001698 /// \brief Build a new overloaded operator call expression.
1699 ///
1700 /// By default, performs semantic analysis to build the new expression.
1701 /// The semantic analysis provides the behavior of template instantiation,
1702 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001703 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001704 /// argument-dependent lookup, etc. Subclasses may override this routine to
1705 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001706 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001707 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001708 Expr *Callee,
1709 Expr *First,
1710 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001711
1712 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001713 /// reinterpret_cast.
1714 ///
1715 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001716 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001717 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001718 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001719 Stmt::StmtClass Class,
1720 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001721 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001722 SourceLocation RAngleLoc,
1723 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001724 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001725 SourceLocation RParenLoc) {
1726 switch (Class) {
1727 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001728 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001729 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001730 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001731
1732 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001733 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001734 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001735 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001736
Douglas Gregorb98b1992009-08-11 05:31:07 +00001737 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001738 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001739 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001740 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001741 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001742
Douglas Gregorb98b1992009-08-11 05:31:07 +00001743 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001744 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001745 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001746 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001747
Douglas Gregorb98b1992009-08-11 05:31:07 +00001748 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001749 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001750 }
Mike Stump1eb44332009-09-09 15:08:12 +00001751
John McCallf312b1e2010-08-26 23:41:50 +00001752 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001753 }
Mike Stump1eb44332009-09-09 15:08:12 +00001754
Douglas Gregorb98b1992009-08-11 05:31:07 +00001755 /// \brief Build a new C++ static_cast expression.
1756 ///
1757 /// By default, performs semantic analysis to build the new expression.
1758 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001759 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001760 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001761 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001762 SourceLocation RAngleLoc,
1763 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001764 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001765 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001766 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001767 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001768 SourceRange(LAngleLoc, RAngleLoc),
1769 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001770 }
1771
1772 /// \brief Build a new C++ dynamic_cast expression.
1773 ///
1774 /// By default, performs semantic analysis to build the new expression.
1775 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001776 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001777 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001778 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001779 SourceLocation RAngleLoc,
1780 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001781 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001782 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001783 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001784 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001785 SourceRange(LAngleLoc, RAngleLoc),
1786 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001787 }
1788
1789 /// \brief Build a new C++ reinterpret_cast expression.
1790 ///
1791 /// By default, performs semantic analysis to build the new expression.
1792 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001793 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001794 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001795 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001796 SourceLocation RAngleLoc,
1797 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001798 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001799 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001800 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001801 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001802 SourceRange(LAngleLoc, RAngleLoc),
1803 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001804 }
1805
1806 /// \brief Build a new C++ const_cast expression.
1807 ///
1808 /// By default, performs semantic analysis to build the new expression.
1809 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001810 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001811 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001812 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001813 SourceLocation RAngleLoc,
1814 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001815 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001816 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001817 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001818 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001819 SourceRange(LAngleLoc, RAngleLoc),
1820 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001821 }
Mike Stump1eb44332009-09-09 15:08:12 +00001822
Douglas Gregorb98b1992009-08-11 05:31:07 +00001823 /// \brief Build a new C++ functional-style cast expression.
1824 ///
1825 /// By default, performs semantic analysis to build the new expression.
1826 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001827 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1828 SourceLocation LParenLoc,
1829 Expr *Sub,
1830 SourceLocation RParenLoc) {
1831 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001832 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001833 RParenLoc);
1834 }
Mike Stump1eb44332009-09-09 15:08:12 +00001835
Douglas Gregorb98b1992009-08-11 05:31:07 +00001836 /// \brief Build a new C++ typeid(type) expression.
1837 ///
1838 /// By default, performs semantic analysis to build the new expression.
1839 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001840 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001841 SourceLocation TypeidLoc,
1842 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001843 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001844 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001845 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001846 }
Mike Stump1eb44332009-09-09 15:08:12 +00001847
Francois Pichet01b7c302010-09-08 12:20:18 +00001848
Douglas Gregorb98b1992009-08-11 05:31:07 +00001849 /// \brief Build a new C++ typeid(expr) expression.
1850 ///
1851 /// By default, performs semantic analysis to build the new expression.
1852 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001853 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001854 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001855 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001856 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001857 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001858 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001859 }
1860
Francois Pichet01b7c302010-09-08 12:20:18 +00001861 /// \brief Build a new C++ __uuidof(type) expression.
1862 ///
1863 /// By default, performs semantic analysis to build the new expression.
1864 /// Subclasses may override this routine to provide different behavior.
1865 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1866 SourceLocation TypeidLoc,
1867 TypeSourceInfo *Operand,
1868 SourceLocation RParenLoc) {
1869 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1870 RParenLoc);
1871 }
1872
1873 /// \brief Build a new C++ __uuidof(expr) expression.
1874 ///
1875 /// By default, performs semantic analysis to build the new expression.
1876 /// Subclasses may override this routine to provide different behavior.
1877 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1878 SourceLocation TypeidLoc,
1879 Expr *Operand,
1880 SourceLocation RParenLoc) {
1881 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1882 RParenLoc);
1883 }
1884
Douglas Gregorb98b1992009-08-11 05:31:07 +00001885 /// \brief Build a new C++ "this" expression.
1886 ///
1887 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001888 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001889 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001890 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001891 QualType ThisType,
1892 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001893 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001894 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001895 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1896 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001897 }
1898
1899 /// \brief Build a new C++ throw expression.
1900 ///
1901 /// By default, performs semantic analysis to build the new expression.
1902 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001903 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1904 bool IsThrownVariableInScope) {
1905 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001906 }
1907
1908 /// \brief Build a new C++ default-argument expression.
1909 ///
1910 /// By default, builds a new default-argument expression, which does not
1911 /// require any semantic analysis. Subclasses may override this routine to
1912 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001913 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001914 ParmVarDecl *Param) {
1915 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1916 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001917 }
1918
1919 /// \brief Build a new C++ zero-initialization expression.
1920 ///
1921 /// By default, performs semantic analysis to build the new expression.
1922 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001923 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1924 SourceLocation LParenLoc,
1925 SourceLocation RParenLoc) {
1926 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001927 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001928 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001929 }
Mike Stump1eb44332009-09-09 15:08:12 +00001930
Douglas Gregorb98b1992009-08-11 05:31:07 +00001931 /// \brief Build a new C++ "new" expression.
1932 ///
1933 /// By default, performs semantic analysis to build the new expression.
1934 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001935 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001936 bool UseGlobal,
1937 SourceLocation PlacementLParen,
1938 MultiExprArg PlacementArgs,
1939 SourceLocation PlacementRParen,
1940 SourceRange TypeIdParens,
1941 QualType AllocatedType,
1942 TypeSourceInfo *AllocatedTypeInfo,
1943 Expr *ArraySize,
1944 SourceLocation ConstructorLParen,
1945 MultiExprArg ConstructorArgs,
1946 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001947 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001948 PlacementLParen,
1949 move(PlacementArgs),
1950 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001951 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001952 AllocatedType,
1953 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001954 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001955 ConstructorLParen,
1956 move(ConstructorArgs),
1957 ConstructorRParen);
1958 }
Mike Stump1eb44332009-09-09 15:08:12 +00001959
Douglas Gregorb98b1992009-08-11 05:31:07 +00001960 /// \brief Build a new C++ "delete" expression.
1961 ///
1962 /// By default, performs semantic analysis to build the new expression.
1963 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001964 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001965 bool IsGlobalDelete,
1966 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001967 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001968 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001969 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001970 }
Mike Stump1eb44332009-09-09 15:08:12 +00001971
Douglas Gregorb98b1992009-08-11 05:31:07 +00001972 /// \brief Build a new unary type trait expression.
1973 ///
1974 /// By default, performs semantic analysis to build the new expression.
1975 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001976 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001977 SourceLocation StartLoc,
1978 TypeSourceInfo *T,
1979 SourceLocation RParenLoc) {
1980 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001981 }
1982
Francois Pichet6ad6f282010-12-07 00:08:36 +00001983 /// \brief Build a new binary type trait expression.
1984 ///
1985 /// By default, performs semantic analysis to build the new expression.
1986 /// Subclasses may override this routine to provide different behavior.
1987 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1988 SourceLocation StartLoc,
1989 TypeSourceInfo *LhsT,
1990 TypeSourceInfo *RhsT,
1991 SourceLocation RParenLoc) {
1992 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1993 }
1994
John Wiegley21ff2e52011-04-28 00:16:57 +00001995 /// \brief Build a new array type trait expression.
1996 ///
1997 /// By default, performs semantic analysis to build the new expression.
1998 /// Subclasses may override this routine to provide different behavior.
1999 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2000 SourceLocation StartLoc,
2001 TypeSourceInfo *TSInfo,
2002 Expr *DimExpr,
2003 SourceLocation RParenLoc) {
2004 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2005 }
2006
John Wiegley55262202011-04-25 06:54:41 +00002007 /// \brief Build a new expression trait expression.
2008 ///
2009 /// By default, performs semantic analysis to build the new expression.
2010 /// Subclasses may override this routine to provide different behavior.
2011 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2012 SourceLocation StartLoc,
2013 Expr *Queried,
2014 SourceLocation RParenLoc) {
2015 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2016 }
2017
Mike Stump1eb44332009-09-09 15:08:12 +00002018 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002019 /// expression.
2020 ///
2021 /// By default, performs semantic analysis to build the new expression.
2022 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002023 ExprResult RebuildDependentScopeDeclRefExpr(
2024 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002025 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002026 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002027 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002028 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002029
2030 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00002031 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002032 *TemplateArgs);
2033
Abramo Bagnara25777432010-08-11 22:01:17 +00002034 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002035 }
2036
2037 /// \brief Build a new template-id expression.
2038 ///
2039 /// By default, performs semantic analysis to build the new expression.
2040 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002041 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00002042 LookupResult &R,
2043 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00002044 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00002045 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002046 }
2047
2048 /// \brief Build a new object-construction expression.
2049 ///
2050 /// By default, performs semantic analysis to build the new expression.
2051 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002052 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002053 SourceLocation Loc,
2054 CXXConstructorDecl *Constructor,
2055 bool IsElidable,
2056 MultiExprArg Args,
2057 bool HadMultipleCandidates,
2058 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002059 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002060 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00002061 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00002062 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002063 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002064 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002065
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002066 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002067 move_arg(ConvertedArgs),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002068 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002069 RequiresZeroInit, ConstructKind,
2070 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002071 }
2072
2073 /// \brief Build a new object-construction expression.
2074 ///
2075 /// By default, performs semantic analysis to build the new expression.
2076 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002077 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2078 SourceLocation LParenLoc,
2079 MultiExprArg Args,
2080 SourceLocation RParenLoc) {
2081 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002082 LParenLoc,
2083 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002084 RParenLoc);
2085 }
2086
2087 /// \brief Build a new object-construction expression.
2088 ///
2089 /// By default, performs semantic analysis to build the new expression.
2090 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002091 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2092 SourceLocation LParenLoc,
2093 MultiExprArg Args,
2094 SourceLocation RParenLoc) {
2095 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002096 LParenLoc,
2097 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002098 RParenLoc);
2099 }
Mike Stump1eb44332009-09-09 15:08:12 +00002100
Douglas Gregorb98b1992009-08-11 05:31:07 +00002101 /// \brief Build a new member reference expression.
2102 ///
2103 /// By default, performs semantic analysis to build the new expression.
2104 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002105 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002106 QualType BaseType,
2107 bool IsArrow,
2108 SourceLocation OperatorLoc,
2109 NestedNameSpecifierLoc QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00002110 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002111 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002112 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002113 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002114 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002115
John McCall9ae2f072010-08-23 23:25:46 +00002116 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002117 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00002118 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002119 MemberNameInfo,
2120 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002121 }
2122
John McCall129e2df2009-11-30 22:42:35 +00002123 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002124 ///
2125 /// By default, performs semantic analysis to build the new expression.
2126 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002127 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2128 SourceLocation OperatorLoc,
2129 bool IsArrow,
2130 NestedNameSpecifierLoc QualifierLoc,
2131 NamedDecl *FirstQualifierInScope,
2132 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002133 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002134 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002135 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002136
John McCall9ae2f072010-08-23 23:25:46 +00002137 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002138 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00002139 SS, FirstQualifierInScope,
2140 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002141 }
Mike Stump1eb44332009-09-09 15:08:12 +00002142
Sebastian Redl2e156222010-09-10 20:55:43 +00002143 /// \brief Build a new noexcept expression.
2144 ///
2145 /// By default, performs semantic analysis to build the new expression.
2146 /// Subclasses may override this routine to provide different behavior.
2147 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2148 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2149 }
2150
Douglas Gregoree8aff02011-01-04 17:33:58 +00002151 /// \brief Build a new expression to compute the length of a parameter pack.
2152 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2153 SourceLocation PackLoc,
2154 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002155 llvm::Optional<unsigned> Length) {
2156 if (Length)
2157 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2158 OperatorLoc, Pack, PackLoc,
2159 RParenLoc, *Length);
2160
Douglas Gregoree8aff02011-01-04 17:33:58 +00002161 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2162 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002163 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002164 }
2165
Douglas Gregorb98b1992009-08-11 05:31:07 +00002166 /// \brief Build a new Objective-C @encode expression.
2167 ///
2168 /// By default, performs semantic analysis to build the new expression.
2169 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002170 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002171 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002172 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002173 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002174 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002175 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002176
Douglas Gregor92e986e2010-04-22 16:44:27 +00002177 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002178 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002179 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002180 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002181 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002182 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002183 MultiExprArg Args,
2184 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002185 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2186 ReceiverTypeInfo->getType(),
2187 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002188 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002189 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002190 }
2191
2192 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002193 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002194 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002195 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002196 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002197 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002198 MultiExprArg Args,
2199 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002200 return SemaRef.BuildInstanceMessage(Receiver,
2201 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002202 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002203 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002204 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002205 }
2206
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002207 /// \brief Build a new Objective-C ivar reference expression.
2208 ///
2209 /// By default, performs semantic analysis to build the new expression.
2210 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002211 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002212 SourceLocation IvarLoc,
2213 bool IsArrow, bool IsFreeIvar) {
2214 // FIXME: We lose track of the IsFreeIvar bit.
2215 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002216 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002217 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2218 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002219 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002220 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002221 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002222 false);
John Wiegley429bb272011-04-08 18:41:53 +00002223 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002224 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002225
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002226 if (Result.get())
2227 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002228
John Wiegley429bb272011-04-08 18:41:53 +00002229 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002230 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002231 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002232 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002233 /*TemplateArgs=*/0);
2234 }
Douglas Gregore3303542010-04-26 20:47:02 +00002235
2236 /// \brief Build a new Objective-C property reference expression.
2237 ///
2238 /// By default, performs semantic analysis to build the new expression.
2239 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002240 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002241 ObjCPropertyDecl *Property,
2242 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002243 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002244 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002245 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2246 Sema::LookupMemberName);
2247 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002248 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002249 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002250 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002251 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002252 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002253
Douglas Gregore3303542010-04-26 20:47:02 +00002254 if (Result.get())
2255 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002256
John Wiegley429bb272011-04-08 18:41:53 +00002257 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002258 /*FIXME:*/PropertyLoc, IsArrow,
2259 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00002260 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002261 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002262 /*TemplateArgs=*/0);
2263 }
Sean Huntc3021132010-05-05 15:23:54 +00002264
John McCall12f78a62010-12-02 01:19:52 +00002265 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002266 ///
2267 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002268 /// Subclasses may override this routine to provide different behavior.
2269 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2270 ObjCMethodDecl *Getter,
2271 ObjCMethodDecl *Setter,
2272 SourceLocation PropertyLoc) {
2273 // Since these expressions can only be value-dependent, we do not
2274 // need to perform semantic analysis again.
2275 return Owned(
2276 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2277 VK_LValue, OK_ObjCProperty,
2278 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002279 }
2280
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002281 /// \brief Build a new Objective-C "isa" expression.
2282 ///
2283 /// By default, performs semantic analysis to build the new expression.
2284 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002285 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002286 bool IsArrow) {
2287 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002288 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002289 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2290 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002291 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002292 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002293 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002294 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002295 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002296
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002297 if (Result.get())
2298 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002299
John Wiegley429bb272011-04-08 18:41:53 +00002300 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002301 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002302 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002303 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002304 /*TemplateArgs=*/0);
2305 }
Sean Huntc3021132010-05-05 15:23:54 +00002306
Douglas Gregorb98b1992009-08-11 05:31:07 +00002307 /// \brief Build a new shuffle vector expression.
2308 ///
2309 /// By default, performs semantic analysis to build the new expression.
2310 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002311 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002312 MultiExprArg SubExprs,
2313 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002314 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002315 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002316 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2317 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2318 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2319 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002320
Douglas Gregorb98b1992009-08-11 05:31:07 +00002321 // Build a reference to the __builtin_shufflevector builtin
2322 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002323 ExprResult Callee
2324 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2325 VK_LValue, BuiltinLoc));
2326 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2327 if (Callee.isInvalid())
2328 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002329
2330 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002331 unsigned NumSubExprs = SubExprs.size();
2332 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002333 ExprResult TheCall = SemaRef.Owned(
2334 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002335 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002336 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002337 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002338 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002339
Douglas Gregorb98b1992009-08-11 05:31:07 +00002340 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002341 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002342 }
John McCall43fed0d2010-11-12 08:19:04 +00002343
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002344 /// \brief Build a new template argument pack expansion.
2345 ///
2346 /// By default, performs semantic analysis to build a new pack expansion
2347 /// for a template argument. Subclasses may override this routine to provide
2348 /// different behavior.
2349 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002350 SourceLocation EllipsisLoc,
2351 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002352 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002353 case TemplateArgument::Expression: {
2354 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002355 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2356 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002357 if (Result.isInvalid())
2358 return TemplateArgumentLoc();
2359
2360 return TemplateArgumentLoc(Result.get(), Result.get());
2361 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002362
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002363 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002364 return TemplateArgumentLoc(TemplateArgument(
2365 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002366 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002367 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002368 Pattern.getTemplateNameLoc(),
2369 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002370
2371 case TemplateArgument::Null:
2372 case TemplateArgument::Integral:
2373 case TemplateArgument::Declaration:
2374 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002375 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002376 llvm_unreachable("Pack expansion pattern has no parameter packs");
2377
2378 case TemplateArgument::Type:
2379 if (TypeSourceInfo *Expansion
2380 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002381 EllipsisLoc,
2382 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002383 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2384 Expansion);
2385 break;
2386 }
2387
2388 return TemplateArgumentLoc();
2389 }
2390
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002391 /// \brief Build a new expression pack expansion.
2392 ///
2393 /// By default, performs semantic analysis to build a new pack expansion
2394 /// for an expression. Subclasses may override this routine to provide
2395 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002396 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2397 llvm::Optional<unsigned> NumExpansions) {
2398 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002399 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002400
2401 /// \brief Build a new atomic operation expression.
2402 ///
2403 /// By default, performs semantic analysis to build the new expression.
2404 /// Subclasses may override this routine to provide different behavior.
2405 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2406 MultiExprArg SubExprs,
2407 QualType RetTy,
2408 AtomicExpr::AtomicOp Op,
2409 SourceLocation RParenLoc) {
2410 // Just create the expression; there is not any interesting semantic
2411 // analysis here because we can't actually build an AtomicExpr until
2412 // we are sure it is semantically sound.
2413 unsigned NumSubExprs = SubExprs.size();
2414 Expr **Subs = (Expr **)SubExprs.release();
2415 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2416 NumSubExprs, RetTy, Op,
2417 RParenLoc);
2418 }
2419
John McCall43fed0d2010-11-12 08:19:04 +00002420private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002421 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2422 QualType ObjectType,
2423 NamedDecl *FirstQualifierInScope,
2424 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002425
2426 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2427 QualType ObjectType,
2428 NamedDecl *FirstQualifierInScope,
2429 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002430};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002431
Douglas Gregor43959a92009-08-20 07:17:43 +00002432template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002433StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002434 if (!S)
2435 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002436
Douglas Gregor43959a92009-08-20 07:17:43 +00002437 switch (S->getStmtClass()) {
2438 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002439
Douglas Gregor43959a92009-08-20 07:17:43 +00002440 // Transform individual statement nodes
2441#define STMT(Node, Parent) \
2442 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002443#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002444#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002445#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002446
Douglas Gregor43959a92009-08-20 07:17:43 +00002447 // Transform expressions by calling TransformExpr.
2448#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002449#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002450#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002451#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002452 {
John McCall60d7b3a2010-08-24 06:29:42 +00002453 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002454 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002455 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002456
John McCall9ae2f072010-08-23 23:25:46 +00002457 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002458 }
Mike Stump1eb44332009-09-09 15:08:12 +00002459 }
2460
John McCall3fa5cae2010-10-26 07:05:15 +00002461 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002462}
Mike Stump1eb44332009-09-09 15:08:12 +00002463
2464
Douglas Gregor670444e2009-08-04 22:27:00 +00002465template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002466ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002467 if (!E)
2468 return SemaRef.Owned(E);
2469
2470 switch (E->getStmtClass()) {
2471 case Stmt::NoStmtClass: break;
2472#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002473#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002474#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002475 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002476#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002477 }
2478
John McCall3fa5cae2010-10-26 07:05:15 +00002479 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002480}
2481
2482template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002483bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2484 unsigned NumInputs,
2485 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002486 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002487 bool *ArgChanged) {
2488 for (unsigned I = 0; I != NumInputs; ++I) {
2489 // If requested, drop call arguments that need to be dropped.
2490 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2491 if (ArgChanged)
2492 *ArgChanged = true;
2493
2494 break;
2495 }
2496
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002497 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2498 Expr *Pattern = Expansion->getPattern();
2499
Chris Lattner686775d2011-07-20 06:58:45 +00002500 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002501 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2502 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2503
2504 // Determine whether the set of unexpanded parameter packs can and should
2505 // be expanded.
2506 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002507 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002508 llvm::Optional<unsigned> OrigNumExpansions
2509 = Expansion->getNumExpansions();
2510 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002511 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2512 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002513 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002514 Expand, RetainExpansion,
2515 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002516 return true;
2517
2518 if (!Expand) {
2519 // The transform has determined that we should perform a simple
2520 // transformation on the pack expansion, producing another pack
2521 // expansion.
2522 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2523 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2524 if (OutPattern.isInvalid())
2525 return true;
2526
2527 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002528 Expansion->getEllipsisLoc(),
2529 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002530 if (Out.isInvalid())
2531 return true;
2532
2533 if (ArgChanged)
2534 *ArgChanged = true;
2535 Outputs.push_back(Out.get());
2536 continue;
2537 }
John McCallc8fc90a2011-07-06 07:30:07 +00002538
2539 // Record right away that the argument was changed. This needs
2540 // to happen even if the array expands to nothing.
2541 if (ArgChanged) *ArgChanged = true;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002542
2543 // The transform has determined that we should perform an elementwise
2544 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002545 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002546 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2547 ExprResult Out = getDerived().TransformExpr(Pattern);
2548 if (Out.isInvalid())
2549 return true;
2550
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002551 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002552 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2553 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002554 if (Out.isInvalid())
2555 return true;
2556 }
2557
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002558 Outputs.push_back(Out.get());
2559 }
2560
2561 continue;
2562 }
2563
Douglas Gregoraa165f82011-01-03 19:04:46 +00002564 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2565 if (Result.isInvalid())
2566 return true;
2567
2568 if (Result.get() != Inputs[I] && ArgChanged)
2569 *ArgChanged = true;
2570
2571 Outputs.push_back(Result.get());
2572 }
2573
2574 return false;
2575}
2576
2577template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002578NestedNameSpecifierLoc
2579TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2580 NestedNameSpecifierLoc NNS,
2581 QualType ObjectType,
2582 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002583 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002584 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2585 Qualifier = Qualifier.getPrefix())
2586 Qualifiers.push_back(Qualifier);
2587
2588 CXXScopeSpec SS;
2589 while (!Qualifiers.empty()) {
2590 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2591 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2592
2593 switch (QNNS->getKind()) {
2594 case NestedNameSpecifier::Identifier:
2595 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2596 *QNNS->getAsIdentifier(),
2597 Q.getLocalBeginLoc(),
2598 Q.getLocalEndLoc(),
2599 ObjectType, false, SS,
2600 FirstQualifierInScope, false))
2601 return NestedNameSpecifierLoc();
2602
2603 break;
2604
2605 case NestedNameSpecifier::Namespace: {
2606 NamespaceDecl *NS
2607 = cast_or_null<NamespaceDecl>(
2608 getDerived().TransformDecl(
2609 Q.getLocalBeginLoc(),
2610 QNNS->getAsNamespace()));
2611 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2612 break;
2613 }
2614
2615 case NestedNameSpecifier::NamespaceAlias: {
2616 NamespaceAliasDecl *Alias
2617 = cast_or_null<NamespaceAliasDecl>(
2618 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2619 QNNS->getAsNamespaceAlias()));
2620 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2621 Q.getLocalEndLoc());
2622 break;
2623 }
2624
2625 case NestedNameSpecifier::Global:
2626 // There is no meaningful transformation that one could perform on the
2627 // global scope.
2628 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2629 break;
2630
2631 case NestedNameSpecifier::TypeSpecWithTemplate:
2632 case NestedNameSpecifier::TypeSpec: {
2633 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2634 FirstQualifierInScope, SS);
2635
2636 if (!TL)
2637 return NestedNameSpecifierLoc();
2638
2639 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2640 (SemaRef.getLangOptions().CPlusPlus0x &&
2641 TL.getType()->isEnumeralType())) {
2642 assert(!TL.getType().hasLocalQualifiers() &&
2643 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002644 if (TL.getType()->isEnumeralType())
2645 SemaRef.Diag(TL.getBeginLoc(),
2646 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002647 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2648 Q.getLocalEndLoc());
2649 break;
2650 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002651 // If the nested-name-specifier is an invalid type def, don't emit an
2652 // error because a previous error should have already been emitted.
2653 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2654 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2655 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2656 << TL.getType() << SS.getRange();
2657 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002658 return NestedNameSpecifierLoc();
2659 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002660 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002661
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002662 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002663 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002664 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002665 }
2666
2667 // Don't rebuild the nested-name-specifier if we don't have to.
2668 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2669 !getDerived().AlwaysRebuild())
2670 return NNS;
2671
2672 // If we can re-use the source-location data from the original
2673 // nested-name-specifier, do so.
2674 if (SS.location_size() == NNS.getDataLength() &&
2675 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2676 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2677
2678 // Allocate new nested-name-specifier location information.
2679 return SS.getWithLocInContext(SemaRef.Context);
2680}
2681
2682template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002683DeclarationNameInfo
2684TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002685::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002686 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002687 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002688 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002689
2690 switch (Name.getNameKind()) {
2691 case DeclarationName::Identifier:
2692 case DeclarationName::ObjCZeroArgSelector:
2693 case DeclarationName::ObjCOneArgSelector:
2694 case DeclarationName::ObjCMultiArgSelector:
2695 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002696 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002697 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002698 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002699
Douglas Gregor81499bb2009-09-03 22:13:48 +00002700 case DeclarationName::CXXConstructorName:
2701 case DeclarationName::CXXDestructorName:
2702 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002703 TypeSourceInfo *NewTInfo;
2704 CanQualType NewCanTy;
2705 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002706 NewTInfo = getDerived().TransformType(OldTInfo);
2707 if (!NewTInfo)
2708 return DeclarationNameInfo();
2709 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002710 }
2711 else {
2712 NewTInfo = 0;
2713 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002714 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002715 if (NewT.isNull())
2716 return DeclarationNameInfo();
2717 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2718 }
Mike Stump1eb44332009-09-09 15:08:12 +00002719
Abramo Bagnara25777432010-08-11 22:01:17 +00002720 DeclarationName NewName
2721 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2722 NewCanTy);
2723 DeclarationNameInfo NewNameInfo(NameInfo);
2724 NewNameInfo.setName(NewName);
2725 NewNameInfo.setNamedTypeInfo(NewTInfo);
2726 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002727 }
Mike Stump1eb44332009-09-09 15:08:12 +00002728 }
2729
David Blaikieb219cfc2011-09-23 05:06:16 +00002730 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002731}
2732
2733template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002734TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002735TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2736 TemplateName Name,
2737 SourceLocation NameLoc,
2738 QualType ObjectType,
2739 NamedDecl *FirstQualifierInScope) {
2740 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2741 TemplateDecl *Template = QTN->getTemplateDecl();
2742 assert(Template && "qualified template name must refer to a template");
2743
2744 TemplateDecl *TransTemplate
2745 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2746 Template));
2747 if (!TransTemplate)
2748 return TemplateName();
2749
2750 if (!getDerived().AlwaysRebuild() &&
2751 SS.getScopeRep() == QTN->getQualifier() &&
2752 TransTemplate == Template)
2753 return Name;
2754
2755 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2756 TransTemplate);
2757 }
2758
2759 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2760 if (SS.getScopeRep()) {
2761 // These apply to the scope specifier, not the template.
2762 ObjectType = QualType();
2763 FirstQualifierInScope = 0;
2764 }
2765
2766 if (!getDerived().AlwaysRebuild() &&
2767 SS.getScopeRep() == DTN->getQualifier() &&
2768 ObjectType.isNull())
2769 return Name;
2770
2771 if (DTN->isIdentifier()) {
2772 return getDerived().RebuildTemplateName(SS,
2773 *DTN->getIdentifier(),
2774 NameLoc,
2775 ObjectType,
2776 FirstQualifierInScope);
2777 }
2778
2779 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2780 ObjectType);
2781 }
2782
2783 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2784 TemplateDecl *TransTemplate
2785 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2786 Template));
2787 if (!TransTemplate)
2788 return TemplateName();
2789
2790 if (!getDerived().AlwaysRebuild() &&
2791 TransTemplate == Template)
2792 return Name;
2793
2794 return TemplateName(TransTemplate);
2795 }
2796
2797 if (SubstTemplateTemplateParmPackStorage *SubstPack
2798 = Name.getAsSubstTemplateTemplateParmPack()) {
2799 TemplateTemplateParmDecl *TransParam
2800 = cast_or_null<TemplateTemplateParmDecl>(
2801 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2802 if (!TransParam)
2803 return TemplateName();
2804
2805 if (!getDerived().AlwaysRebuild() &&
2806 TransParam == SubstPack->getParameterPack())
2807 return Name;
2808
2809 return getDerived().RebuildTemplateName(TransParam,
2810 SubstPack->getArgumentPack());
2811 }
2812
2813 // These should be getting filtered out before they reach the AST.
2814 llvm_unreachable("overloaded function decl survived to here");
2815 return TemplateName();
2816}
2817
2818template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002819void TreeTransform<Derived>::InventTemplateArgumentLoc(
2820 const TemplateArgument &Arg,
2821 TemplateArgumentLoc &Output) {
2822 SourceLocation Loc = getDerived().getBaseLocation();
2823 switch (Arg.getKind()) {
2824 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002825 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002826 break;
2827
2828 case TemplateArgument::Type:
2829 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002830 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002831
John McCall833ca992009-10-29 08:12:44 +00002832 break;
2833
Douglas Gregor788cd062009-11-11 01:00:40 +00002834 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002835 case TemplateArgument::TemplateExpansion: {
2836 NestedNameSpecifierLocBuilder Builder;
2837 TemplateName Template = Arg.getAsTemplate();
2838 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2839 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2840 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2841 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2842
2843 if (Arg.getKind() == TemplateArgument::Template)
2844 Output = TemplateArgumentLoc(Arg,
2845 Builder.getWithLocInContext(SemaRef.Context),
2846 Loc);
2847 else
2848 Output = TemplateArgumentLoc(Arg,
2849 Builder.getWithLocInContext(SemaRef.Context),
2850 Loc, Loc);
2851
Douglas Gregor788cd062009-11-11 01:00:40 +00002852 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002853 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002854
John McCall833ca992009-10-29 08:12:44 +00002855 case TemplateArgument::Expression:
2856 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2857 break;
2858
2859 case TemplateArgument::Declaration:
2860 case TemplateArgument::Integral:
2861 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002862 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002863 break;
2864 }
2865}
2866
2867template<typename Derived>
2868bool TreeTransform<Derived>::TransformTemplateArgument(
2869 const TemplateArgumentLoc &Input,
2870 TemplateArgumentLoc &Output) {
2871 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002872 switch (Arg.getKind()) {
2873 case TemplateArgument::Null:
2874 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002875 Output = Input;
2876 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002877
Douglas Gregor670444e2009-08-04 22:27:00 +00002878 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002879 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002880 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002881 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002882
2883 DI = getDerived().TransformType(DI);
2884 if (!DI) return true;
2885
2886 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2887 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002888 }
Mike Stump1eb44332009-09-09 15:08:12 +00002889
Douglas Gregor670444e2009-08-04 22:27:00 +00002890 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002891 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002892 DeclarationName Name;
2893 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2894 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002895 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002896 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002897 if (!D) return true;
2898
John McCall828bff22009-10-29 18:45:58 +00002899 Expr *SourceExpr = Input.getSourceDeclExpression();
2900 if (SourceExpr) {
2901 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00002902 Sema::ConstantEvaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002903 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002904 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002905 }
2906
2907 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002908 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002909 }
Mike Stump1eb44332009-09-09 15:08:12 +00002910
Douglas Gregor788cd062009-11-11 01:00:40 +00002911 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002912 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2913 if (QualifierLoc) {
2914 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2915 if (!QualifierLoc)
2916 return true;
2917 }
2918
Douglas Gregor1d752d72011-03-02 18:46:51 +00002919 CXXScopeSpec SS;
2920 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00002921 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00002922 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2923 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00002924 if (Template.isNull())
2925 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002926
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002927 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00002928 Input.getTemplateNameLoc());
2929 return false;
2930 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002931
2932 case TemplateArgument::TemplateExpansion:
2933 llvm_unreachable("Caller should expand pack expansions");
2934
Douglas Gregor670444e2009-08-04 22:27:00 +00002935 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00002936 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00002937 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00002938 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002939
John McCall833ca992009-10-29 08:12:44 +00002940 Expr *InputExpr = Input.getSourceExpression();
2941 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2942
Chris Lattner223de242011-04-25 20:37:58 +00002943 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall833ca992009-10-29 08:12:44 +00002944 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002945 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002946 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002947 }
Mike Stump1eb44332009-09-09 15:08:12 +00002948
Douglas Gregor670444e2009-08-04 22:27:00 +00002949 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00002950 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00002951 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002952 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002953 AEnd = Arg.pack_end();
2954 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002955
John McCall833ca992009-10-29 08:12:44 +00002956 // FIXME: preserve source information here when we start
2957 // caring about parameter packs.
2958
John McCall828bff22009-10-29 18:45:58 +00002959 TemplateArgumentLoc InputArg;
2960 TemplateArgumentLoc OutputArg;
2961 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2962 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002963 return true;
2964
John McCall828bff22009-10-29 18:45:58 +00002965 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002966 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002967
2968 TemplateArgument *TransformedArgsPtr
2969 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2970 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2971 TransformedArgsPtr);
2972 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2973 TransformedArgs.size()),
2974 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002975 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002976 }
2977 }
Mike Stump1eb44332009-09-09 15:08:12 +00002978
Douglas Gregor670444e2009-08-04 22:27:00 +00002979 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002980 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002981}
2982
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002983/// \brief Iterator adaptor that invents template argument location information
2984/// for each of the template arguments in its underlying iterator.
2985template<typename Derived, typename InputIterator>
2986class TemplateArgumentLocInventIterator {
2987 TreeTransform<Derived> &Self;
2988 InputIterator Iter;
2989
2990public:
2991 typedef TemplateArgumentLoc value_type;
2992 typedef TemplateArgumentLoc reference;
2993 typedef typename std::iterator_traits<InputIterator>::difference_type
2994 difference_type;
2995 typedef std::input_iterator_tag iterator_category;
2996
2997 class pointer {
2998 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002999
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003000 public:
3001 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3002
3003 const TemplateArgumentLoc *operator->() const { return &Arg; }
3004 };
3005
3006 TemplateArgumentLocInventIterator() { }
3007
3008 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3009 InputIterator Iter)
3010 : Self(Self), Iter(Iter) { }
3011
3012 TemplateArgumentLocInventIterator &operator++() {
3013 ++Iter;
3014 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003015 }
3016
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003017 TemplateArgumentLocInventIterator operator++(int) {
3018 TemplateArgumentLocInventIterator Old(*this);
3019 ++(*this);
3020 return Old;
3021 }
3022
3023 reference operator*() const {
3024 TemplateArgumentLoc Result;
3025 Self.InventTemplateArgumentLoc(*Iter, Result);
3026 return Result;
3027 }
3028
3029 pointer operator->() const { return pointer(**this); }
3030
3031 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3032 const TemplateArgumentLocInventIterator &Y) {
3033 return X.Iter == Y.Iter;
3034 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003035
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003036 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3037 const TemplateArgumentLocInventIterator &Y) {
3038 return X.Iter != Y.Iter;
3039 }
3040};
3041
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003042template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003043template<typename InputIterator>
3044bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3045 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003046 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003047 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003048 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003049 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003050
3051 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3052 // Unpack argument packs, which we translate them into separate
3053 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003054 // FIXME: We could do much better if we could guarantee that the
3055 // TemplateArgumentLocInfo for the pack expansion would be usable for
3056 // all of the template arguments in the argument pack.
3057 typedef TemplateArgumentLocInventIterator<Derived,
3058 TemplateArgument::pack_iterator>
3059 PackLocIterator;
3060 if (TransformTemplateArguments(PackLocIterator(*this,
3061 In.getArgument().pack_begin()),
3062 PackLocIterator(*this,
3063 In.getArgument().pack_end()),
3064 Outputs))
3065 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003066
3067 continue;
3068 }
3069
3070 if (In.getArgument().isPackExpansion()) {
3071 // We have a pack expansion, for which we will be substituting into
3072 // the pattern.
3073 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003074 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003075 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003076 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3077 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003078
Chris Lattner686775d2011-07-20 06:58:45 +00003079 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003080 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3081 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3082
3083 // Determine whether the set of unexpanded parameter packs can and should
3084 // be expanded.
3085 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003086 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003087 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003088 if (getDerived().TryExpandParameterPacks(Ellipsis,
3089 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003090 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003091 Expand,
3092 RetainExpansion,
3093 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003094 return true;
3095
3096 if (!Expand) {
3097 // The transform has determined that we should perform a simple
3098 // transformation on the pack expansion, producing another pack
3099 // expansion.
3100 TemplateArgumentLoc OutPattern;
3101 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3102 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3103 return true;
3104
Douglas Gregorcded4f62011-01-14 17:04:44 +00003105 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3106 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003107 if (Out.getArgument().isNull())
3108 return true;
3109
3110 Outputs.addArgument(Out);
3111 continue;
3112 }
3113
3114 // The transform has determined that we should perform an elementwise
3115 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003116 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003117 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3118
3119 if (getDerived().TransformTemplateArgument(Pattern, Out))
3120 return true;
3121
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003122 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003123 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3124 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003125 if (Out.getArgument().isNull())
3126 return true;
3127 }
3128
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003129 Outputs.addArgument(Out);
3130 }
3131
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003132 // If we're supposed to retain a pack expansion, do so by temporarily
3133 // forgetting the partially-substituted parameter pack.
3134 if (RetainExpansion) {
3135 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3136
3137 if (getDerived().TransformTemplateArgument(Pattern, Out))
3138 return true;
3139
Douglas Gregorcded4f62011-01-14 17:04:44 +00003140 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3141 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003142 if (Out.getArgument().isNull())
3143 return true;
3144
3145 Outputs.addArgument(Out);
3146 }
Douglas Gregord3731192011-01-10 07:32:04 +00003147
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003148 continue;
3149 }
3150
3151 // The simple case:
3152 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003153 return true;
3154
3155 Outputs.addArgument(Out);
3156 }
3157
3158 return false;
3159
3160}
3161
Douglas Gregor577f75a2009-08-04 16:50:30 +00003162//===----------------------------------------------------------------------===//
3163// Type transformation
3164//===----------------------------------------------------------------------===//
3165
3166template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003167QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003168 if (getDerived().AlreadyTransformed(T))
3169 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003170
John McCalla2becad2009-10-21 00:40:46 +00003171 // Temporary workaround. All of these transformations should
3172 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003173 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3174 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003175
John McCall43fed0d2010-11-12 08:19:04 +00003176 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003177
John McCalla2becad2009-10-21 00:40:46 +00003178 if (!NewDI)
3179 return QualType();
3180
3181 return NewDI->getType();
3182}
3183
3184template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003185TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003186 // Refine the base location to the type's location.
3187 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3188 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003189 if (getDerived().AlreadyTransformed(DI->getType()))
3190 return DI;
3191
3192 TypeLocBuilder TLB;
3193
3194 TypeLoc TL = DI->getTypeLoc();
3195 TLB.reserve(TL.getFullDataSize());
3196
John McCall43fed0d2010-11-12 08:19:04 +00003197 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003198 if (Result.isNull())
3199 return 0;
3200
John McCalla93c9342009-12-07 02:54:59 +00003201 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003202}
3203
3204template<typename Derived>
3205QualType
John McCall43fed0d2010-11-12 08:19:04 +00003206TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003207 switch (T.getTypeLocClass()) {
3208#define ABSTRACT_TYPELOC(CLASS, PARENT)
3209#define TYPELOC(CLASS, PARENT) \
3210 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003211 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003212#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003213 }
Mike Stump1eb44332009-09-09 15:08:12 +00003214
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003215 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003216 return QualType();
3217}
3218
3219/// FIXME: By default, this routine adds type qualifiers only to types
3220/// that can have qualifiers, and silently suppresses those qualifiers
3221/// that are not permitted (e.g., qualifiers on reference or function
3222/// types). This is the right thing for template instantiation, but
3223/// probably not for other clients.
3224template<typename Derived>
3225QualType
3226TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003227 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003228 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003229
John McCall43fed0d2010-11-12 08:19:04 +00003230 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003231 if (Result.isNull())
3232 return QualType();
3233
3234 // Silently suppress qualifiers if the result type can't be qualified.
3235 // FIXME: this is the right thing for template instantiation, but
3236 // probably not for other clients.
3237 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003238 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003239
John McCallf85e1932011-06-15 23:02:42 +00003240 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003241 // resulting type.
3242 if (Quals.hasObjCLifetime()) {
3243 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3244 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003245 else if (Result.getObjCLifetime()) {
Douglas Gregore559ca12011-06-17 22:11:49 +00003246 // Objective-C ARC:
3247 // A lifetime qualifier applied to a substituted template parameter
3248 // overrides the lifetime qualifier from the template argument.
3249 if (const SubstTemplateTypeParmType *SubstTypeParam
3250 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3251 QualType Replacement = SubstTypeParam->getReplacementType();
3252 Qualifiers Qs = Replacement.getQualifiers();
3253 Qs.removeObjCLifetime();
3254 Replacement
3255 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3256 Qs);
3257 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3258 SubstTypeParam->getReplacedParameter(),
3259 Replacement);
3260 TLB.TypeWasModifiedSafely(Result);
3261 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003262 // Otherwise, complain about the addition of a qualifier to an
3263 // already-qualified type.
3264 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003265 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003266 << Result << R;
3267
Douglas Gregore559ca12011-06-17 22:11:49 +00003268 Quals.removeObjCLifetime();
3269 }
3270 }
3271 }
John McCall28654742010-06-05 06:41:15 +00003272 if (!Quals.empty()) {
3273 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3274 TLB.push<QualifiedTypeLoc>(Result);
3275 // No location information to preserve.
3276 }
John McCalla2becad2009-10-21 00:40:46 +00003277
3278 return Result;
3279}
3280
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003281template<typename Derived>
3282TypeLoc
3283TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3284 QualType ObjectType,
3285 NamedDecl *UnqualLookup,
3286 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003287 QualType T = TL.getType();
3288 if (getDerived().AlreadyTransformed(T))
3289 return TL;
3290
3291 TypeLocBuilder TLB;
3292 QualType Result;
3293
3294 if (isa<TemplateSpecializationType>(T)) {
3295 TemplateSpecializationTypeLoc SpecTL
3296 = cast<TemplateSpecializationTypeLoc>(TL);
3297
3298 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003299 getDerived().TransformTemplateName(SS,
3300 SpecTL.getTypePtr()->getTemplateName(),
3301 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003302 ObjectType, UnqualLookup);
3303 if (Template.isNull())
3304 return TypeLoc();
3305
3306 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3307 Template);
3308 } else if (isa<DependentTemplateSpecializationType>(T)) {
3309 DependentTemplateSpecializationTypeLoc SpecTL
3310 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3311
Douglas Gregora88f09f2011-02-28 17:23:35 +00003312 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003313 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003314 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003315 SpecTL.getNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003316 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003317 if (Template.isNull())
3318 return TypeLoc();
3319
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003320 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003321 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003322 Template,
3323 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003324 } else {
3325 // Nothing special needs to be done for these.
3326 Result = getDerived().TransformType(TLB, TL);
3327 }
3328
3329 if (Result.isNull())
3330 return TypeLoc();
3331
3332 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3333}
3334
Douglas Gregorb71d8212011-03-02 18:32:08 +00003335template<typename Derived>
3336TypeSourceInfo *
3337TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3338 QualType ObjectType,
3339 NamedDecl *UnqualLookup,
3340 CXXScopeSpec &SS) {
3341 // FIXME: Painfully copy-paste from the above!
3342
3343 QualType T = TSInfo->getType();
3344 if (getDerived().AlreadyTransformed(T))
3345 return TSInfo;
3346
3347 TypeLocBuilder TLB;
3348 QualType Result;
3349
3350 TypeLoc TL = TSInfo->getTypeLoc();
3351 if (isa<TemplateSpecializationType>(T)) {
3352 TemplateSpecializationTypeLoc SpecTL
3353 = cast<TemplateSpecializationTypeLoc>(TL);
3354
3355 TemplateName Template
3356 = getDerived().TransformTemplateName(SS,
3357 SpecTL.getTypePtr()->getTemplateName(),
3358 SpecTL.getTemplateNameLoc(),
3359 ObjectType, UnqualLookup);
3360 if (Template.isNull())
3361 return 0;
3362
3363 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3364 Template);
3365 } else if (isa<DependentTemplateSpecializationType>(T)) {
3366 DependentTemplateSpecializationTypeLoc SpecTL
3367 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3368
3369 TemplateName Template
3370 = getDerived().RebuildTemplateName(SS,
3371 *SpecTL.getTypePtr()->getIdentifier(),
3372 SpecTL.getNameLoc(),
3373 ObjectType, UnqualLookup);
3374 if (Template.isNull())
3375 return 0;
3376
3377 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3378 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003379 Template,
3380 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003381 } else {
3382 // Nothing special needs to be done for these.
3383 Result = getDerived().TransformType(TLB, TL);
3384 }
3385
3386 if (Result.isNull())
3387 return 0;
3388
3389 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3390}
3391
John McCalla2becad2009-10-21 00:40:46 +00003392template <class TyLoc> static inline
3393QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3394 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3395 NewT.setNameLoc(T.getNameLoc());
3396 return T.getType();
3397}
3398
John McCalla2becad2009-10-21 00:40:46 +00003399template<typename Derived>
3400QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003401 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003402 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3403 NewT.setBuiltinLoc(T.getBuiltinLoc());
3404 if (T.needsExtraLocalData())
3405 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3406 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003407}
Mike Stump1eb44332009-09-09 15:08:12 +00003408
Douglas Gregor577f75a2009-08-04 16:50:30 +00003409template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003410QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003411 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003412 // FIXME: recurse?
3413 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003414}
Mike Stump1eb44332009-09-09 15:08:12 +00003415
Douglas Gregor577f75a2009-08-04 16:50:30 +00003416template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003417QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003418 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003419 QualType PointeeType
3420 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003421 if (PointeeType.isNull())
3422 return QualType();
3423
3424 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003425 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003426 // A dependent pointer type 'T *' has is being transformed such
3427 // that an Objective-C class type is being replaced for 'T'. The
3428 // resulting pointer type is an ObjCObjectPointerType, not a
3429 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003430 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003431
John McCallc12c5bb2010-05-15 11:32:37 +00003432 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3433 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003434 return Result;
3435 }
John McCall43fed0d2010-11-12 08:19:04 +00003436
Douglas Gregor92e986e2010-04-22 16:44:27 +00003437 if (getDerived().AlwaysRebuild() ||
3438 PointeeType != TL.getPointeeLoc().getType()) {
3439 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3440 if (Result.isNull())
3441 return QualType();
3442 }
John McCallf85e1932011-06-15 23:02:42 +00003443
3444 // Objective-C ARC can add lifetime qualifiers to the type that we're
3445 // pointing to.
3446 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3447
Douglas Gregor92e986e2010-04-22 16:44:27 +00003448 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3449 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003450 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003451}
Mike Stump1eb44332009-09-09 15:08:12 +00003452
3453template<typename Derived>
3454QualType
John McCalla2becad2009-10-21 00:40:46 +00003455TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003456 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003457 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003458 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3459 if (PointeeType.isNull())
3460 return QualType();
3461
3462 QualType Result = TL.getType();
3463 if (getDerived().AlwaysRebuild() ||
3464 PointeeType != TL.getPointeeLoc().getType()) {
3465 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003466 TL.getSigilLoc());
3467 if (Result.isNull())
3468 return QualType();
3469 }
3470
Douglas Gregor39968ad2010-04-22 16:50:51 +00003471 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003472 NewT.setSigilLoc(TL.getSigilLoc());
3473 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003474}
3475
John McCall85737a72009-10-30 00:06:24 +00003476/// Transforms a reference type. Note that somewhat paradoxically we
3477/// don't care whether the type itself is an l-value type or an r-value
3478/// type; we only care if the type was *written* as an l-value type
3479/// or an r-value type.
3480template<typename Derived>
3481QualType
3482TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003483 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003484 const ReferenceType *T = TL.getTypePtr();
3485
3486 // Note that this works with the pointee-as-written.
3487 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3488 if (PointeeType.isNull())
3489 return QualType();
3490
3491 QualType Result = TL.getType();
3492 if (getDerived().AlwaysRebuild() ||
3493 PointeeType != T->getPointeeTypeAsWritten()) {
3494 Result = getDerived().RebuildReferenceType(PointeeType,
3495 T->isSpelledAsLValue(),
3496 TL.getSigilLoc());
3497 if (Result.isNull())
3498 return QualType();
3499 }
3500
John McCallf85e1932011-06-15 23:02:42 +00003501 // Objective-C ARC can add lifetime qualifiers to the type that we're
3502 // referring to.
3503 TLB.TypeWasModifiedSafely(
3504 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3505
John McCall85737a72009-10-30 00:06:24 +00003506 // r-value references can be rebuilt as l-value references.
3507 ReferenceTypeLoc NewTL;
3508 if (isa<LValueReferenceType>(Result))
3509 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3510 else
3511 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3512 NewTL.setSigilLoc(TL.getSigilLoc());
3513
3514 return Result;
3515}
3516
Mike Stump1eb44332009-09-09 15:08:12 +00003517template<typename Derived>
3518QualType
John McCalla2becad2009-10-21 00:40:46 +00003519TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003520 LValueReferenceTypeLoc TL) {
3521 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003522}
3523
Mike Stump1eb44332009-09-09 15:08:12 +00003524template<typename Derived>
3525QualType
John McCalla2becad2009-10-21 00:40:46 +00003526TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003527 RValueReferenceTypeLoc TL) {
3528 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003529}
Mike Stump1eb44332009-09-09 15:08:12 +00003530
Douglas Gregor577f75a2009-08-04 16:50:30 +00003531template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003532QualType
John McCalla2becad2009-10-21 00:40:46 +00003533TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003534 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003535 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003536 if (PointeeType.isNull())
3537 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003538
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003539 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3540 TypeSourceInfo* NewClsTInfo = 0;
3541 if (OldClsTInfo) {
3542 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3543 if (!NewClsTInfo)
3544 return QualType();
3545 }
3546
3547 const MemberPointerType *T = TL.getTypePtr();
3548 QualType OldClsType = QualType(T->getClass(), 0);
3549 QualType NewClsType;
3550 if (NewClsTInfo)
3551 NewClsType = NewClsTInfo->getType();
3552 else {
3553 NewClsType = getDerived().TransformType(OldClsType);
3554 if (NewClsType.isNull())
3555 return QualType();
3556 }
Mike Stump1eb44332009-09-09 15:08:12 +00003557
John McCalla2becad2009-10-21 00:40:46 +00003558 QualType Result = TL.getType();
3559 if (getDerived().AlwaysRebuild() ||
3560 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003561 NewClsType != OldClsType) {
3562 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003563 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003564 if (Result.isNull())
3565 return QualType();
3566 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003567
John McCalla2becad2009-10-21 00:40:46 +00003568 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3569 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003570 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003571
3572 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003573}
3574
Mike Stump1eb44332009-09-09 15:08:12 +00003575template<typename Derived>
3576QualType
John McCalla2becad2009-10-21 00:40:46 +00003577TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003578 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003579 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003580 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003581 if (ElementType.isNull())
3582 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003583
John McCalla2becad2009-10-21 00:40:46 +00003584 QualType Result = TL.getType();
3585 if (getDerived().AlwaysRebuild() ||
3586 ElementType != T->getElementType()) {
3587 Result = getDerived().RebuildConstantArrayType(ElementType,
3588 T->getSizeModifier(),
3589 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003590 T->getIndexTypeCVRQualifiers(),
3591 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003592 if (Result.isNull())
3593 return QualType();
3594 }
Sean Huntc3021132010-05-05 15:23:54 +00003595
John McCalla2becad2009-10-21 00:40:46 +00003596 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3597 NewTL.setLBracketLoc(TL.getLBracketLoc());
3598 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003599
John McCalla2becad2009-10-21 00:40:46 +00003600 Expr *Size = TL.getSizeExpr();
3601 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003602 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3603 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003604 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3605 }
3606 NewTL.setSizeExpr(Size);
3607
3608 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003609}
Mike Stump1eb44332009-09-09 15:08:12 +00003610
Douglas Gregor577f75a2009-08-04 16:50:30 +00003611template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003612QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003613 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003614 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003615 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003616 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003617 if (ElementType.isNull())
3618 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003619
John McCalla2becad2009-10-21 00:40:46 +00003620 QualType Result = TL.getType();
3621 if (getDerived().AlwaysRebuild() ||
3622 ElementType != T->getElementType()) {
3623 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003624 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003625 T->getIndexTypeCVRQualifiers(),
3626 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003627 if (Result.isNull())
3628 return QualType();
3629 }
Sean Huntc3021132010-05-05 15:23:54 +00003630
John McCalla2becad2009-10-21 00:40:46 +00003631 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3632 NewTL.setLBracketLoc(TL.getLBracketLoc());
3633 NewTL.setRBracketLoc(TL.getRBracketLoc());
3634 NewTL.setSizeExpr(0);
3635
3636 return Result;
3637}
3638
3639template<typename Derived>
3640QualType
3641TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003642 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003643 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003644 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3645 if (ElementType.isNull())
3646 return QualType();
3647
John McCall60d7b3a2010-08-24 06:29:42 +00003648 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003649 = getDerived().TransformExpr(T->getSizeExpr());
3650 if (SizeResult.isInvalid())
3651 return QualType();
3652
John McCall9ae2f072010-08-23 23:25:46 +00003653 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003654
3655 QualType Result = TL.getType();
3656 if (getDerived().AlwaysRebuild() ||
3657 ElementType != T->getElementType() ||
3658 Size != T->getSizeExpr()) {
3659 Result = getDerived().RebuildVariableArrayType(ElementType,
3660 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003661 Size,
John McCalla2becad2009-10-21 00:40:46 +00003662 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003663 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003664 if (Result.isNull())
3665 return QualType();
3666 }
Sean Huntc3021132010-05-05 15:23:54 +00003667
John McCalla2becad2009-10-21 00:40:46 +00003668 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3669 NewTL.setLBracketLoc(TL.getLBracketLoc());
3670 NewTL.setRBracketLoc(TL.getRBracketLoc());
3671 NewTL.setSizeExpr(Size);
3672
3673 return Result;
3674}
3675
3676template<typename Derived>
3677QualType
3678TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003679 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003680 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003681 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3682 if (ElementType.isNull())
3683 return QualType();
3684
Richard Smithf6702a32011-12-20 02:08:33 +00003685 // Array bounds are constant expressions.
3686 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3687 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003688
John McCall3b657512011-01-19 10:06:00 +00003689 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3690 Expr *origSize = TL.getSizeExpr();
3691 if (!origSize) origSize = T->getSizeExpr();
3692
3693 ExprResult sizeResult
3694 = getDerived().TransformExpr(origSize);
3695 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003696 return QualType();
3697
John McCall3b657512011-01-19 10:06:00 +00003698 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003699
3700 QualType Result = TL.getType();
3701 if (getDerived().AlwaysRebuild() ||
3702 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003703 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003704 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3705 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003706 size,
John McCalla2becad2009-10-21 00:40:46 +00003707 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003708 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003709 if (Result.isNull())
3710 return QualType();
3711 }
John McCalla2becad2009-10-21 00:40:46 +00003712
3713 // We might have any sort of array type now, but fortunately they
3714 // all have the same location layout.
3715 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3716 NewTL.setLBracketLoc(TL.getLBracketLoc());
3717 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003718 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003719
3720 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003721}
Mike Stump1eb44332009-09-09 15:08:12 +00003722
3723template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003724QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003725 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003726 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003727 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003728
3729 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003730 QualType ElementType = getDerived().TransformType(T->getElementType());
3731 if (ElementType.isNull())
3732 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003733
Richard Smithf6702a32011-12-20 02:08:33 +00003734 // Vector sizes are constant expressions.
3735 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3736 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003737
John McCall60d7b3a2010-08-24 06:29:42 +00003738 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003739 if (Size.isInvalid())
3740 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003741
John McCalla2becad2009-10-21 00:40:46 +00003742 QualType Result = TL.getType();
3743 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003744 ElementType != T->getElementType() ||
3745 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003746 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003747 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003748 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003749 if (Result.isNull())
3750 return QualType();
3751 }
John McCalla2becad2009-10-21 00:40:46 +00003752
3753 // Result might be dependent or not.
3754 if (isa<DependentSizedExtVectorType>(Result)) {
3755 DependentSizedExtVectorTypeLoc NewTL
3756 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3757 NewTL.setNameLoc(TL.getNameLoc());
3758 } else {
3759 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3760 NewTL.setNameLoc(TL.getNameLoc());
3761 }
3762
3763 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003764}
Mike Stump1eb44332009-09-09 15:08:12 +00003765
3766template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003767QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003768 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003769 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003770 QualType ElementType = getDerived().TransformType(T->getElementType());
3771 if (ElementType.isNull())
3772 return QualType();
3773
John McCalla2becad2009-10-21 00:40:46 +00003774 QualType Result = TL.getType();
3775 if (getDerived().AlwaysRebuild() ||
3776 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003777 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003778 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003779 if (Result.isNull())
3780 return QualType();
3781 }
Sean Huntc3021132010-05-05 15:23:54 +00003782
John McCalla2becad2009-10-21 00:40:46 +00003783 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3784 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003785
John McCalla2becad2009-10-21 00:40:46 +00003786 return Result;
3787}
3788
3789template<typename Derived>
3790QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003791 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003792 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003793 QualType ElementType = getDerived().TransformType(T->getElementType());
3794 if (ElementType.isNull())
3795 return QualType();
3796
3797 QualType Result = TL.getType();
3798 if (getDerived().AlwaysRebuild() ||
3799 ElementType != T->getElementType()) {
3800 Result = getDerived().RebuildExtVectorType(ElementType,
3801 T->getNumElements(),
3802 /*FIXME*/ SourceLocation());
3803 if (Result.isNull())
3804 return QualType();
3805 }
Sean Huntc3021132010-05-05 15:23:54 +00003806
John McCalla2becad2009-10-21 00:40:46 +00003807 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3808 NewTL.setNameLoc(TL.getNameLoc());
3809
3810 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003811}
Mike Stump1eb44332009-09-09 15:08:12 +00003812
3813template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003814ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003815TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003816 int indexAdjustment,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003817 llvm::Optional<unsigned> NumExpansions) {
John McCall21ef0fa2010-03-11 09:03:00 +00003818 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003819 TypeSourceInfo *NewDI = 0;
3820
3821 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3822 // If we're substituting into a pack expansion type and we know the
3823 TypeLoc OldTL = OldDI->getTypeLoc();
3824 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3825
3826 TypeLocBuilder TLB;
3827 TypeLoc NewTL = OldDI->getTypeLoc();
3828 TLB.reserve(NewTL.getFullDataSize());
3829
3830 QualType Result = getDerived().TransformType(TLB,
3831 OldExpansionTL.getPatternLoc());
3832 if (Result.isNull())
3833 return 0;
3834
3835 Result = RebuildPackExpansionType(Result,
3836 OldExpansionTL.getPatternLoc().getSourceRange(),
3837 OldExpansionTL.getEllipsisLoc(),
3838 NumExpansions);
3839 if (Result.isNull())
3840 return 0;
3841
3842 PackExpansionTypeLoc NewExpansionTL
3843 = TLB.push<PackExpansionTypeLoc>(Result);
3844 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3845 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3846 } else
3847 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003848 if (!NewDI)
3849 return 0;
3850
John McCallfb44de92011-05-01 22:35:37 +00003851 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003852 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003853
3854 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3855 OldParm->getDeclContext(),
3856 OldParm->getInnerLocStart(),
3857 OldParm->getLocation(),
3858 OldParm->getIdentifier(),
3859 NewDI->getType(),
3860 NewDI,
3861 OldParm->getStorageClass(),
3862 OldParm->getStorageClassAsWritten(),
3863 /* DefArg */ NULL);
3864 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3865 OldParm->getFunctionScopeIndex() + indexAdjustment);
3866 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003867}
3868
3869template<typename Derived>
3870bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003871 TransformFunctionTypeParams(SourceLocation Loc,
3872 ParmVarDecl **Params, unsigned NumParams,
3873 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003874 SmallVectorImpl<QualType> &OutParamTypes,
3875 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003876 int indexAdjustment = 0;
3877
Douglas Gregora009b592011-01-07 00:20:55 +00003878 for (unsigned i = 0; i != NumParams; ++i) {
3879 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003880 assert(OldParm->getFunctionScopeIndex() == i);
3881
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003882 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003883 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003884 if (OldParm->isParameterPack()) {
3885 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003886 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003887
Douglas Gregor603cfb42011-01-05 23:12:31 +00003888 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003889 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3890 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3891 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3892 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003893 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3894
Douglas Gregor603cfb42011-01-05 23:12:31 +00003895 // Determine whether we should expand the parameter packs.
3896 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003897 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003898 llvm::Optional<unsigned> OrigNumExpansions
3899 = ExpansionTL.getTypePtr()->getNumExpansions();
3900 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003901 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3902 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003903 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003904 ShouldExpand,
3905 RetainExpansion,
3906 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003907 return true;
3908 }
3909
3910 if (ShouldExpand) {
3911 // Expand the function parameter pack into multiple, separate
3912 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003913 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003914 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003915 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3916 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003917 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003918 indexAdjustment++,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003919 OrigNumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003920 if (!NewParm)
3921 return true;
3922
Douglas Gregora009b592011-01-07 00:20:55 +00003923 OutParamTypes.push_back(NewParm->getType());
3924 if (PVars)
3925 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003926 }
Douglas Gregord3731192011-01-10 07:32:04 +00003927
3928 // If we're supposed to retain a pack expansion, do so by temporarily
3929 // forgetting the partially-substituted parameter pack.
3930 if (RetainExpansion) {
3931 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3932 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003933 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003934 indexAdjustment++,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003935 OrigNumExpansions);
Douglas Gregord3731192011-01-10 07:32:04 +00003936 if (!NewParm)
3937 return true;
3938
3939 OutParamTypes.push_back(NewParm->getType());
3940 if (PVars)
3941 PVars->push_back(NewParm);
3942 }
3943
John McCallfb44de92011-05-01 22:35:37 +00003944 // The next parameter should have the same adjustment as the
3945 // last thing we pushed, but we post-incremented indexAdjustment
3946 // on every push. Also, if we push nothing, the adjustment should
3947 // go down by one.
3948 indexAdjustment--;
3949
Douglas Gregor603cfb42011-01-05 23:12:31 +00003950 // We're done with the pack expansion.
3951 continue;
3952 }
3953
3954 // We'll substitute the parameter now without expanding the pack
3955 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00003956 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3957 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003958 indexAdjustment,
Douglas Gregor406f98f2011-03-02 02:04:06 +00003959 NumExpansions);
3960 } else {
3961 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003962 indexAdjustment,
Douglas Gregor406f98f2011-03-02 02:04:06 +00003963 llvm::Optional<unsigned>());
Douglas Gregor603cfb42011-01-05 23:12:31 +00003964 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00003965
John McCall21ef0fa2010-03-11 09:03:00 +00003966 if (!NewParm)
3967 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003968
Douglas Gregora009b592011-01-07 00:20:55 +00003969 OutParamTypes.push_back(NewParm->getType());
3970 if (PVars)
3971 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003972 continue;
3973 }
John McCall21ef0fa2010-03-11 09:03:00 +00003974
3975 // Deal with the possibility that we don't have a parameter
3976 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00003977 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00003978 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003979 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003980 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003981 if (const PackExpansionType *Expansion
3982 = dyn_cast<PackExpansionType>(OldType)) {
3983 // We have a function parameter pack that may need to be expanded.
3984 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00003985 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003986 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3987
3988 // Determine whether we should expand the parameter packs.
3989 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003990 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00003991 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003992 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003993 ShouldExpand,
3994 RetainExpansion,
3995 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00003996 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003997 }
3998
3999 if (ShouldExpand) {
4000 // Expand the function parameter pack into multiple, separate
4001 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004002 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004003 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4004 QualType NewType = getDerived().TransformType(Pattern);
4005 if (NewType.isNull())
4006 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004007
Douglas Gregora009b592011-01-07 00:20:55 +00004008 OutParamTypes.push_back(NewType);
4009 if (PVars)
4010 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004011 }
4012
4013 // We're done with the pack expansion.
4014 continue;
4015 }
4016
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004017 // If we're supposed to retain a pack expansion, do so by temporarily
4018 // forgetting the partially-substituted parameter pack.
4019 if (RetainExpansion) {
4020 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4021 QualType NewType = getDerived().TransformType(Pattern);
4022 if (NewType.isNull())
4023 return true;
4024
4025 OutParamTypes.push_back(NewType);
4026 if (PVars)
4027 PVars->push_back(0);
4028 }
Douglas Gregord3731192011-01-10 07:32:04 +00004029
Douglas Gregor603cfb42011-01-05 23:12:31 +00004030 // We'll substitute the parameter now without expanding the pack
4031 // expansion.
4032 OldType = Expansion->getPattern();
4033 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004034 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4035 NewType = getDerived().TransformType(OldType);
4036 } else {
4037 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004038 }
4039
Douglas Gregor603cfb42011-01-05 23:12:31 +00004040 if (NewType.isNull())
4041 return true;
4042
4043 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004044 NewType = getSema().Context.getPackExpansionType(NewType,
4045 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004046
Douglas Gregora009b592011-01-07 00:20:55 +00004047 OutParamTypes.push_back(NewType);
4048 if (PVars)
4049 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004050 }
4051
John McCallfb44de92011-05-01 22:35:37 +00004052#ifndef NDEBUG
4053 if (PVars) {
4054 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4055 if (ParmVarDecl *parm = (*PVars)[i])
4056 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004057 }
John McCallfb44de92011-05-01 22:35:37 +00004058#endif
4059
4060 return false;
4061}
John McCall21ef0fa2010-03-11 09:03:00 +00004062
4063template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004064QualType
John McCalla2becad2009-10-21 00:40:46 +00004065TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004066 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004067 // Transform the parameters and return type.
4068 //
4069 // We instantiate in source order, with the return type first followed by
4070 // the parameters, because users tend to expect this (even if they shouldn't
4071 // rely on it!).
4072 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00004073 // When the function has a trailing return type, we instantiate the
4074 // parameters before the return type, since the return type can then refer
4075 // to the parameters themselves (via decltype, sizeof, etc.).
4076 //
Chris Lattner686775d2011-07-20 06:58:45 +00004077 SmallVector<QualType, 4> ParamTypes;
4078 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004079 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004080
Douglas Gregordab60ad2010-10-01 18:44:50 +00004081 QualType ResultType;
4082
4083 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00004084 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4085 TL.getParmArray(),
4086 TL.getNumArgs(),
4087 TL.getTypePtr()->arg_type_begin(),
4088 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004089 return QualType();
4090
4091 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4092 if (ResultType.isNull())
4093 return QualType();
4094 }
4095 else {
4096 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4097 if (ResultType.isNull())
4098 return QualType();
4099
Douglas Gregora009b592011-01-07 00:20:55 +00004100 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4101 TL.getParmArray(),
4102 TL.getNumArgs(),
4103 TL.getTypePtr()->arg_type_begin(),
4104 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004105 return QualType();
4106 }
4107
John McCalla2becad2009-10-21 00:40:46 +00004108 QualType Result = TL.getType();
4109 if (getDerived().AlwaysRebuild() ||
4110 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004111 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004112 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4113 Result = getDerived().RebuildFunctionProtoType(ResultType,
4114 ParamTypes.data(),
4115 ParamTypes.size(),
4116 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004117 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004118 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004119 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004120 if (Result.isNull())
4121 return QualType();
4122 }
Mike Stump1eb44332009-09-09 15:08:12 +00004123
John McCalla2becad2009-10-21 00:40:46 +00004124 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004125 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4126 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004127 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004128 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4129 NewTL.setArg(i, ParamDecls[i]);
4130
4131 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004132}
Mike Stump1eb44332009-09-09 15:08:12 +00004133
Douglas Gregor577f75a2009-08-04 16:50:30 +00004134template<typename Derived>
4135QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004136 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004137 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004138 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004139 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4140 if (ResultType.isNull())
4141 return QualType();
4142
4143 QualType Result = TL.getType();
4144 if (getDerived().AlwaysRebuild() ||
4145 ResultType != T->getResultType())
4146 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4147
4148 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004149 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4150 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004151 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004152
4153 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004154}
Mike Stump1eb44332009-09-09 15:08:12 +00004155
John McCalled976492009-12-04 22:46:56 +00004156template<typename Derived> QualType
4157TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004158 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004159 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004160 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004161 if (!D)
4162 return QualType();
4163
4164 QualType Result = TL.getType();
4165 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4166 Result = getDerived().RebuildUnresolvedUsingType(D);
4167 if (Result.isNull())
4168 return QualType();
4169 }
4170
4171 // We might get an arbitrary type spec type back. We should at
4172 // least always get a type spec type, though.
4173 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4174 NewTL.setNameLoc(TL.getNameLoc());
4175
4176 return Result;
4177}
4178
Douglas Gregor577f75a2009-08-04 16:50:30 +00004179template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004180QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004181 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004182 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004183 TypedefNameDecl *Typedef
4184 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4185 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004186 if (!Typedef)
4187 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004188
John McCalla2becad2009-10-21 00:40:46 +00004189 QualType Result = TL.getType();
4190 if (getDerived().AlwaysRebuild() ||
4191 Typedef != T->getDecl()) {
4192 Result = getDerived().RebuildTypedefType(Typedef);
4193 if (Result.isNull())
4194 return QualType();
4195 }
Mike Stump1eb44332009-09-09 15:08:12 +00004196
John McCalla2becad2009-10-21 00:40:46 +00004197 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4198 NewTL.setNameLoc(TL.getNameLoc());
4199
4200 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004201}
Mike Stump1eb44332009-09-09 15:08:12 +00004202
Douglas Gregor577f75a2009-08-04 16:50:30 +00004203template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004204QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004205 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004206 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004207 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004208
John McCall60d7b3a2010-08-24 06:29:42 +00004209 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004210 if (E.isInvalid())
4211 return QualType();
4212
John McCalla2becad2009-10-21 00:40:46 +00004213 QualType Result = TL.getType();
4214 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004215 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004216 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004217 if (Result.isNull())
4218 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004219 }
John McCalla2becad2009-10-21 00:40:46 +00004220 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004221
John McCalla2becad2009-10-21 00:40:46 +00004222 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004223 NewTL.setTypeofLoc(TL.getTypeofLoc());
4224 NewTL.setLParenLoc(TL.getLParenLoc());
4225 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004226
4227 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004228}
Mike Stump1eb44332009-09-09 15:08:12 +00004229
4230template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004231QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004232 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004233 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4234 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4235 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004236 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004237
John McCalla2becad2009-10-21 00:40:46 +00004238 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004239 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4240 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004241 if (Result.isNull())
4242 return QualType();
4243 }
Mike Stump1eb44332009-09-09 15:08:12 +00004244
John McCalla2becad2009-10-21 00:40:46 +00004245 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004246 NewTL.setTypeofLoc(TL.getTypeofLoc());
4247 NewTL.setLParenLoc(TL.getLParenLoc());
4248 NewTL.setRParenLoc(TL.getRParenLoc());
4249 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004250
4251 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004252}
Mike Stump1eb44332009-09-09 15:08:12 +00004253
4254template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004255QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004256 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004257 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004258
Douglas Gregor670444e2009-08-04 22:27:00 +00004259 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004260 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004261
John McCall60d7b3a2010-08-24 06:29:42 +00004262 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004263 if (E.isInvalid())
4264 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004265
John McCalla2becad2009-10-21 00:40:46 +00004266 QualType Result = TL.getType();
4267 if (getDerived().AlwaysRebuild() ||
4268 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004269 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004270 if (Result.isNull())
4271 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004272 }
John McCalla2becad2009-10-21 00:40:46 +00004273 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004274
John McCalla2becad2009-10-21 00:40:46 +00004275 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4276 NewTL.setNameLoc(TL.getNameLoc());
4277
4278 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004279}
4280
4281template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004282QualType TreeTransform<Derived>::TransformUnaryTransformType(
4283 TypeLocBuilder &TLB,
4284 UnaryTransformTypeLoc TL) {
4285 QualType Result = TL.getType();
4286 if (Result->isDependentType()) {
4287 const UnaryTransformType *T = TL.getTypePtr();
4288 QualType NewBase =
4289 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4290 Result = getDerived().RebuildUnaryTransformType(NewBase,
4291 T->getUTTKind(),
4292 TL.getKWLoc());
4293 if (Result.isNull())
4294 return QualType();
4295 }
4296
4297 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4298 NewTL.setKWLoc(TL.getKWLoc());
4299 NewTL.setParensRange(TL.getParensRange());
4300 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4301 return Result;
4302}
4303
4304template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004305QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4306 AutoTypeLoc TL) {
4307 const AutoType *T = TL.getTypePtr();
4308 QualType OldDeduced = T->getDeducedType();
4309 QualType NewDeduced;
4310 if (!OldDeduced.isNull()) {
4311 NewDeduced = getDerived().TransformType(OldDeduced);
4312 if (NewDeduced.isNull())
4313 return QualType();
4314 }
4315
4316 QualType Result = TL.getType();
4317 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4318 Result = getDerived().RebuildAutoType(NewDeduced);
4319 if (Result.isNull())
4320 return QualType();
4321 }
4322
4323 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4324 NewTL.setNameLoc(TL.getNameLoc());
4325
4326 return Result;
4327}
4328
4329template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004330QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004331 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004332 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004333 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004334 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4335 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004336 if (!Record)
4337 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004338
John McCalla2becad2009-10-21 00:40:46 +00004339 QualType Result = TL.getType();
4340 if (getDerived().AlwaysRebuild() ||
4341 Record != T->getDecl()) {
4342 Result = getDerived().RebuildRecordType(Record);
4343 if (Result.isNull())
4344 return QualType();
4345 }
Mike Stump1eb44332009-09-09 15:08:12 +00004346
John McCalla2becad2009-10-21 00:40:46 +00004347 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4348 NewTL.setNameLoc(TL.getNameLoc());
4349
4350 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004351}
Mike Stump1eb44332009-09-09 15:08:12 +00004352
4353template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004354QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004355 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004356 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004357 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004358 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4359 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004360 if (!Enum)
4361 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004362
John McCalla2becad2009-10-21 00:40:46 +00004363 QualType Result = TL.getType();
4364 if (getDerived().AlwaysRebuild() ||
4365 Enum != T->getDecl()) {
4366 Result = getDerived().RebuildEnumType(Enum);
4367 if (Result.isNull())
4368 return QualType();
4369 }
Mike Stump1eb44332009-09-09 15:08:12 +00004370
John McCalla2becad2009-10-21 00:40:46 +00004371 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4372 NewTL.setNameLoc(TL.getNameLoc());
4373
4374 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004375}
John McCall7da24312009-09-05 00:15:47 +00004376
John McCall3cb0ebd2010-03-10 03:28:59 +00004377template<typename Derived>
4378QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4379 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004380 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004381 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4382 TL.getTypePtr()->getDecl());
4383 if (!D) return QualType();
4384
4385 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4386 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4387 return T;
4388}
4389
Douglas Gregor577f75a2009-08-04 16:50:30 +00004390template<typename Derived>
4391QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004392 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004393 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004394 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004395}
4396
Mike Stump1eb44332009-09-09 15:08:12 +00004397template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004398QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004399 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004400 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004401 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4402
4403 // Substitute into the replacement type, which itself might involve something
4404 // that needs to be transformed. This only tends to occur with default
4405 // template arguments of template template parameters.
4406 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4407 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4408 if (Replacement.isNull())
4409 return QualType();
4410
4411 // Always canonicalize the replacement type.
4412 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4413 QualType Result
4414 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4415 Replacement);
4416
4417 // Propagate type-source information.
4418 SubstTemplateTypeParmTypeLoc NewTL
4419 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4420 NewTL.setNameLoc(TL.getNameLoc());
4421 return Result;
4422
John McCall49a832b2009-10-18 09:09:24 +00004423}
4424
4425template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004426QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4427 TypeLocBuilder &TLB,
4428 SubstTemplateTypeParmPackTypeLoc TL) {
4429 return TransformTypeSpecType(TLB, TL);
4430}
4431
4432template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004433QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004434 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004435 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004436 const TemplateSpecializationType *T = TL.getTypePtr();
4437
Douglas Gregor1d752d72011-03-02 18:46:51 +00004438 // The nested-name-specifier never matters in a TemplateSpecializationType,
4439 // because we can't have a dependent nested-name-specifier anyway.
4440 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004441 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004442 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4443 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004444 if (Template.isNull())
4445 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004446
John McCall43fed0d2010-11-12 08:19:04 +00004447 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4448}
4449
Eli Friedmanb001de72011-10-06 23:00:33 +00004450template<typename Derived>
4451QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4452 AtomicTypeLoc TL) {
4453 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4454 if (ValueType.isNull())
4455 return QualType();
4456
4457 QualType Result = TL.getType();
4458 if (getDerived().AlwaysRebuild() ||
4459 ValueType != TL.getValueLoc().getType()) {
4460 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4461 if (Result.isNull())
4462 return QualType();
4463 }
4464
4465 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4466 NewTL.setKWLoc(TL.getKWLoc());
4467 NewTL.setLParenLoc(TL.getLParenLoc());
4468 NewTL.setRParenLoc(TL.getRParenLoc());
4469
4470 return Result;
4471}
4472
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004473namespace {
4474 /// \brief Simple iterator that traverses the template arguments in a
4475 /// container that provides a \c getArgLoc() member function.
4476 ///
4477 /// This iterator is intended to be used with the iterator form of
4478 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4479 template<typename ArgLocContainer>
4480 class TemplateArgumentLocContainerIterator {
4481 ArgLocContainer *Container;
4482 unsigned Index;
4483
4484 public:
4485 typedef TemplateArgumentLoc value_type;
4486 typedef TemplateArgumentLoc reference;
4487 typedef int difference_type;
4488 typedef std::input_iterator_tag iterator_category;
4489
4490 class pointer {
4491 TemplateArgumentLoc Arg;
4492
4493 public:
4494 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4495
4496 const TemplateArgumentLoc *operator->() const {
4497 return &Arg;
4498 }
4499 };
4500
4501
4502 TemplateArgumentLocContainerIterator() {}
4503
4504 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4505 unsigned Index)
4506 : Container(&Container), Index(Index) { }
4507
4508 TemplateArgumentLocContainerIterator &operator++() {
4509 ++Index;
4510 return *this;
4511 }
4512
4513 TemplateArgumentLocContainerIterator operator++(int) {
4514 TemplateArgumentLocContainerIterator Old(*this);
4515 ++(*this);
4516 return Old;
4517 }
4518
4519 TemplateArgumentLoc operator*() const {
4520 return Container->getArgLoc(Index);
4521 }
4522
4523 pointer operator->() const {
4524 return pointer(Container->getArgLoc(Index));
4525 }
4526
4527 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004528 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004529 return X.Container == Y.Container && X.Index == Y.Index;
4530 }
4531
4532 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004533 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004534 return !(X == Y);
4535 }
4536 };
4537}
4538
4539
John McCall43fed0d2010-11-12 08:19:04 +00004540template <typename Derived>
4541QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4542 TypeLocBuilder &TLB,
4543 TemplateSpecializationTypeLoc TL,
4544 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004545 TemplateArgumentListInfo NewTemplateArgs;
4546 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4547 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004548 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4549 ArgIterator;
4550 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4551 ArgIterator(TL, TL.getNumArgs()),
4552 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004553 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004554
John McCall833ca992009-10-29 08:12:44 +00004555 // FIXME: maybe don't rebuild if all the template arguments are the same.
4556
4557 QualType Result =
4558 getDerived().RebuildTemplateSpecializationType(Template,
4559 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004560 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004561
4562 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004563 // Specializations of template template parameters are represented as
4564 // TemplateSpecializationTypes, and substitution of type alias templates
4565 // within a dependent context can transform them into
4566 // DependentTemplateSpecializationTypes.
4567 if (isa<DependentTemplateSpecializationType>(Result)) {
4568 DependentTemplateSpecializationTypeLoc NewTL
4569 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4570 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4571 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4572 NewTL.setNameLoc(TL.getTemplateNameLoc());
4573 NewTL.setLAngleLoc(TL.getLAngleLoc());
4574 NewTL.setRAngleLoc(TL.getRAngleLoc());
4575 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4576 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4577 return Result;
4578 }
4579
John McCall833ca992009-10-29 08:12:44 +00004580 TemplateSpecializationTypeLoc NewTL
4581 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4582 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4583 NewTL.setLAngleLoc(TL.getLAngleLoc());
4584 NewTL.setRAngleLoc(TL.getRAngleLoc());
4585 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4586 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004587 }
Mike Stump1eb44332009-09-09 15:08:12 +00004588
John McCall833ca992009-10-29 08:12:44 +00004589 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004590}
Mike Stump1eb44332009-09-09 15:08:12 +00004591
Douglas Gregora88f09f2011-02-28 17:23:35 +00004592template <typename Derived>
4593QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4594 TypeLocBuilder &TLB,
4595 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004596 TemplateName Template,
4597 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004598 TemplateArgumentListInfo NewTemplateArgs;
4599 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4600 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4601 typedef TemplateArgumentLocContainerIterator<
4602 DependentTemplateSpecializationTypeLoc> ArgIterator;
4603 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4604 ArgIterator(TL, TL.getNumArgs()),
4605 NewTemplateArgs))
4606 return QualType();
4607
4608 // FIXME: maybe don't rebuild if all the template arguments are the same.
4609
4610 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4611 QualType Result
4612 = getSema().Context.getDependentTemplateSpecializationType(
4613 TL.getTypePtr()->getKeyword(),
4614 DTN->getQualifier(),
4615 DTN->getIdentifier(),
4616 NewTemplateArgs);
4617
4618 DependentTemplateSpecializationTypeLoc NewTL
4619 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4620 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004621
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004622 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregora88f09f2011-02-28 17:23:35 +00004623 NewTL.setNameLoc(TL.getNameLoc());
4624 NewTL.setLAngleLoc(TL.getLAngleLoc());
4625 NewTL.setRAngleLoc(TL.getRAngleLoc());
4626 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4627 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4628 return Result;
4629 }
4630
4631 QualType Result
4632 = getDerived().RebuildTemplateSpecializationType(Template,
4633 TL.getNameLoc(),
4634 NewTemplateArgs);
4635
4636 if (!Result.isNull()) {
4637 /// FIXME: Wrap this in an elaborated-type-specifier?
4638 TemplateSpecializationTypeLoc NewTL
4639 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4640 NewTL.setTemplateNameLoc(TL.getNameLoc());
4641 NewTL.setLAngleLoc(TL.getLAngleLoc());
4642 NewTL.setRAngleLoc(TL.getRAngleLoc());
4643 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4644 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4645 }
4646
4647 return Result;
4648}
4649
Mike Stump1eb44332009-09-09 15:08:12 +00004650template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004651QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004652TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004653 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004654 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004655
Douglas Gregor9e876872011-03-01 18:12:44 +00004656 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004657 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004658 if (TL.getQualifierLoc()) {
4659 QualifierLoc
4660 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4661 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004662 return QualType();
4663 }
Mike Stump1eb44332009-09-09 15:08:12 +00004664
John McCall43fed0d2010-11-12 08:19:04 +00004665 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4666 if (NamedT.isNull())
4667 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004668
Richard Smith3e4c6c42011-05-05 21:57:07 +00004669 // C++0x [dcl.type.elab]p2:
4670 // If the identifier resolves to a typedef-name or the simple-template-id
4671 // resolves to an alias template specialization, the
4672 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004673 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4674 if (const TemplateSpecializationType *TST =
4675 NamedT->getAs<TemplateSpecializationType>()) {
4676 TemplateName Template = TST->getTemplateName();
4677 if (TypeAliasTemplateDecl *TAT =
4678 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4679 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4680 diag::err_tag_reference_non_tag) << 4;
4681 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4682 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004683 }
4684 }
4685
John McCalla2becad2009-10-21 00:40:46 +00004686 QualType Result = TL.getType();
4687 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004688 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004689 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00004690 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004691 T->getKeyword(),
4692 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004693 if (Result.isNull())
4694 return QualType();
4695 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004696
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004697 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004698 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004699 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004700 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004701}
Mike Stump1eb44332009-09-09 15:08:12 +00004702
4703template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004704QualType TreeTransform<Derived>::TransformAttributedType(
4705 TypeLocBuilder &TLB,
4706 AttributedTypeLoc TL) {
4707 const AttributedType *oldType = TL.getTypePtr();
4708 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4709 if (modifiedType.isNull())
4710 return QualType();
4711
4712 QualType result = TL.getType();
4713
4714 // FIXME: dependent operand expressions?
4715 if (getDerived().AlwaysRebuild() ||
4716 modifiedType != oldType->getModifiedType()) {
4717 // TODO: this is really lame; we should really be rebuilding the
4718 // equivalent type from first principles.
4719 QualType equivalentType
4720 = getDerived().TransformType(oldType->getEquivalentType());
4721 if (equivalentType.isNull())
4722 return QualType();
4723 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4724 modifiedType,
4725 equivalentType);
4726 }
4727
4728 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4729 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4730 if (TL.hasAttrOperand())
4731 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4732 if (TL.hasAttrExprOperand())
4733 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4734 else if (TL.hasAttrEnumOperand())
4735 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4736
4737 return result;
4738}
4739
4740template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004741QualType
4742TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4743 ParenTypeLoc TL) {
4744 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4745 if (Inner.isNull())
4746 return QualType();
4747
4748 QualType Result = TL.getType();
4749 if (getDerived().AlwaysRebuild() ||
4750 Inner != TL.getInnerLoc().getType()) {
4751 Result = getDerived().RebuildParenType(Inner);
4752 if (Result.isNull())
4753 return QualType();
4754 }
4755
4756 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4757 NewTL.setLParenLoc(TL.getLParenLoc());
4758 NewTL.setRParenLoc(TL.getRParenLoc());
4759 return Result;
4760}
4761
4762template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004763QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004764 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004765 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004766
Douglas Gregor2494dd02011-03-01 01:34:45 +00004767 NestedNameSpecifierLoc QualifierLoc
4768 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4769 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004770 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004771
John McCall33500952010-06-11 00:33:02 +00004772 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004773 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCall33500952010-06-11 00:33:02 +00004774 TL.getKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004775 QualifierLoc,
4776 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004777 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004778 if (Result.isNull())
4779 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004780
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004781 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4782 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004783 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4784
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004785 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4786 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004787 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004788 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004789 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4790 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004791 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004792 NewTL.setNameLoc(TL.getNameLoc());
4793 }
John McCalla2becad2009-10-21 00:40:46 +00004794 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004795}
Mike Stump1eb44332009-09-09 15:08:12 +00004796
Douglas Gregor577f75a2009-08-04 16:50:30 +00004797template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004798QualType TreeTransform<Derived>::
4799 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004800 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004801 NestedNameSpecifierLoc QualifierLoc;
4802 if (TL.getQualifierLoc()) {
4803 QualifierLoc
4804 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4805 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004806 return QualType();
4807 }
4808
John McCall43fed0d2010-11-12 08:19:04 +00004809 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004810 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004811}
4812
4813template<typename Derived>
4814QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004815TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4816 DependentTemplateSpecializationTypeLoc TL,
4817 NestedNameSpecifierLoc QualifierLoc) {
4818 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4819
4820 TemplateArgumentListInfo NewTemplateArgs;
4821 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4822 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4823
4824 typedef TemplateArgumentLocContainerIterator<
4825 DependentTemplateSpecializationTypeLoc> ArgIterator;
4826 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4827 ArgIterator(TL, TL.getNumArgs()),
4828 NewTemplateArgs))
4829 return QualType();
4830
4831 QualType Result
4832 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4833 QualifierLoc,
4834 T->getIdentifier(),
4835 TL.getNameLoc(),
4836 NewTemplateArgs);
4837 if (Result.isNull())
4838 return QualType();
4839
4840 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4841 QualType NamedT = ElabT->getNamedType();
4842
4843 // Copy information relevant to the template specialization.
4844 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004845 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004846 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004847 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4848 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004849 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004850 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004851
4852 // Copy information relevant to the elaborated type.
4853 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4854 NewTL.setKeywordLoc(TL.getKeywordLoc());
4855 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004856 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4857 DependentTemplateSpecializationTypeLoc SpecTL
4858 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor944cdae2011-03-07 15:13:34 +00004859 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004860 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004861 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004862 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4863 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004864 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004865 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004866 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004867 TemplateSpecializationTypeLoc SpecTL
4868 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004869 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004870 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4871 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004872 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004873 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004874 }
4875 return Result;
4876}
4877
4878template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004879QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4880 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004881 QualType Pattern
4882 = getDerived().TransformType(TLB, TL.getPatternLoc());
4883 if (Pattern.isNull())
4884 return QualType();
4885
4886 QualType Result = TL.getType();
4887 if (getDerived().AlwaysRebuild() ||
4888 Pattern != TL.getPatternLoc().getType()) {
4889 Result = getDerived().RebuildPackExpansionType(Pattern,
4890 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004891 TL.getEllipsisLoc(),
4892 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004893 if (Result.isNull())
4894 return QualType();
4895 }
4896
4897 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4898 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4899 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004900}
4901
4902template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004903QualType
4904TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004905 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004906 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004907 TLB.pushFullCopy(TL);
4908 return TL.getType();
4909}
4910
4911template<typename Derived>
4912QualType
4913TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004914 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004915 // ObjCObjectType is never dependent.
4916 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004917 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004918}
Mike Stump1eb44332009-09-09 15:08:12 +00004919
4920template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004921QualType
4922TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004923 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004924 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004925 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004926 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004927}
4928
Douglas Gregor577f75a2009-08-04 16:50:30 +00004929//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004930// Statement transformation
4931//===----------------------------------------------------------------------===//
4932template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004933StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004934TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004935 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004936}
4937
4938template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004939StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004940TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4941 return getDerived().TransformCompoundStmt(S, false);
4942}
4943
4944template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004945StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004946TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004947 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004948 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004949 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004950 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004951 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4952 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004953 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004954 if (Result.isInvalid()) {
4955 // Immediately fail if this was a DeclStmt, since it's very
4956 // likely that this will cause problems for future statements.
4957 if (isa<DeclStmt>(*B))
4958 return StmtError();
4959
4960 // Otherwise, just keep processing substatements and fail later.
4961 SubStmtInvalid = true;
4962 continue;
4963 }
Mike Stump1eb44332009-09-09 15:08:12 +00004964
Douglas Gregor43959a92009-08-20 07:17:43 +00004965 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4966 Statements.push_back(Result.takeAs<Stmt>());
4967 }
Mike Stump1eb44332009-09-09 15:08:12 +00004968
John McCall7114cba2010-08-27 19:56:05 +00004969 if (SubStmtInvalid)
4970 return StmtError();
4971
Douglas Gregor43959a92009-08-20 07:17:43 +00004972 if (!getDerived().AlwaysRebuild() &&
4973 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004974 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004975
4976 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4977 move_arg(Statements),
4978 S->getRBracLoc(),
4979 IsStmtExpr);
4980}
Mike Stump1eb44332009-09-09 15:08:12 +00004981
Douglas Gregor43959a92009-08-20 07:17:43 +00004982template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004983StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004984TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004985 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00004986 {
4987 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00004988 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004989
Eli Friedman264c1f82009-11-19 03:14:00 +00004990 // Transform the left-hand case value.
4991 LHS = getDerived().TransformExpr(S->getLHS());
4992 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004993 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004994
Eli Friedman264c1f82009-11-19 03:14:00 +00004995 // Transform the right-hand case value (for the GNU case-range extension).
4996 RHS = getDerived().TransformExpr(S->getRHS());
4997 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004998 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00004999 }
Mike Stump1eb44332009-09-09 15:08:12 +00005000
Douglas Gregor43959a92009-08-20 07:17:43 +00005001 // Build the case statement.
5002 // Case statements are always rebuilt so that they will attached to their
5003 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005004 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005005 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005006 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005007 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005008 S->getColonLoc());
5009 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005010 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005011
Douglas Gregor43959a92009-08-20 07:17:43 +00005012 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005013 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005014 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005015 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005016
Douglas Gregor43959a92009-08-20 07:17:43 +00005017 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005018 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005019}
5020
5021template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005022StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005023TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005024 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005025 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005026 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005027 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005028
Douglas Gregor43959a92009-08-20 07:17:43 +00005029 // Default statements are always rebuilt
5030 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005031 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005032}
Mike Stump1eb44332009-09-09 15:08:12 +00005033
Douglas Gregor43959a92009-08-20 07:17:43 +00005034template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005035StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005036TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005037 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005038 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005039 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005040
Chris Lattner57ad3782011-02-17 20:34:02 +00005041 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5042 S->getDecl());
5043 if (!LD)
5044 return StmtError();
5045
5046
Douglas Gregor43959a92009-08-20 07:17:43 +00005047 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005048 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005049 cast<LabelDecl>(LD), SourceLocation(),
5050 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005051}
Mike Stump1eb44332009-09-09 15:08:12 +00005052
Douglas Gregor43959a92009-08-20 07:17:43 +00005053template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005054StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005055TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005056 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005057 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005058 VarDecl *ConditionVar = 0;
5059 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005060 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005061 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005062 getDerived().TransformDefinition(
5063 S->getConditionVariable()->getLocation(),
5064 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005065 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005066 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005067 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005068 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005069
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005070 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005071 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005072
5073 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005074 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005075 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5076 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005077 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005078 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005079
John McCall9ae2f072010-08-23 23:25:46 +00005080 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005081 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005082 }
Sean Huntc3021132010-05-05 15:23:54 +00005083
John McCall9ae2f072010-08-23 23:25:46 +00005084 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5085 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005086 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005087
Douglas Gregor43959a92009-08-20 07:17:43 +00005088 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005089 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005090 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005091 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005092
Douglas Gregor43959a92009-08-20 07:17:43 +00005093 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005094 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005095 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005096 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005097
Douglas Gregor43959a92009-08-20 07:17:43 +00005098 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005099 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005100 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005101 Then.get() == S->getThen() &&
5102 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005103 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005104
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005105 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005106 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005107 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005108}
5109
5110template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005111StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005112TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005113 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005114 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005115 VarDecl *ConditionVar = 0;
5116 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005117 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005118 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005119 getDerived().TransformDefinition(
5120 S->getConditionVariable()->getLocation(),
5121 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005122 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005123 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005124 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005125 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005126
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005127 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005128 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005129 }
Mike Stump1eb44332009-09-09 15:08:12 +00005130
Douglas Gregor43959a92009-08-20 07:17:43 +00005131 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005132 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005133 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005134 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005135 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005136 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005137
Douglas Gregor43959a92009-08-20 07:17:43 +00005138 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005139 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005140 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005141 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005142
Douglas Gregor43959a92009-08-20 07:17:43 +00005143 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005144 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5145 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005146}
Mike Stump1eb44332009-09-09 15:08:12 +00005147
Douglas Gregor43959a92009-08-20 07:17:43 +00005148template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005149StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005150TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005151 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005152 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005153 VarDecl *ConditionVar = 0;
5154 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005155 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005156 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005157 getDerived().TransformDefinition(
5158 S->getConditionVariable()->getLocation(),
5159 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005160 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005161 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005162 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005163 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005164
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005165 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005166 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005167
5168 if (S->getCond()) {
5169 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005170 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5171 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005172 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005173 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005174 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005175 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005176 }
Mike Stump1eb44332009-09-09 15:08:12 +00005177
John McCall9ae2f072010-08-23 23:25:46 +00005178 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5179 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005180 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005181
Douglas Gregor43959a92009-08-20 07:17:43 +00005182 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005183 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005184 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005185 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005186
Douglas Gregor43959a92009-08-20 07:17:43 +00005187 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005188 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005189 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005190 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005191 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005192
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005193 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005194 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005195}
Mike Stump1eb44332009-09-09 15:08:12 +00005196
Douglas Gregor43959a92009-08-20 07:17:43 +00005197template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005198StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005199TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005200 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005201 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005202 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005203 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005204
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005205 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005206 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005207 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005208 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005209
Douglas Gregor43959a92009-08-20 07:17:43 +00005210 if (!getDerived().AlwaysRebuild() &&
5211 Cond.get() == S->getCond() &&
5212 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005213 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005214
John McCall9ae2f072010-08-23 23:25:46 +00005215 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5216 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005217 S->getRParenLoc());
5218}
Mike Stump1eb44332009-09-09 15:08:12 +00005219
Douglas Gregor43959a92009-08-20 07:17:43 +00005220template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005221StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005222TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005223 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005224 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005225 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005226 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005227
Douglas Gregor43959a92009-08-20 07:17:43 +00005228 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005229 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005230 VarDecl *ConditionVar = 0;
5231 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005232 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005233 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005234 getDerived().TransformDefinition(
5235 S->getConditionVariable()->getLocation(),
5236 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005237 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005238 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005239 } else {
5240 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005241
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005242 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005243 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005244
5245 if (S->getCond()) {
5246 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005247 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5248 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005249 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005250 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005251
John McCall9ae2f072010-08-23 23:25:46 +00005252 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005253 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005254 }
Mike Stump1eb44332009-09-09 15:08:12 +00005255
John McCall9ae2f072010-08-23 23:25:46 +00005256 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5257 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005258 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005259
Douglas Gregor43959a92009-08-20 07:17:43 +00005260 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005261 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005262 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005263 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005264
John McCall9ae2f072010-08-23 23:25:46 +00005265 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5266 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005267 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005268
Douglas Gregor43959a92009-08-20 07:17:43 +00005269 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005270 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005271 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005272 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005273
Douglas Gregor43959a92009-08-20 07:17:43 +00005274 if (!getDerived().AlwaysRebuild() &&
5275 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005276 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005277 Inc.get() == S->getInc() &&
5278 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005279 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005280
Douglas Gregor43959a92009-08-20 07:17:43 +00005281 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005282 Init.get(), FullCond, ConditionVar,
5283 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005284}
5285
5286template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005287StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005288TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005289 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5290 S->getLabel());
5291 if (!LD)
5292 return StmtError();
5293
Douglas Gregor43959a92009-08-20 07:17:43 +00005294 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005295 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005296 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005297}
5298
5299template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005300StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005301TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005302 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005303 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005304 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005305
Douglas Gregor43959a92009-08-20 07:17:43 +00005306 if (!getDerived().AlwaysRebuild() &&
5307 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005308 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005309
5310 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005311 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005312}
5313
5314template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005315StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005316TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005317 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005318}
Mike Stump1eb44332009-09-09 15:08:12 +00005319
Douglas Gregor43959a92009-08-20 07:17:43 +00005320template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005321StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005322TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005323 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005324}
Mike Stump1eb44332009-09-09 15:08:12 +00005325
Douglas Gregor43959a92009-08-20 07:17:43 +00005326template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005327StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005328TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005329 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005330 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005331 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005332
Mike Stump1eb44332009-09-09 15:08:12 +00005333 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005334 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005335 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005336}
Mike Stump1eb44332009-09-09 15:08:12 +00005337
Douglas Gregor43959a92009-08-20 07:17:43 +00005338template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005339StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005340TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005341 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005342 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005343 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5344 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005345 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5346 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005347 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005348 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005349
Douglas Gregor43959a92009-08-20 07:17:43 +00005350 if (Transformed != *D)
5351 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005352
Douglas Gregor43959a92009-08-20 07:17:43 +00005353 Decls.push_back(Transformed);
5354 }
Mike Stump1eb44332009-09-09 15:08:12 +00005355
Douglas Gregor43959a92009-08-20 07:17:43 +00005356 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005357 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005358
5359 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005360 S->getStartLoc(), S->getEndLoc());
5361}
Mike Stump1eb44332009-09-09 15:08:12 +00005362
Douglas Gregor43959a92009-08-20 07:17:43 +00005363template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005364StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005365TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005366
John McCallca0408f2010-08-23 06:44:23 +00005367 ASTOwningVector<Expr*> Constraints(getSema());
5368 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005369 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005370
John McCall60d7b3a2010-08-24 06:29:42 +00005371 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005372 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005373
5374 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005375
Anders Carlsson703e3942010-01-24 05:50:09 +00005376 // Go through the outputs.
5377 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005378 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005379
Anders Carlsson703e3942010-01-24 05:50:09 +00005380 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005381 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005382
Anders Carlsson703e3942010-01-24 05:50:09 +00005383 // Transform the output expr.
5384 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005385 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005386 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005387 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005388
Anders Carlsson703e3942010-01-24 05:50:09 +00005389 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005390
John McCall9ae2f072010-08-23 23:25:46 +00005391 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005392 }
Sean Huntc3021132010-05-05 15:23:54 +00005393
Anders Carlsson703e3942010-01-24 05:50:09 +00005394 // Go through the inputs.
5395 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005396 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005397
Anders Carlsson703e3942010-01-24 05:50:09 +00005398 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005399 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005400
Anders Carlsson703e3942010-01-24 05:50:09 +00005401 // Transform the input expr.
5402 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005403 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005404 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005405 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005406
Anders Carlsson703e3942010-01-24 05:50:09 +00005407 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005408
John McCall9ae2f072010-08-23 23:25:46 +00005409 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005410 }
Sean Huntc3021132010-05-05 15:23:54 +00005411
Anders Carlsson703e3942010-01-24 05:50:09 +00005412 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005413 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005414
5415 // Go through the clobbers.
5416 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005417 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005418
5419 // No need to transform the asm string literal.
5420 AsmString = SemaRef.Owned(S->getAsmString());
5421
5422 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5423 S->isSimple(),
5424 S->isVolatile(),
5425 S->getNumOutputs(),
5426 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005427 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005428 move_arg(Constraints),
5429 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005430 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005431 move_arg(Clobbers),
5432 S->getRParenLoc(),
5433 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005434}
5435
5436
5437template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005438StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005439TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005440 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005441 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005442 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005443 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005444
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005445 // Transform the @catch statements (if present).
5446 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005447 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005448 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005449 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005450 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005451 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005452 if (Catch.get() != S->getCatchStmt(I))
5453 AnyCatchChanged = true;
5454 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005455 }
Sean Huntc3021132010-05-05 15:23:54 +00005456
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005457 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005458 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005459 if (S->getFinallyStmt()) {
5460 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5461 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005462 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005463 }
5464
5465 // If nothing changed, just retain this statement.
5466 if (!getDerived().AlwaysRebuild() &&
5467 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005468 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005469 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005470 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005471
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005472 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005473 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5474 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005475}
Mike Stump1eb44332009-09-09 15:08:12 +00005476
Douglas Gregor43959a92009-08-20 07:17:43 +00005477template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005478StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005479TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005480 // Transform the @catch parameter, if there is one.
5481 VarDecl *Var = 0;
5482 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5483 TypeSourceInfo *TSInfo = 0;
5484 if (FromVar->getTypeSourceInfo()) {
5485 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5486 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005487 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005488 }
Sean Huntc3021132010-05-05 15:23:54 +00005489
Douglas Gregorbe270a02010-04-26 17:57:08 +00005490 QualType T;
5491 if (TSInfo)
5492 T = TSInfo->getType();
5493 else {
5494 T = getDerived().TransformType(FromVar->getType());
5495 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005496 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005497 }
Sean Huntc3021132010-05-05 15:23:54 +00005498
Douglas Gregorbe270a02010-04-26 17:57:08 +00005499 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5500 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005501 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005502 }
Sean Huntc3021132010-05-05 15:23:54 +00005503
John McCall60d7b3a2010-08-24 06:29:42 +00005504 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005505 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005506 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005507
5508 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005509 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005510 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005511}
Mike Stump1eb44332009-09-09 15:08:12 +00005512
Douglas Gregor43959a92009-08-20 07:17:43 +00005513template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005514StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005515TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005516 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005517 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005518 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005519 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005520
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005521 // If nothing changed, just retain this statement.
5522 if (!getDerived().AlwaysRebuild() &&
5523 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005524 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005525
5526 // Build a new statement.
5527 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005528 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005529}
Mike Stump1eb44332009-09-09 15:08:12 +00005530
Douglas Gregor43959a92009-08-20 07:17:43 +00005531template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005532StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005533TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005534 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005535 if (S->getThrowExpr()) {
5536 Operand = getDerived().TransformExpr(S->getThrowExpr());
5537 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005538 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005539 }
Sean Huntc3021132010-05-05 15:23:54 +00005540
Douglas Gregord1377b22010-04-22 21:44:01 +00005541 if (!getDerived().AlwaysRebuild() &&
5542 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005543 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005544
John McCall9ae2f072010-08-23 23:25:46 +00005545 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005546}
Mike Stump1eb44332009-09-09 15:08:12 +00005547
Douglas Gregor43959a92009-08-20 07:17:43 +00005548template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005549StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005550TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005551 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005552 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005553 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005554 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005555 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005556 Object =
5557 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5558 Object.get());
5559 if (Object.isInvalid())
5560 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005561
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005562 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005563 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005564 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005565 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005566
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005567 // If nothing change, just retain the current statement.
5568 if (!getDerived().AlwaysRebuild() &&
5569 Object.get() == S->getSynchExpr() &&
5570 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005571 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005572
5573 // Build a new statement.
5574 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005575 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005576}
5577
5578template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005579StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005580TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5581 ObjCAutoreleasePoolStmt *S) {
5582 // Transform the body.
5583 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5584 if (Body.isInvalid())
5585 return StmtError();
5586
5587 // If nothing changed, just retain this statement.
5588 if (!getDerived().AlwaysRebuild() &&
5589 Body.get() == S->getSubStmt())
5590 return SemaRef.Owned(S);
5591
5592 // Build a new statement.
5593 return getDerived().RebuildObjCAutoreleasePoolStmt(
5594 S->getAtLoc(), Body.get());
5595}
5596
5597template<typename Derived>
5598StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005599TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005600 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005601 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005602 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005603 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005604 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005605
Douglas Gregorc3203e72010-04-22 23:10:45 +00005606 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005607 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005608 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005609 return StmtError();
John McCall990567c2011-07-27 01:07:15 +00005610 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5611 Collection.take());
5612 if (Collection.isInvalid())
5613 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005614
Douglas Gregorc3203e72010-04-22 23:10:45 +00005615 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005616 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005617 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005618 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005619
Douglas Gregorc3203e72010-04-22 23:10:45 +00005620 // If nothing changed, just retain this statement.
5621 if (!getDerived().AlwaysRebuild() &&
5622 Element.get() == S->getElement() &&
5623 Collection.get() == S->getCollection() &&
5624 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005625 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005626
Douglas Gregorc3203e72010-04-22 23:10:45 +00005627 // Build a new statement.
5628 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5629 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005630 Element.get(),
5631 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005632 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005633 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005634}
5635
5636
5637template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005638StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005639TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5640 // Transform the exception declaration, if any.
5641 VarDecl *Var = 0;
5642 if (S->getExceptionDecl()) {
5643 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005644 TypeSourceInfo *T = getDerived().TransformType(
5645 ExceptionDecl->getTypeSourceInfo());
5646 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005647 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005648
Douglas Gregor83cb9422010-09-09 17:09:21 +00005649 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005650 ExceptionDecl->getInnerLocStart(),
5651 ExceptionDecl->getLocation(),
5652 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005653 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005654 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005655 }
Mike Stump1eb44332009-09-09 15:08:12 +00005656
Douglas Gregor43959a92009-08-20 07:17:43 +00005657 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005658 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005659 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005660 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005661
Douglas Gregor43959a92009-08-20 07:17:43 +00005662 if (!getDerived().AlwaysRebuild() &&
5663 !Var &&
5664 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005665 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005666
5667 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5668 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005669 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005670}
Mike Stump1eb44332009-09-09 15:08:12 +00005671
Douglas Gregor43959a92009-08-20 07:17:43 +00005672template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005673StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005674TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5675 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005676 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005677 = getDerived().TransformCompoundStmt(S->getTryBlock());
5678 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005679 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005680
Douglas Gregor43959a92009-08-20 07:17:43 +00005681 // Transform the handlers.
5682 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005683 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005684 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005685 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005686 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5687 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005688 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005689
Douglas Gregor43959a92009-08-20 07:17:43 +00005690 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5691 Handlers.push_back(Handler.takeAs<Stmt>());
5692 }
Mike Stump1eb44332009-09-09 15:08:12 +00005693
Douglas Gregor43959a92009-08-20 07:17:43 +00005694 if (!getDerived().AlwaysRebuild() &&
5695 TryBlock.get() == S->getTryBlock() &&
5696 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005697 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005698
John McCall9ae2f072010-08-23 23:25:46 +00005699 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005700 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005701}
Mike Stump1eb44332009-09-09 15:08:12 +00005702
Richard Smithad762fc2011-04-14 22:09:26 +00005703template<typename Derived>
5704StmtResult
5705TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5706 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5707 if (Range.isInvalid())
5708 return StmtError();
5709
5710 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5711 if (BeginEnd.isInvalid())
5712 return StmtError();
5713
5714 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5715 if (Cond.isInvalid())
5716 return StmtError();
5717
5718 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5719 if (Inc.isInvalid())
5720 return StmtError();
5721
5722 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5723 if (LoopVar.isInvalid())
5724 return StmtError();
5725
5726 StmtResult NewStmt = S;
5727 if (getDerived().AlwaysRebuild() ||
5728 Range.get() != S->getRangeStmt() ||
5729 BeginEnd.get() != S->getBeginEndStmt() ||
5730 Cond.get() != S->getCond() ||
5731 Inc.get() != S->getInc() ||
5732 LoopVar.get() != S->getLoopVarStmt())
5733 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5734 S->getColonLoc(), Range.get(),
5735 BeginEnd.get(), Cond.get(),
5736 Inc.get(), LoopVar.get(),
5737 S->getRParenLoc());
5738
5739 StmtResult Body = getDerived().TransformStmt(S->getBody());
5740 if (Body.isInvalid())
5741 return StmtError();
5742
5743 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5744 // it now so we have a new statement to attach the body to.
5745 if (Body.get() != S->getBody() && NewStmt.get() == S)
5746 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5747 S->getColonLoc(), Range.get(),
5748 BeginEnd.get(), Cond.get(),
5749 Inc.get(), LoopVar.get(),
5750 S->getRParenLoc());
5751
5752 if (NewStmt.get() == S)
5753 return SemaRef.Owned(S);
5754
5755 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5756}
5757
John Wiegley28bbe4b2011-04-28 01:08:34 +00005758template<typename Derived>
5759StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005760TreeTransform<Derived>::TransformMSDependentExistsStmt(
5761 MSDependentExistsStmt *S) {
5762 // Transform the nested-name-specifier, if any.
5763 NestedNameSpecifierLoc QualifierLoc;
5764 if (S->getQualifierLoc()) {
5765 QualifierLoc
5766 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5767 if (!QualifierLoc)
5768 return StmtError();
5769 }
5770
5771 // Transform the declaration name.
5772 DeclarationNameInfo NameInfo = S->getNameInfo();
5773 if (NameInfo.getName()) {
5774 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5775 if (!NameInfo.getName())
5776 return StmtError();
5777 }
5778
5779 // Check whether anything changed.
5780 if (!getDerived().AlwaysRebuild() &&
5781 QualifierLoc == S->getQualifierLoc() &&
5782 NameInfo.getName() == S->getNameInfo().getName())
5783 return S;
5784
5785 // Determine whether this name exists, if we can.
5786 CXXScopeSpec SS;
5787 SS.Adopt(QualifierLoc);
5788 bool Dependent = false;
5789 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5790 case Sema::IER_Exists:
5791 if (S->isIfExists())
5792 break;
5793
5794 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5795
5796 case Sema::IER_DoesNotExist:
5797 if (S->isIfNotExists())
5798 break;
5799
5800 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5801
5802 case Sema::IER_Dependent:
5803 Dependent = true;
5804 break;
Douglas Gregor65019ac2011-10-25 03:44:56 +00005805
5806 case Sema::IER_Error:
5807 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005808 }
5809
5810 // We need to continue with the instantiation, so do so now.
5811 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5812 if (SubStmt.isInvalid())
5813 return StmtError();
5814
5815 // If we have resolved the name, just transform to the substatement.
5816 if (!Dependent)
5817 return SubStmt;
5818
5819 // The name is still dependent, so build a dependent expression again.
5820 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5821 S->isIfExists(),
5822 QualifierLoc,
5823 NameInfo,
5824 SubStmt.get());
5825}
5826
5827template<typename Derived>
5828StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00005829TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5830 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5831 if(TryBlock.isInvalid()) return StmtError();
5832
5833 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5834 if(!getDerived().AlwaysRebuild() &&
5835 TryBlock.get() == S->getTryBlock() &&
5836 Handler.get() == S->getHandler())
5837 return SemaRef.Owned(S);
5838
5839 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5840 S->getTryLoc(),
5841 TryBlock.take(),
5842 Handler.take());
5843}
5844
5845template<typename Derived>
5846StmtResult
5847TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5848 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5849 if(Block.isInvalid()) return StmtError();
5850
5851 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5852 Block.take());
5853}
5854
5855template<typename Derived>
5856StmtResult
5857TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5858 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5859 if(FilterExpr.isInvalid()) return StmtError();
5860
5861 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5862 if(Block.isInvalid()) return StmtError();
5863
5864 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5865 FilterExpr.take(),
5866 Block.take());
5867}
5868
5869template<typename Derived>
5870StmtResult
5871TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5872 if(isa<SEHFinallyStmt>(Handler))
5873 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5874 else
5875 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5876}
5877
Douglas Gregor43959a92009-08-20 07:17:43 +00005878//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005879// Expression transformation
5880//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005881template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005882ExprResult
John McCall454feb92009-12-08 09:21:05 +00005883TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005884 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005885}
Mike Stump1eb44332009-09-09 15:08:12 +00005886
5887template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005888ExprResult
John McCall454feb92009-12-08 09:21:05 +00005889TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005890 NestedNameSpecifierLoc QualifierLoc;
5891 if (E->getQualifierLoc()) {
5892 QualifierLoc
5893 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5894 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005895 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005896 }
John McCalldbd872f2009-12-08 09:08:17 +00005897
5898 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005899 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5900 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005901 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005902 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005903
John McCallec8045d2010-08-17 21:27:17 +00005904 DeclarationNameInfo NameInfo = E->getNameInfo();
5905 if (NameInfo.getName()) {
5906 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5907 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005908 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005909 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005910
5911 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00005912 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00005913 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005914 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00005915 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005916
5917 // Mark it referenced in the new context regardless.
5918 // FIXME: this is a bit instantiation-specific.
5919 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5920
John McCall3fa5cae2010-10-26 07:05:15 +00005921 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00005922 }
John McCalldbd872f2009-12-08 09:08:17 +00005923
5924 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00005925 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005926 TemplateArgs = &TransArgs;
5927 TransArgs.setLAngleLoc(E->getLAngleLoc());
5928 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005929 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5930 E->getNumTemplateArgs(),
5931 TransArgs))
5932 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00005933 }
5934
Douglas Gregor40d96a62011-02-28 21:54:11 +00005935 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5936 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005937}
Mike Stump1eb44332009-09-09 15:08:12 +00005938
Douglas Gregorb98b1992009-08-11 05:31:07 +00005939template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005940ExprResult
John McCall454feb92009-12-08 09:21:05 +00005941TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005942 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005943}
Mike Stump1eb44332009-09-09 15:08:12 +00005944
Douglas Gregorb98b1992009-08-11 05:31:07 +00005945template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005946ExprResult
John McCall454feb92009-12-08 09:21:05 +00005947TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005948 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005949}
Mike Stump1eb44332009-09-09 15:08:12 +00005950
Douglas Gregorb98b1992009-08-11 05:31:07 +00005951template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005952ExprResult
John McCall454feb92009-12-08 09:21:05 +00005953TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005954 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005955}
Mike Stump1eb44332009-09-09 15:08:12 +00005956
Douglas Gregorb98b1992009-08-11 05:31:07 +00005957template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005958ExprResult
John McCall454feb92009-12-08 09:21:05 +00005959TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005960 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005961}
Mike Stump1eb44332009-09-09 15:08:12 +00005962
Douglas Gregorb98b1992009-08-11 05:31:07 +00005963template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005964ExprResult
John McCall454feb92009-12-08 09:21:05 +00005965TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005966 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005967}
5968
5969template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005970ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00005971TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5972 ExprResult ControllingExpr =
5973 getDerived().TransformExpr(E->getControllingExpr());
5974 if (ControllingExpr.isInvalid())
5975 return ExprError();
5976
Chris Lattner686775d2011-07-20 06:58:45 +00005977 SmallVector<Expr *, 4> AssocExprs;
5978 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00005979 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5980 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5981 if (TS) {
5982 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5983 if (!AssocType)
5984 return ExprError();
5985 AssocTypes.push_back(AssocType);
5986 } else {
5987 AssocTypes.push_back(0);
5988 }
5989
5990 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5991 if (AssocExpr.isInvalid())
5992 return ExprError();
5993 AssocExprs.push_back(AssocExpr.release());
5994 }
5995
5996 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5997 E->getDefaultLoc(),
5998 E->getRParenLoc(),
5999 ControllingExpr.release(),
6000 AssocTypes.data(),
6001 AssocExprs.data(),
6002 E->getNumAssocs());
6003}
6004
6005template<typename Derived>
6006ExprResult
John McCall454feb92009-12-08 09:21:05 +00006007TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006008 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006009 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006010 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006011
Douglas Gregorb98b1992009-08-11 05:31:07 +00006012 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006013 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006014
John McCall9ae2f072010-08-23 23:25:46 +00006015 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006016 E->getRParen());
6017}
6018
Mike Stump1eb44332009-09-09 15:08:12 +00006019template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006020ExprResult
John McCall454feb92009-12-08 09:21:05 +00006021TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006022 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006023 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006024 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006025
Douglas Gregorb98b1992009-08-11 05:31:07 +00006026 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006027 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006028
Douglas Gregorb98b1992009-08-11 05:31:07 +00006029 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6030 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006031 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006032}
Mike Stump1eb44332009-09-09 15:08:12 +00006033
Douglas Gregorb98b1992009-08-11 05:31:07 +00006034template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006035ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006036TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6037 // Transform the type.
6038 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6039 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006040 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006041
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006042 // Transform all of the components into components similar to what the
6043 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00006044 // FIXME: It would be slightly more efficient in the non-dependent case to
6045 // just map FieldDecls, rather than requiring the rebuilder to look for
6046 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006047 // template code that we don't care.
6048 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006049 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006050 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006051 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006052 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6053 const Node &ON = E->getComponent(I);
6054 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006055 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006056 Comp.LocStart = ON.getSourceRange().getBegin();
6057 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006058 switch (ON.getKind()) {
6059 case Node::Array: {
6060 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006061 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006062 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006063 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006064
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006065 ExprChanged = ExprChanged || Index.get() != FromIndex;
6066 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006067 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006068 break;
6069 }
Sean Huntc3021132010-05-05 15:23:54 +00006070
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006071 case Node::Field:
6072 case Node::Identifier:
6073 Comp.isBrackets = false;
6074 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006075 if (!Comp.U.IdentInfo)
6076 continue;
Sean Huntc3021132010-05-05 15:23:54 +00006077
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006078 break;
Sean Huntc3021132010-05-05 15:23:54 +00006079
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006080 case Node::Base:
6081 // Will be recomputed during the rebuild.
6082 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006083 }
Sean Huntc3021132010-05-05 15:23:54 +00006084
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006085 Components.push_back(Comp);
6086 }
Sean Huntc3021132010-05-05 15:23:54 +00006087
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006088 // If nothing changed, retain the existing expression.
6089 if (!getDerived().AlwaysRebuild() &&
6090 Type == E->getTypeSourceInfo() &&
6091 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006092 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006093
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006094 // Build a new offsetof expression.
6095 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6096 Components.data(), Components.size(),
6097 E->getRParenLoc());
6098}
6099
6100template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006101ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006102TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6103 assert(getDerived().AlreadyTransformed(E->getType()) &&
6104 "opaque value expression requires transformation");
6105 return SemaRef.Owned(E);
6106}
6107
6108template<typename Derived>
6109ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006110TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006111 // Rebuild the syntactic form. The original syntactic form has
6112 // opaque-value expressions in it, so strip those away and rebuild
6113 // the result. This is a really awful way of doing this, but the
6114 // better solution (rebuilding the semantic expressions and
6115 // rebinding OVEs as necessary) doesn't work; we'd need
6116 // TreeTransform to not strip away implicit conversions.
6117 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6118 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006119 if (result.isInvalid()) return ExprError();
6120
6121 // If that gives us a pseudo-object result back, the pseudo-object
6122 // expression must have been an lvalue-to-rvalue conversion which we
6123 // should reapply.
6124 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6125 result = SemaRef.checkPseudoObjectRValue(result.take());
6126
6127 return result;
6128}
6129
6130template<typename Derived>
6131ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006132TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6133 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006134 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006135 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006136
John McCalla93c9342009-12-07 02:54:59 +00006137 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006138 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006139 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006140
John McCall5ab75172009-11-04 07:28:41 +00006141 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006142 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006143
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006144 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6145 E->getKind(),
6146 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006147 }
Mike Stump1eb44332009-09-09 15:08:12 +00006148
John McCall60d7b3a2010-08-24 06:29:42 +00006149 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00006150 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006151 // C++0x [expr.sizeof]p1:
6152 // The operand is either an expression, which is an unevaluated operand
6153 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00006154 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006155
Douglas Gregorb98b1992009-08-11 05:31:07 +00006156 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6157 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006158 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006159
Douglas Gregorb98b1992009-08-11 05:31:07 +00006160 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006161 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006162 }
Mike Stump1eb44332009-09-09 15:08:12 +00006163
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006164 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6165 E->getOperatorLoc(),
6166 E->getKind(),
6167 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006168}
Mike Stump1eb44332009-09-09 15:08:12 +00006169
Douglas Gregorb98b1992009-08-11 05:31:07 +00006170template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006171ExprResult
John McCall454feb92009-12-08 09:21:05 +00006172TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006173 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006174 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006175 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006176
John McCall60d7b3a2010-08-24 06:29:42 +00006177 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006178 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006179 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006180
6181
Douglas Gregorb98b1992009-08-11 05:31:07 +00006182 if (!getDerived().AlwaysRebuild() &&
6183 LHS.get() == E->getLHS() &&
6184 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006185 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006186
John McCall9ae2f072010-08-23 23:25:46 +00006187 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006188 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006189 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006190 E->getRBracketLoc());
6191}
Mike Stump1eb44332009-09-09 15:08:12 +00006192
6193template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006194ExprResult
John McCall454feb92009-12-08 09:21:05 +00006195TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006196 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006197 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006198 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006199 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006200
6201 // Transform arguments.
6202 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006203 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006204 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6205 &ArgChanged))
6206 return ExprError();
6207
Douglas Gregorb98b1992009-08-11 05:31:07 +00006208 if (!getDerived().AlwaysRebuild() &&
6209 Callee.get() == E->getCallee() &&
6210 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006211 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump1eb44332009-09-09 15:08:12 +00006212
Douglas Gregorb98b1992009-08-11 05:31:07 +00006213 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006214 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006215 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006216 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006217 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006218 E->getRParenLoc());
6219}
Mike Stump1eb44332009-09-09 15:08:12 +00006220
6221template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006222ExprResult
John McCall454feb92009-12-08 09:21:05 +00006223TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006224 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006225 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006226 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006227
Douglas Gregor40d96a62011-02-28 21:54:11 +00006228 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006229 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006230 QualifierLoc
6231 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6232
6233 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006234 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006235 }
Mike Stump1eb44332009-09-09 15:08:12 +00006236
Eli Friedmanf595cc42009-12-04 06:40:45 +00006237 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006238 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6239 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006240 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006241 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006242
John McCall6bb80172010-03-30 21:47:33 +00006243 NamedDecl *FoundDecl = E->getFoundDecl();
6244 if (FoundDecl == E->getMemberDecl()) {
6245 FoundDecl = Member;
6246 } else {
6247 FoundDecl = cast_or_null<NamedDecl>(
6248 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6249 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006250 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006251 }
6252
Douglas Gregorb98b1992009-08-11 05:31:07 +00006253 if (!getDerived().AlwaysRebuild() &&
6254 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006255 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006256 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006257 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006258 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006259
Anders Carlsson1f240322009-12-22 05:24:09 +00006260 // Mark it referenced in the new context regardless.
6261 // FIXME: this is a bit instantiation-specific.
6262 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00006263 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006264 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006265
John McCalld5532b62009-11-23 01:53:49 +00006266 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006267 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006268 TransArgs.setLAngleLoc(E->getLAngleLoc());
6269 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006270 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6271 E->getNumTemplateArgs(),
6272 TransArgs))
6273 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006274 }
Sean Huntc3021132010-05-05 15:23:54 +00006275
Douglas Gregorb98b1992009-08-11 05:31:07 +00006276 // FIXME: Bogus source location for the operator
6277 SourceLocation FakeOperatorLoc
6278 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6279
John McCallc2233c52010-01-15 08:34:02 +00006280 // FIXME: to do this check properly, we will need to preserve the
6281 // first-qualifier-in-scope here, just in case we had a dependent
6282 // base (and therefore couldn't do the check) and a
6283 // nested-name-qualifier (and therefore could do the lookup).
6284 NamedDecl *FirstQualifierInScope = 0;
6285
John McCall9ae2f072010-08-23 23:25:46 +00006286 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006287 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006288 QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006289 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006290 Member,
John McCall6bb80172010-03-30 21:47:33 +00006291 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006292 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006293 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006294 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006295}
Mike Stump1eb44332009-09-09 15:08:12 +00006296
Douglas Gregorb98b1992009-08-11 05:31:07 +00006297template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006298ExprResult
John McCall454feb92009-12-08 09:21:05 +00006299TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006300 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006301 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006302 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006303
John McCall60d7b3a2010-08-24 06:29:42 +00006304 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006305 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006306 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006307
Douglas Gregorb98b1992009-08-11 05:31:07 +00006308 if (!getDerived().AlwaysRebuild() &&
6309 LHS.get() == E->getLHS() &&
6310 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006311 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006312
Douglas Gregorb98b1992009-08-11 05:31:07 +00006313 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006314 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006315}
6316
Mike Stump1eb44332009-09-09 15:08:12 +00006317template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006318ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006319TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006320 CompoundAssignOperator *E) {
6321 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006322}
Mike Stump1eb44332009-09-09 15:08:12 +00006323
Douglas Gregorb98b1992009-08-11 05:31:07 +00006324template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006325ExprResult TreeTransform<Derived>::
6326TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6327 // Just rebuild the common and RHS expressions and see whether we
6328 // get any changes.
6329
6330 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6331 if (commonExpr.isInvalid())
6332 return ExprError();
6333
6334 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6335 if (rhs.isInvalid())
6336 return ExprError();
6337
6338 if (!getDerived().AlwaysRebuild() &&
6339 commonExpr.get() == e->getCommon() &&
6340 rhs.get() == e->getFalseExpr())
6341 return SemaRef.Owned(e);
6342
6343 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6344 e->getQuestionLoc(),
6345 0,
6346 e->getColonLoc(),
6347 rhs.get());
6348}
6349
6350template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006351ExprResult
John McCall454feb92009-12-08 09:21:05 +00006352TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006353 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006354 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006355 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006356
John McCall60d7b3a2010-08-24 06:29:42 +00006357 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006358 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006359 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006360
John McCall60d7b3a2010-08-24 06:29:42 +00006361 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006362 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006363 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006364
Douglas Gregorb98b1992009-08-11 05:31:07 +00006365 if (!getDerived().AlwaysRebuild() &&
6366 Cond.get() == E->getCond() &&
6367 LHS.get() == E->getLHS() &&
6368 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006369 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006370
John McCall9ae2f072010-08-23 23:25:46 +00006371 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006372 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006373 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006374 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006375 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006376}
Mike Stump1eb44332009-09-09 15:08:12 +00006377
6378template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006379ExprResult
John McCall454feb92009-12-08 09:21:05 +00006380TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006381 // Implicit casts are eliminated during transformation, since they
6382 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006383 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006384}
Mike Stump1eb44332009-09-09 15:08:12 +00006385
Douglas Gregorb98b1992009-08-11 05:31:07 +00006386template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006387ExprResult
John McCall454feb92009-12-08 09:21:05 +00006388TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006389 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6390 if (!Type)
6391 return ExprError();
6392
John McCall60d7b3a2010-08-24 06:29:42 +00006393 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006394 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006395 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006396 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006397
Douglas Gregorb98b1992009-08-11 05:31:07 +00006398 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006399 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006400 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006401 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006402
John McCall9d125032010-01-15 18:39:57 +00006403 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006404 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006405 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006406 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006407}
Mike Stump1eb44332009-09-09 15:08:12 +00006408
Douglas Gregorb98b1992009-08-11 05:31:07 +00006409template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006410ExprResult
John McCall454feb92009-12-08 09:21:05 +00006411TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006412 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6413 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6414 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006415 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006416
John McCall60d7b3a2010-08-24 06:29:42 +00006417 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006418 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006419 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006420
Douglas Gregorb98b1992009-08-11 05:31:07 +00006421 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006422 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006423 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006424 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006425
John McCall1d7d8d62010-01-19 22:33:45 +00006426 // Note: the expression type doesn't necessarily match the
6427 // type-as-written, but that's okay, because it should always be
6428 // derivable from the initializer.
6429
John McCall42f56b52010-01-18 19:35:47 +00006430 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006431 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006432 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006433}
Mike Stump1eb44332009-09-09 15:08:12 +00006434
Douglas Gregorb98b1992009-08-11 05:31:07 +00006435template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006436ExprResult
John McCall454feb92009-12-08 09:21:05 +00006437TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006438 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006439 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006440 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006441
Douglas Gregorb98b1992009-08-11 05:31:07 +00006442 if (!getDerived().AlwaysRebuild() &&
6443 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006444 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006445
Douglas Gregorb98b1992009-08-11 05:31:07 +00006446 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006447 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006448 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006449 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006450 E->getAccessorLoc(),
6451 E->getAccessor());
6452}
Mike Stump1eb44332009-09-09 15:08:12 +00006453
Douglas Gregorb98b1992009-08-11 05:31:07 +00006454template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006455ExprResult
John McCall454feb92009-12-08 09:21:05 +00006456TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006457 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006458
John McCallca0408f2010-08-23 06:44:23 +00006459 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006460 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6461 Inits, &InitChanged))
6462 return ExprError();
6463
Douglas Gregorb98b1992009-08-11 05:31:07 +00006464 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006465 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006466
Douglas Gregorb98b1992009-08-11 05:31:07 +00006467 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006468 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006469}
Mike Stump1eb44332009-09-09 15:08:12 +00006470
Douglas Gregorb98b1992009-08-11 05:31:07 +00006471template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006472ExprResult
John McCall454feb92009-12-08 09:21:05 +00006473TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006474 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006475
Douglas Gregor43959a92009-08-20 07:17:43 +00006476 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006477 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006478 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006479 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006480
Douglas Gregor43959a92009-08-20 07:17:43 +00006481 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006482 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006483 bool ExprChanged = false;
6484 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6485 DEnd = E->designators_end();
6486 D != DEnd; ++D) {
6487 if (D->isFieldDesignator()) {
6488 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6489 D->getDotLoc(),
6490 D->getFieldLoc()));
6491 continue;
6492 }
Mike Stump1eb44332009-09-09 15:08:12 +00006493
Douglas Gregorb98b1992009-08-11 05:31:07 +00006494 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006495 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006496 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006497 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006498
6499 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006500 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006501
Douglas Gregorb98b1992009-08-11 05:31:07 +00006502 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6503 ArrayExprs.push_back(Index.release());
6504 continue;
6505 }
Mike Stump1eb44332009-09-09 15:08:12 +00006506
Douglas Gregorb98b1992009-08-11 05:31:07 +00006507 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006508 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006509 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6510 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006511 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006512
John McCall60d7b3a2010-08-24 06:29:42 +00006513 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006514 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006515 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006516
6517 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006518 End.get(),
6519 D->getLBracketLoc(),
6520 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006521
Douglas Gregorb98b1992009-08-11 05:31:07 +00006522 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6523 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006524
Douglas Gregorb98b1992009-08-11 05:31:07 +00006525 ArrayExprs.push_back(Start.release());
6526 ArrayExprs.push_back(End.release());
6527 }
Mike Stump1eb44332009-09-09 15:08:12 +00006528
Douglas Gregorb98b1992009-08-11 05:31:07 +00006529 if (!getDerived().AlwaysRebuild() &&
6530 Init.get() == E->getInit() &&
6531 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006532 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006533
Douglas Gregorb98b1992009-08-11 05:31:07 +00006534 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6535 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006536 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006537}
Mike Stump1eb44332009-09-09 15:08:12 +00006538
Douglas Gregorb98b1992009-08-11 05:31:07 +00006539template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006540ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006541TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006542 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006543 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006544
Douglas Gregor5557b252009-10-28 00:29:27 +00006545 // FIXME: Will we ever have proper type location here? Will we actually
6546 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006547 QualType T = getDerived().TransformType(E->getType());
6548 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006549 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006550
Douglas Gregorb98b1992009-08-11 05:31:07 +00006551 if (!getDerived().AlwaysRebuild() &&
6552 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006553 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006554
Douglas Gregorb98b1992009-08-11 05:31:07 +00006555 return getDerived().RebuildImplicitValueInitExpr(T);
6556}
Mike Stump1eb44332009-09-09 15:08:12 +00006557
Douglas Gregorb98b1992009-08-11 05:31:07 +00006558template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006559ExprResult
John McCall454feb92009-12-08 09:21:05 +00006560TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006561 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6562 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006563 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006564
John McCall60d7b3a2010-08-24 06:29:42 +00006565 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006566 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006567 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006568
Douglas Gregorb98b1992009-08-11 05:31:07 +00006569 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006570 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006571 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006572 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006573
John McCall9ae2f072010-08-23 23:25:46 +00006574 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006575 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006576}
6577
6578template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006579ExprResult
John McCall454feb92009-12-08 09:21:05 +00006580TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006581 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006582 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006583 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6584 &ArgumentChanged))
6585 return ExprError();
6586
Douglas Gregorb98b1992009-08-11 05:31:07 +00006587 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6588 move_arg(Inits),
6589 E->getRParenLoc());
6590}
Mike Stump1eb44332009-09-09 15:08:12 +00006591
Douglas Gregorb98b1992009-08-11 05:31:07 +00006592/// \brief Transform an address-of-label expression.
6593///
6594/// By default, the transformation of an address-of-label expression always
6595/// rebuilds the expression, so that the label identifier can be resolved to
6596/// the corresponding label statement by semantic analysis.
6597template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006598ExprResult
John McCall454feb92009-12-08 09:21:05 +00006599TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006600 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6601 E->getLabel());
6602 if (!LD)
6603 return ExprError();
6604
Douglas Gregorb98b1992009-08-11 05:31:07 +00006605 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006606 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006607}
Mike Stump1eb44332009-09-09 15:08:12 +00006608
6609template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006610ExprResult
John McCall454feb92009-12-08 09:21:05 +00006611TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006612 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006613 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6614 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006615 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006616
Douglas Gregorb98b1992009-08-11 05:31:07 +00006617 if (!getDerived().AlwaysRebuild() &&
6618 SubStmt.get() == E->getSubStmt())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006619 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006620
6621 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006622 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006623 E->getRParenLoc());
6624}
Mike Stump1eb44332009-09-09 15:08:12 +00006625
Douglas Gregorb98b1992009-08-11 05:31:07 +00006626template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006627ExprResult
John McCall454feb92009-12-08 09:21:05 +00006628TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006629 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006630 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006631 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006632
John McCall60d7b3a2010-08-24 06:29:42 +00006633 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006634 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006635 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006636
John McCall60d7b3a2010-08-24 06:29:42 +00006637 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006638 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006639 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006640
Douglas Gregorb98b1992009-08-11 05:31:07 +00006641 if (!getDerived().AlwaysRebuild() &&
6642 Cond.get() == E->getCond() &&
6643 LHS.get() == E->getLHS() &&
6644 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006645 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006646
Douglas Gregorb98b1992009-08-11 05:31:07 +00006647 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006648 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006649 E->getRParenLoc());
6650}
Mike Stump1eb44332009-09-09 15:08:12 +00006651
Douglas Gregorb98b1992009-08-11 05:31:07 +00006652template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006653ExprResult
John McCall454feb92009-12-08 09:21:05 +00006654TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006655 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006656}
6657
6658template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006659ExprResult
John McCall454feb92009-12-08 09:21:05 +00006660TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006661 switch (E->getOperator()) {
6662 case OO_New:
6663 case OO_Delete:
6664 case OO_Array_New:
6665 case OO_Array_Delete:
6666 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00006667 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006668
Douglas Gregor668d6d92009-12-13 20:44:55 +00006669 case OO_Call: {
6670 // This is a call to an object's operator().
6671 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6672
6673 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006674 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006675 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006676 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006677
6678 // FIXME: Poor location information
6679 SourceLocation FakeLParenLoc
6680 = SemaRef.PP.getLocForEndOfToken(
6681 static_cast<Expr *>(Object.get())->getLocEnd());
6682
6683 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006684 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006685 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6686 Args))
6687 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006688
John McCall9ae2f072010-08-23 23:25:46 +00006689 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006690 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006691 E->getLocEnd());
6692 }
6693
6694#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6695 case OO_##Name:
6696#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6697#include "clang/Basic/OperatorKinds.def"
6698 case OO_Subscript:
6699 // Handled below.
6700 break;
6701
6702 case OO_Conditional:
6703 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00006704 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006705
6706 case OO_None:
6707 case NUM_OVERLOADED_OPERATORS:
6708 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00006709 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006710 }
6711
John McCall60d7b3a2010-08-24 06:29:42 +00006712 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006713 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006714 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006715
John McCall60d7b3a2010-08-24 06:29:42 +00006716 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006717 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006718 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006719
John McCall60d7b3a2010-08-24 06:29:42 +00006720 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006721 if (E->getNumArgs() == 2) {
6722 Second = getDerived().TransformExpr(E->getArg(1));
6723 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006724 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006725 }
Mike Stump1eb44332009-09-09 15:08:12 +00006726
Douglas Gregorb98b1992009-08-11 05:31:07 +00006727 if (!getDerived().AlwaysRebuild() &&
6728 Callee.get() == E->getCallee() &&
6729 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006730 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006731 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006732
Douglas Gregorb98b1992009-08-11 05:31:07 +00006733 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6734 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006735 Callee.get(),
6736 First.get(),
6737 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006738}
Mike Stump1eb44332009-09-09 15:08:12 +00006739
Douglas Gregorb98b1992009-08-11 05:31:07 +00006740template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006741ExprResult
John McCall454feb92009-12-08 09:21:05 +00006742TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6743 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006744}
Mike Stump1eb44332009-09-09 15:08:12 +00006745
Douglas Gregorb98b1992009-08-11 05:31:07 +00006746template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006747ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006748TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6749 // Transform the callee.
6750 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6751 if (Callee.isInvalid())
6752 return ExprError();
6753
6754 // Transform exec config.
6755 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6756 if (EC.isInvalid())
6757 return ExprError();
6758
6759 // Transform arguments.
6760 bool ArgChanged = false;
6761 ASTOwningVector<Expr*> Args(SemaRef);
6762 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6763 &ArgChanged))
6764 return ExprError();
6765
6766 if (!getDerived().AlwaysRebuild() &&
6767 Callee.get() == E->getCallee() &&
6768 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006769 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006770
6771 // FIXME: Wrong source location information for the '('.
6772 SourceLocation FakeLParenLoc
6773 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6774 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6775 move_arg(Args),
6776 E->getRParenLoc(), EC.get());
6777}
6778
6779template<typename Derived>
6780ExprResult
John McCall454feb92009-12-08 09:21:05 +00006781TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006782 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6783 if (!Type)
6784 return ExprError();
6785
John McCall60d7b3a2010-08-24 06:29:42 +00006786 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006787 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006788 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006789 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006790
Douglas Gregorb98b1992009-08-11 05:31:07 +00006791 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006792 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006793 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006794 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006795
Douglas Gregorb98b1992009-08-11 05:31:07 +00006796 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006797 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006798 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6799 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6800 SourceLocation FakeRParenLoc
6801 = SemaRef.PP.getLocForEndOfToken(
6802 E->getSubExpr()->getSourceRange().getEnd());
6803 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006804 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006805 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006806 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006807 FakeRAngleLoc,
6808 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006809 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006810 FakeRParenLoc);
6811}
Mike Stump1eb44332009-09-09 15:08:12 +00006812
Douglas Gregorb98b1992009-08-11 05:31:07 +00006813template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006814ExprResult
John McCall454feb92009-12-08 09:21:05 +00006815TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6816 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006817}
Mike Stump1eb44332009-09-09 15:08:12 +00006818
6819template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006820ExprResult
John McCall454feb92009-12-08 09:21:05 +00006821TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6822 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006823}
6824
Douglas Gregorb98b1992009-08-11 05:31:07 +00006825template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006826ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006827TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006828 CXXReinterpretCastExpr *E) {
6829 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006830}
Mike Stump1eb44332009-09-09 15:08:12 +00006831
Douglas Gregorb98b1992009-08-11 05:31:07 +00006832template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006833ExprResult
John McCall454feb92009-12-08 09:21:05 +00006834TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6835 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006836}
Mike Stump1eb44332009-09-09 15:08:12 +00006837
Douglas Gregorb98b1992009-08-11 05:31:07 +00006838template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006839ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006840TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006841 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006842 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6843 if (!Type)
6844 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006845
John McCall60d7b3a2010-08-24 06:29:42 +00006846 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006847 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006848 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006849 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006850
Douglas Gregorb98b1992009-08-11 05:31:07 +00006851 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006852 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006853 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006854 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006855
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006856 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006857 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006858 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006859 E->getRParenLoc());
6860}
Mike Stump1eb44332009-09-09 15:08:12 +00006861
Douglas Gregorb98b1992009-08-11 05:31:07 +00006862template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006863ExprResult
John McCall454feb92009-12-08 09:21:05 +00006864TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006865 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006866 TypeSourceInfo *TInfo
6867 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6868 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006869 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006870
Douglas Gregorb98b1992009-08-11 05:31:07 +00006871 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006872 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006873 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006874
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006875 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6876 E->getLocStart(),
6877 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006878 E->getLocEnd());
6879 }
Mike Stump1eb44332009-09-09 15:08:12 +00006880
Douglas Gregorb98b1992009-08-11 05:31:07 +00006881 // We don't know whether the expression is potentially evaluated until
6882 // after we perform semantic analysis, so the expression is potentially
6883 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00006884 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00006885 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006886
John McCall60d7b3a2010-08-24 06:29:42 +00006887 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006888 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006889 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006890
Douglas Gregorb98b1992009-08-11 05:31:07 +00006891 if (!getDerived().AlwaysRebuild() &&
6892 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006893 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006894
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006895 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6896 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006897 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006898 E->getLocEnd());
6899}
6900
6901template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006902ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00006903TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6904 if (E->isTypeOperand()) {
6905 TypeSourceInfo *TInfo
6906 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6907 if (!TInfo)
6908 return ExprError();
6909
6910 if (!getDerived().AlwaysRebuild() &&
6911 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006912 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006913
Douglas Gregor3c52a212011-03-06 17:40:41 +00006914 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00006915 E->getLocStart(),
6916 TInfo,
6917 E->getLocEnd());
6918 }
6919
Francois Pichet01b7c302010-09-08 12:20:18 +00006920 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6921
6922 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6923 if (SubExpr.isInvalid())
6924 return ExprError();
6925
6926 if (!getDerived().AlwaysRebuild() &&
6927 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006928 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006929
6930 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6931 E->getLocStart(),
6932 SubExpr.get(),
6933 E->getLocEnd());
6934}
6935
6936template<typename Derived>
6937ExprResult
John McCall454feb92009-12-08 09:21:05 +00006938TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006939 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006940}
Mike Stump1eb44332009-09-09 15:08:12 +00006941
Douglas Gregorb98b1992009-08-11 05:31:07 +00006942template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006943ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006944TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00006945 CXXNullPtrLiteralExpr *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
John McCall454feb92009-12-08 09:21:05 +00006951TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006952 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00006953 QualType T;
6954 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
6955 T = MD->getThisType(getSema().Context);
6956 else
6957 T = getSema().Context.getPointerType(
6958 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00006959
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006960 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006961 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006962
Douglas Gregor828a1972010-01-07 23:12:05 +00006963 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006964}
Mike Stump1eb44332009-09-09 15:08:12 +00006965
Douglas Gregorb98b1992009-08-11 05:31:07 +00006966template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006967ExprResult
John McCall454feb92009-12-08 09:21:05 +00006968TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006969 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006970 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006971 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006972
Douglas Gregorb98b1992009-08-11 05:31:07 +00006973 if (!getDerived().AlwaysRebuild() &&
6974 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006975 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006976
Douglas Gregorbca01b42011-07-06 22:04:06 +00006977 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
6978 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006979}
Mike Stump1eb44332009-09-09 15:08:12 +00006980
Douglas Gregorb98b1992009-08-11 05:31:07 +00006981template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006982ExprResult
John McCall454feb92009-12-08 09:21:05 +00006983TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006984 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006985 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6986 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006987 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00006988 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006989
Chandler Carruth53cb6f82010-02-08 06:42:49 +00006990 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006991 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00006992 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006993
Douglas Gregor036aed12009-12-23 23:03:06 +00006994 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006995}
Mike Stump1eb44332009-09-09 15:08:12 +00006996
Douglas Gregorb98b1992009-08-11 05:31:07 +00006997template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006998ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00006999TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7000 CXXScalarValueInitExpr *E) {
7001 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7002 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007003 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00007004
Douglas Gregorb98b1992009-08-11 05:31:07 +00007005 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007006 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007007 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007008
Douglas Gregorab6677e2010-09-08 00:15:04 +00007009 return getDerived().RebuildCXXScalarValueInitExpr(T,
7010 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007011 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007012}
Mike Stump1eb44332009-09-09 15:08:12 +00007013
Douglas Gregorb98b1992009-08-11 05:31:07 +00007014template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007015ExprResult
John McCall454feb92009-12-08 09:21:05 +00007016TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007017 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007018 TypeSourceInfo *AllocTypeInfo
7019 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7020 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007021 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007022
Douglas Gregorb98b1992009-08-11 05:31:07 +00007023 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007024 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007025 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007026 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007027
Douglas Gregorb98b1992009-08-11 05:31:07 +00007028 // Transform the placement arguments (if any).
7029 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007030 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007031 if (getDerived().TransformExprs(E->getPlacementArgs(),
7032 E->getNumPlacementArgs(), true,
7033 PlacementArgs, &ArgumentChanged))
7034 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007035
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007036 // Transform the constructor arguments (if any).
7037 // As an annoying corner case, we may have introduced an implicit value-
7038 // initialization expression when allocating a new array, which we implicitly
7039 // drop. It will be re-created during type checking.
John McCallca0408f2010-08-23 06:44:23 +00007040 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007041 if (!(E->isArray() && E->getNumConstructorArgs() == 1 &&
7042 isa<ImplicitValueInitExpr>(E->getConstructorArgs()[0])) &&
7043 TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007044 ConstructorArgs, &ArgumentChanged))
7045 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007046
Douglas Gregor1af74512010-02-26 00:38:10 +00007047 // Transform constructor, new operator, and delete operator.
7048 CXXConstructorDecl *Constructor = 0;
7049 if (E->getConstructor()) {
7050 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007051 getDerived().TransformDecl(E->getLocStart(),
7052 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007053 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007054 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007055 }
7056
7057 FunctionDecl *OperatorNew = 0;
7058 if (E->getOperatorNew()) {
7059 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007060 getDerived().TransformDecl(E->getLocStart(),
7061 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007062 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007063 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007064 }
7065
7066 FunctionDecl *OperatorDelete = 0;
7067 if (E->getOperatorDelete()) {
7068 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007069 getDerived().TransformDecl(E->getLocStart(),
7070 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007071 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007072 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007073 }
Sean Huntc3021132010-05-05 15:23:54 +00007074
Douglas Gregorb98b1992009-08-11 05:31:07 +00007075 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007076 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007077 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007078 Constructor == E->getConstructor() &&
7079 OperatorNew == E->getOperatorNew() &&
7080 OperatorDelete == E->getOperatorDelete() &&
7081 !ArgumentChanged) {
7082 // Mark any declarations we need as referenced.
7083 // FIXME: instantiation-specific.
7084 if (Constructor)
7085 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
7086 if (OperatorNew)
7087 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
7088 if (OperatorDelete)
7089 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007090
7091 if (E->isArray() && Constructor &&
7092 !E->getAllocatedType()->isDependentType()) {
7093 QualType ElementType
7094 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7095 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7096 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7097 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
7098 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Destructor);
7099 }
7100 }
7101 }
7102
John McCall3fa5cae2010-10-26 07:05:15 +00007103 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007104 }
Mike Stump1eb44332009-09-09 15:08:12 +00007105
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007106 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007107 if (!ArraySize.get()) {
7108 // If no array size was specified, but the new expression was
7109 // instantiated with an array type (e.g., "new T" where T is
7110 // instantiated with "int[4]"), extract the outer bound from the
7111 // array type as our array size. We do this with constant and
7112 // dependently-sized array types.
7113 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7114 if (!ArrayT) {
7115 // Do nothing
7116 } else if (const ConstantArrayType *ConsArrayT
7117 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00007118 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007119 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7120 ConsArrayT->getSize(),
7121 SemaRef.Context.getSizeType(),
7122 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007123 AllocType = ConsArrayT->getElementType();
7124 } else if (const DependentSizedArrayType *DepArrayT
7125 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7126 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007127 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007128 AllocType = DepArrayT->getElementType();
7129 }
7130 }
7131 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007132
Douglas Gregorb98b1992009-08-11 05:31:07 +00007133 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7134 E->isGlobalNew(),
7135 /*FIXME:*/E->getLocStart(),
7136 move_arg(PlacementArgs),
7137 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007138 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007139 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007140 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007141 ArraySize.get(),
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007142 E->getConstructorLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007143 move_arg(ConstructorArgs),
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007144 E->getConstructorRParen());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007145}
Mike Stump1eb44332009-09-09 15:08:12 +00007146
Douglas Gregorb98b1992009-08-11 05:31:07 +00007147template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007148ExprResult
John McCall454feb92009-12-08 09:21:05 +00007149TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007150 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007151 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007152 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007153
Douglas Gregor1af74512010-02-26 00:38:10 +00007154 // Transform the delete operator, if known.
7155 FunctionDecl *OperatorDelete = 0;
7156 if (E->getOperatorDelete()) {
7157 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007158 getDerived().TransformDecl(E->getLocStart(),
7159 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007160 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007161 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007162 }
Sean Huntc3021132010-05-05 15:23:54 +00007163
Douglas Gregorb98b1992009-08-11 05:31:07 +00007164 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007165 Operand.get() == E->getArgument() &&
7166 OperatorDelete == E->getOperatorDelete()) {
7167 // Mark any declarations we need as referenced.
7168 // FIXME: instantiation-specific.
7169 if (OperatorDelete)
7170 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007171
7172 if (!E->getArgument()->isTypeDependent()) {
7173 QualType Destroyed = SemaRef.Context.getBaseElementType(
7174 E->getDestroyedType());
7175 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7176 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
7177 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
7178 SemaRef.LookupDestructor(Record));
7179 }
7180 }
7181
John McCall3fa5cae2010-10-26 07:05:15 +00007182 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007183 }
Mike Stump1eb44332009-09-09 15:08:12 +00007184
Douglas Gregorb98b1992009-08-11 05:31:07 +00007185 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7186 E->isGlobalDelete(),
7187 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007188 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007189}
Mike Stump1eb44332009-09-09 15:08:12 +00007190
Douglas Gregorb98b1992009-08-11 05:31:07 +00007191template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007192ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007193TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007194 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007195 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007196 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007197 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007198
John McCallb3d87482010-08-24 05:47:05 +00007199 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007200 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007201 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007202 E->getOperatorLoc(),
7203 E->isArrow()? tok::arrow : tok::period,
7204 ObjectTypePtr,
7205 MayBePseudoDestructor);
7206 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007207 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007208
John McCallb3d87482010-08-24 05:47:05 +00007209 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007210 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7211 if (QualifierLoc) {
7212 QualifierLoc
7213 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7214 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007215 return ExprError();
7216 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007217 CXXScopeSpec SS;
7218 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007219
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007220 PseudoDestructorTypeStorage Destroyed;
7221 if (E->getDestroyedTypeInfo()) {
7222 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007223 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007224 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007225 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007226 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007227 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007228 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007229 // We aren't likely to be able to resolve the identifier down to a type
7230 // now anyway, so just retain the identifier.
7231 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7232 E->getDestroyedTypeLoc());
7233 } else {
7234 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007235 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007236 *E->getDestroyedTypeIdentifier(),
7237 E->getDestroyedTypeLoc(),
7238 /*Scope=*/0,
7239 SS, ObjectTypePtr,
7240 false);
7241 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007242 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007243
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007244 Destroyed
7245 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7246 E->getDestroyedTypeLoc());
7247 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007248
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007249 TypeSourceInfo *ScopeTypeInfo = 0;
7250 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007251 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007252 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007253 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007254 }
Sean Huntc3021132010-05-05 15:23:54 +00007255
John McCall9ae2f072010-08-23 23:25:46 +00007256 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007257 E->getOperatorLoc(),
7258 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007259 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007260 ScopeTypeInfo,
7261 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007262 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007263 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007264}
Mike Stump1eb44332009-09-09 15:08:12 +00007265
Douglas Gregora71d8192009-09-04 17:36:40 +00007266template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007267ExprResult
John McCallba135432009-11-21 08:51:07 +00007268TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007269 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007270 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7271 Sema::LookupOrdinaryName);
7272
7273 // Transform all the decls.
7274 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7275 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007276 NamedDecl *InstD = static_cast<NamedDecl*>(
7277 getDerived().TransformDecl(Old->getNameLoc(),
7278 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007279 if (!InstD) {
7280 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7281 // This can happen because of dependent hiding.
7282 if (isa<UsingShadowDecl>(*I))
7283 continue;
7284 else
John McCallf312b1e2010-08-26 23:41:50 +00007285 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007286 }
John McCallf7a1a742009-11-24 19:00:30 +00007287
7288 // Expand using declarations.
7289 if (isa<UsingDecl>(InstD)) {
7290 UsingDecl *UD = cast<UsingDecl>(InstD);
7291 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7292 E = UD->shadow_end(); I != E; ++I)
7293 R.addDecl(*I);
7294 continue;
7295 }
7296
7297 R.addDecl(InstD);
7298 }
7299
7300 // Resolve a kind, but don't do any further analysis. If it's
7301 // ambiguous, the callee needs to deal with it.
7302 R.resolveKind();
7303
7304 // Rebuild the nested-name qualifier, if present.
7305 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007306 if (Old->getQualifierLoc()) {
7307 NestedNameSpecifierLoc QualifierLoc
7308 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7309 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007310 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007311
Douglas Gregor4c9be892011-02-28 20:01:57 +00007312 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007313 }
7314
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007315 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007316 CXXRecordDecl *NamingClass
7317 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7318 Old->getNameLoc(),
7319 Old->getNamingClass()));
7320 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007321 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007322
Douglas Gregor66c45152010-04-27 16:10:10 +00007323 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007324 }
7325
7326 // If we have no template arguments, it's a normal declaration name.
7327 if (!Old->hasExplicitTemplateArgs())
7328 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7329
7330 // If we have template arguments, rebuild them, then rebuild the
7331 // templateid expression.
7332 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007333 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7334 Old->getNumTemplateArgs(),
7335 TransArgs))
7336 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007337
7338 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7339 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007340}
Mike Stump1eb44332009-09-09 15:08:12 +00007341
Douglas Gregorb98b1992009-08-11 05:31:07 +00007342template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007343ExprResult
John McCall454feb92009-12-08 09:21:05 +00007344TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007345 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7346 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007347 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007348
Douglas Gregorb98b1992009-08-11 05:31:07 +00007349 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007350 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007351 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007352
Mike Stump1eb44332009-09-09 15:08:12 +00007353 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007354 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007355 T,
7356 E->getLocEnd());
7357}
Mike Stump1eb44332009-09-09 15:08:12 +00007358
Douglas Gregorb98b1992009-08-11 05:31:07 +00007359template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007360ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007361TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7362 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7363 if (!LhsT)
7364 return ExprError();
7365
7366 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7367 if (!RhsT)
7368 return ExprError();
7369
7370 if (!getDerived().AlwaysRebuild() &&
7371 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7372 return SemaRef.Owned(E);
7373
7374 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7375 E->getLocStart(),
7376 LhsT, RhsT,
7377 E->getLocEnd());
7378}
7379
7380template<typename Derived>
7381ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007382TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7383 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7384 if (!T)
7385 return ExprError();
7386
7387 if (!getDerived().AlwaysRebuild() &&
7388 T == E->getQueriedTypeSourceInfo())
7389 return SemaRef.Owned(E);
7390
7391 ExprResult SubExpr;
7392 {
7393 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7394 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7395 if (SubExpr.isInvalid())
7396 return ExprError();
7397
7398 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7399 return SemaRef.Owned(E);
7400 }
7401
7402 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7403 E->getLocStart(),
7404 T,
7405 SubExpr.get(),
7406 E->getLocEnd());
7407}
7408
7409template<typename Derived>
7410ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007411TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7412 ExprResult SubExpr;
7413 {
7414 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7415 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7416 if (SubExpr.isInvalid())
7417 return ExprError();
7418
7419 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7420 return SemaRef.Owned(E);
7421 }
7422
7423 return getDerived().RebuildExpressionTrait(
7424 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7425}
7426
7427template<typename Derived>
7428ExprResult
John McCall865d4472009-11-19 22:55:06 +00007429TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007430 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007431 NestedNameSpecifierLoc QualifierLoc
7432 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7433 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007434 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007435
John McCall43fed0d2010-11-12 08:19:04 +00007436 // TODO: If this is a conversion-function-id, verify that the
7437 // destination type name (if present) resolves the same way after
7438 // instantiation as it did in the local scope.
7439
Abramo Bagnara25777432010-08-11 22:01:17 +00007440 DeclarationNameInfo NameInfo
7441 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7442 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007443 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007444
John McCallf7a1a742009-11-24 19:00:30 +00007445 if (!E->hasExplicitTemplateArgs()) {
7446 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007447 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007448 // Note: it is sufficient to compare the Name component of NameInfo:
7449 // if name has not changed, DNLoc has not changed either.
7450 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007451 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007452
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007453 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007454 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007455 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007456 }
John McCalld5532b62009-11-23 01:53:49 +00007457
7458 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007459 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7460 E->getNumTemplateArgs(),
7461 TransArgs))
7462 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007463
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007464 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007465 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007466 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007467}
7468
7469template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007470ExprResult
John McCall454feb92009-12-08 09:21:05 +00007471TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007472 // CXXConstructExprs are always implicit, so when we have a
7473 // 1-argument construction we just transform that argument.
7474 if (E->getNumArgs() == 1 ||
7475 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7476 return getDerived().TransformExpr(E->getArg(0));
7477
Douglas Gregorb98b1992009-08-11 05:31:07 +00007478 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7479
7480 QualType T = getDerived().TransformType(E->getType());
7481 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007482 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007483
7484 CXXConstructorDecl *Constructor
7485 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007486 getDerived().TransformDecl(E->getLocStart(),
7487 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007488 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007489 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007490
Douglas Gregorb98b1992009-08-11 05:31:07 +00007491 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007492 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007493 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7494 &ArgumentChanged))
7495 return ExprError();
7496
Douglas Gregorb98b1992009-08-11 05:31:07 +00007497 if (!getDerived().AlwaysRebuild() &&
7498 T == E->getType() &&
7499 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007500 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007501 // Mark the constructor as referenced.
7502 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00007503 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007504 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007505 }
Mike Stump1eb44332009-09-09 15:08:12 +00007506
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007507 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7508 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007509 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007510 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007511 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007512 E->getConstructionKind(),
7513 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007514}
Mike Stump1eb44332009-09-09 15:08:12 +00007515
Douglas Gregorb98b1992009-08-11 05:31:07 +00007516/// \brief Transform a C++ temporary-binding expression.
7517///
Douglas Gregor51326552009-12-24 18:51:59 +00007518/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7519/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007520template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007521ExprResult
John McCall454feb92009-12-08 09:21:05 +00007522TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007523 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007524}
Mike Stump1eb44332009-09-09 15:08:12 +00007525
John McCall4765fa02010-12-06 08:20:24 +00007526/// \brief Transform a C++ expression that contains cleanups that should
7527/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007528///
John McCall4765fa02010-12-06 08:20:24 +00007529/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007530/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007531template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007532ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007533TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007534 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007535}
Mike Stump1eb44332009-09-09 15:08:12 +00007536
Douglas Gregorb98b1992009-08-11 05:31:07 +00007537template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007538ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007539TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007540 CXXTemporaryObjectExpr *E) {
7541 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7542 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007543 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007544
Douglas Gregorb98b1992009-08-11 05:31:07 +00007545 CXXConstructorDecl *Constructor
7546 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007547 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007548 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007549 if (!Constructor)
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 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007553 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007554 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007555 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7556 &ArgumentChanged))
7557 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007558
Douglas Gregorb98b1992009-08-11 05:31:07 +00007559 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007560 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007561 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007562 !ArgumentChanged) {
7563 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00007564 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007565 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007566 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007567
7568 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7569 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007570 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007571 E->getLocEnd());
7572}
Mike Stump1eb44332009-09-09 15:08:12 +00007573
Douglas Gregorb98b1992009-08-11 05:31:07 +00007574template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007575ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007576TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007577 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007578 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7579 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007580 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007581
Douglas Gregorb98b1992009-08-11 05:31:07 +00007582 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007583 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007584 Args.reserve(E->arg_size());
7585 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7586 &ArgumentChanged))
7587 return ExprError();
7588
Douglas Gregorb98b1992009-08-11 05:31:07 +00007589 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007590 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007591 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007592 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007593
Douglas Gregorb98b1992009-08-11 05:31:07 +00007594 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00007595 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007596 E->getLParenLoc(),
7597 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007598 E->getRParenLoc());
7599}
Mike Stump1eb44332009-09-09 15:08:12 +00007600
Douglas Gregorb98b1992009-08-11 05:31:07 +00007601template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007602ExprResult
John McCall865d4472009-11-19 22:55:06 +00007603TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007604 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007605 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007606 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007607 Expr *OldBase;
7608 QualType BaseType;
7609 QualType ObjectType;
7610 if (!E->isImplicitAccess()) {
7611 OldBase = E->getBase();
7612 Base = getDerived().TransformExpr(OldBase);
7613 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007614 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007615
John McCallaa81e162009-12-01 22:10:20 +00007616 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00007617 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00007618 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007619 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007620 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00007621 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00007622 ObjectTy,
7623 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00007624 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007625 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007626
John McCallb3d87482010-08-24 05:47:05 +00007627 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00007628 BaseType = ((Expr*) Base.get())->getType();
7629 } else {
7630 OldBase = 0;
7631 BaseType = getDerived().TransformType(E->getBaseType());
7632 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7633 }
Mike Stump1eb44332009-09-09 15:08:12 +00007634
Douglas Gregor6cd21982009-10-20 05:58:46 +00007635 // Transform the first part of the nested-name-specifier that qualifies
7636 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00007637 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00007638 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007639 E->getFirstQualifierFoundInScope(),
7640 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00007641
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007642 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00007643 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007644 QualifierLoc
7645 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7646 ObjectType,
7647 FirstQualifierInScope);
7648 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007649 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00007650 }
Mike Stump1eb44332009-09-09 15:08:12 +00007651
John McCall43fed0d2010-11-12 08:19:04 +00007652 // TODO: If this is a conversion-function-id, verify that the
7653 // destination type name (if present) resolves the same way after
7654 // instantiation as it did in the local scope.
7655
Abramo Bagnara25777432010-08-11 22:01:17 +00007656 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00007657 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00007658 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007659 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007660
John McCallaa81e162009-12-01 22:10:20 +00007661 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007662 // This is a reference to a member without an explicitly-specified
7663 // template argument list. Optimize for this common case.
7664 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00007665 Base.get() == OldBase &&
7666 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007667 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007668 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007669 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00007670 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007671
John McCall9ae2f072010-08-23 23:25:46 +00007672 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007673 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007674 E->isArrow(),
7675 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007676 QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00007677 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007678 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007679 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007680 }
7681
John McCalld5532b62009-11-23 01:53:49 +00007682 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007683 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7684 E->getNumTemplateArgs(),
7685 TransArgs))
7686 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007687
John McCall9ae2f072010-08-23 23:25:46 +00007688 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007689 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007690 E->isArrow(),
7691 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007692 QualifierLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007693 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007694 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007695 &TransArgs);
7696}
7697
7698template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007699ExprResult
John McCall454feb92009-12-08 09:21:05 +00007700TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00007701 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007702 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007703 QualType BaseType;
7704 if (!Old->isImplicitAccess()) {
7705 Base = getDerived().TransformExpr(Old->getBase());
7706 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007707 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00007708 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
7709 Old->isArrow());
7710 if (Base.isInvalid())
7711 return ExprError();
7712 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00007713 } else {
7714 BaseType = getDerived().TransformType(Old->getBaseType());
7715 }
John McCall129e2df2009-11-30 22:42:35 +00007716
Douglas Gregor4c9be892011-02-28 20:01:57 +00007717 NestedNameSpecifierLoc QualifierLoc;
7718 if (Old->getQualifierLoc()) {
7719 QualifierLoc
7720 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7721 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007722 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007723 }
7724
Abramo Bagnara25777432010-08-11 22:01:17 +00007725 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00007726 Sema::LookupOrdinaryName);
7727
7728 // Transform all the decls.
7729 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7730 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007731 NamedDecl *InstD = static_cast<NamedDecl*>(
7732 getDerived().TransformDecl(Old->getMemberLoc(),
7733 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007734 if (!InstD) {
7735 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7736 // This can happen because of dependent hiding.
7737 if (isa<UsingShadowDecl>(*I))
7738 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007739 else {
7740 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007741 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007742 }
John McCall9f54ad42009-12-10 09:41:52 +00007743 }
John McCall129e2df2009-11-30 22:42:35 +00007744
7745 // Expand using declarations.
7746 if (isa<UsingDecl>(InstD)) {
7747 UsingDecl *UD = cast<UsingDecl>(InstD);
7748 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7749 E = UD->shadow_end(); I != E; ++I)
7750 R.addDecl(*I);
7751 continue;
7752 }
7753
7754 R.addDecl(InstD);
7755 }
7756
7757 R.resolveKind();
7758
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007759 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00007760 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00007761 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007762 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00007763 Old->getMemberLoc(),
7764 Old->getNamingClass()));
7765 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007766 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007767
Douglas Gregor66c45152010-04-27 16:10:10 +00007768 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007769 }
Sean Huntc3021132010-05-05 15:23:54 +00007770
John McCall129e2df2009-11-30 22:42:35 +00007771 TemplateArgumentListInfo TransArgs;
7772 if (Old->hasExplicitTemplateArgs()) {
7773 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7774 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007775 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7776 Old->getNumTemplateArgs(),
7777 TransArgs))
7778 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007779 }
John McCallc2233c52010-01-15 08:34:02 +00007780
7781 // FIXME: to do this check properly, we will need to preserve the
7782 // first-qualifier-in-scope here, just in case we had a dependent
7783 // base (and therefore couldn't do the check) and a
7784 // nested-name-qualifier (and therefore could do the lookup).
7785 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00007786
John McCall9ae2f072010-08-23 23:25:46 +00007787 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007788 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00007789 Old->getOperatorLoc(),
7790 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00007791 QualifierLoc,
John McCallc2233c52010-01-15 08:34:02 +00007792 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00007793 R,
7794 (Old->hasExplicitTemplateArgs()
7795 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007796}
7797
7798template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007799ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00007800TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00007801 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00007802 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7803 if (SubExpr.isInvalid())
7804 return ExprError();
7805
7806 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007807 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00007808
7809 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7810}
7811
7812template<typename Derived>
7813ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00007814TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00007815 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7816 if (Pattern.isInvalid())
7817 return ExprError();
7818
7819 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7820 return SemaRef.Owned(E);
7821
Douglas Gregor67fd1252011-01-14 21:20:45 +00007822 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7823 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00007824}
Douglas Gregoree8aff02011-01-04 17:33:58 +00007825
7826template<typename Derived>
7827ExprResult
7828TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7829 // If E is not value-dependent, then nothing will change when we transform it.
7830 // Note: This is an instantiation-centric view.
7831 if (!E->isValueDependent())
7832 return SemaRef.Owned(E);
7833
7834 // Note: None of the implementations of TryExpandParameterPacks can ever
7835 // produce a diagnostic when given only a single unexpanded parameter pack,
7836 // so
7837 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7838 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00007839 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00007840 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00007841 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00007842 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00007843 ShouldExpand, RetainExpansion,
7844 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00007845 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00007846
Douglas Gregor089e8932011-10-10 18:59:29 +00007847 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00007848 return SemaRef.Owned(E);
Douglas Gregor089e8932011-10-10 18:59:29 +00007849
7850 NamedDecl *Pack = E->getPack();
7851 if (!ShouldExpand) {
7852 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
7853 Pack));
7854 if (!Pack)
7855 return ExprError();
7856 }
7857
Douglas Gregoree8aff02011-01-04 17:33:58 +00007858
7859 // We now know the length of the parameter pack, so build a new expression
7860 // that stores that length.
Douglas Gregor089e8932011-10-10 18:59:29 +00007861 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregoree8aff02011-01-04 17:33:58 +00007862 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00007863 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00007864}
7865
Douglas Gregorbe230c32011-01-03 17:17:50 +00007866template<typename Derived>
7867ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00007868TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7869 SubstNonTypeTemplateParmPackExpr *E) {
7870 // Default behavior is to do nothing with this transformation.
7871 return SemaRef.Owned(E);
7872}
7873
7874template<typename Derived>
7875ExprResult
John McCall91a57552011-07-15 05:09:51 +00007876TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
7877 SubstNonTypeTemplateParmExpr *E) {
7878 // Default behavior is to do nothing with this transformation.
7879 return SemaRef.Owned(E);
7880}
7881
7882template<typename Derived>
7883ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00007884TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
7885 MaterializeTemporaryExpr *E) {
7886 return getDerived().TransformExpr(E->GetTemporaryExpr());
7887}
7888
7889template<typename Derived>
7890ExprResult
John McCall454feb92009-12-08 09:21:05 +00007891TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007892 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007893}
7894
Mike Stump1eb44332009-09-09 15:08:12 +00007895template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007896ExprResult
John McCall454feb92009-12-08 09:21:05 +00007897TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00007898 TypeSourceInfo *EncodedTypeInfo
7899 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7900 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007901 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007902
Douglas Gregorb98b1992009-08-11 05:31:07 +00007903 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00007904 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007905 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007906
7907 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00007908 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007909 E->getRParenLoc());
7910}
Mike Stump1eb44332009-09-09 15:08:12 +00007911
Douglas Gregorb98b1992009-08-11 05:31:07 +00007912template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00007913ExprResult TreeTransform<Derived>::
7914TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7915 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7916 if (result.isInvalid()) return ExprError();
7917 Expr *subExpr = result.take();
7918
7919 if (!getDerived().AlwaysRebuild() &&
7920 subExpr == E->getSubExpr())
7921 return SemaRef.Owned(E);
7922
7923 return SemaRef.Owned(new(SemaRef.Context)
7924 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7925}
7926
7927template<typename Derived>
7928ExprResult TreeTransform<Derived>::
7929TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7930 TypeSourceInfo *TSInfo
7931 = getDerived().TransformType(E->getTypeInfoAsWritten());
7932 if (!TSInfo)
7933 return ExprError();
7934
7935 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7936 if (Result.isInvalid())
7937 return ExprError();
7938
7939 if (!getDerived().AlwaysRebuild() &&
7940 TSInfo == E->getTypeInfoAsWritten() &&
7941 Result.get() == E->getSubExpr())
7942 return SemaRef.Owned(E);
7943
7944 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
7945 E->getBridgeKeywordLoc(), TSInfo,
7946 Result.get());
7947}
7948
7949template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007950ExprResult
John McCall454feb92009-12-08 09:21:05 +00007951TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00007952 // Transform arguments.
7953 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007954 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007955 Args.reserve(E->getNumArgs());
7956 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7957 &ArgChanged))
7958 return ExprError();
7959
Douglas Gregor92e986e2010-04-22 16:44:27 +00007960 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7961 // Class message: transform the receiver type.
7962 TypeSourceInfo *ReceiverTypeInfo
7963 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7964 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007965 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007966
Douglas Gregor92e986e2010-04-22 16:44:27 +00007967 // If nothing changed, just retain the existing message send.
7968 if (!getDerived().AlwaysRebuild() &&
7969 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007970 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00007971
7972 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00007973 SmallVector<SourceLocation, 16> SelLocs;
7974 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00007975 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7976 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00007977 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00007978 E->getMethodDecl(),
7979 E->getLeftLoc(),
7980 move_arg(Args),
7981 E->getRightLoc());
7982 }
7983
7984 // Instance message: transform the receiver
7985 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7986 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00007987 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00007988 = getDerived().TransformExpr(E->getInstanceReceiver());
7989 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007990 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00007991
7992 // If nothing changed, just retain the existing message send.
7993 if (!getDerived().AlwaysRebuild() &&
7994 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007995 return SemaRef.MaybeBindToTemporary(E);
Sean Huntc3021132010-05-05 15:23:54 +00007996
Douglas Gregor92e986e2010-04-22 16:44:27 +00007997 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00007998 SmallVector<SourceLocation, 16> SelLocs;
7999 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008000 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008001 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008002 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008003 E->getMethodDecl(),
8004 E->getLeftLoc(),
8005 move_arg(Args),
8006 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008007}
8008
Mike Stump1eb44332009-09-09 15:08:12 +00008009template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008010ExprResult
John McCall454feb92009-12-08 09:21:05 +00008011TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008012 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008013}
8014
Mike Stump1eb44332009-09-09 15:08:12 +00008015template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008016ExprResult
John McCall454feb92009-12-08 09:21:05 +00008017TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008018 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008019}
8020
Mike Stump1eb44332009-09-09 15:08:12 +00008021template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008022ExprResult
John McCall454feb92009-12-08 09:21:05 +00008023TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008024 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008025 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008026 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008027 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008028
8029 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008030
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008031 // If nothing changed, just retain the existing expression.
8032 if (!getDerived().AlwaysRebuild() &&
8033 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008034 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008035
John McCall9ae2f072010-08-23 23:25:46 +00008036 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008037 E->getLocation(),
8038 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008039}
8040
Mike Stump1eb44332009-09-09 15:08:12 +00008041template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008042ExprResult
John McCall454feb92009-12-08 09:21:05 +00008043TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008044 // 'super' and types never change. Property never changes. Just
8045 // retain the existing expression.
8046 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008047 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00008048
Douglas Gregore3303542010-04-26 20:47:02 +00008049 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008050 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008051 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008052 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008053
Douglas Gregore3303542010-04-26 20:47:02 +00008054 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008055
Douglas Gregore3303542010-04-26 20:47:02 +00008056 // If nothing changed, just retain the existing expression.
8057 if (!getDerived().AlwaysRebuild() &&
8058 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008059 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008060
John McCall12f78a62010-12-02 01:19:52 +00008061 if (E->isExplicitProperty())
8062 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8063 E->getExplicitProperty(),
8064 E->getLocation());
8065
8066 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008067 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008068 E->getImplicitPropertyGetter(),
8069 E->getImplicitPropertySetter(),
8070 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008071}
8072
Mike Stump1eb44332009-09-09 15:08:12 +00008073template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008074ExprResult
John McCall454feb92009-12-08 09:21:05 +00008075TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008076 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008077 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008078 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008079 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008080
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008081 // If nothing changed, just retain the existing expression.
8082 if (!getDerived().AlwaysRebuild() &&
8083 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008084 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008085
John McCall9ae2f072010-08-23 23:25:46 +00008086 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008087 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008088}
8089
Mike Stump1eb44332009-09-09 15:08:12 +00008090template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008091ExprResult
John McCall454feb92009-12-08 09:21:05 +00008092TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008093 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008094 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008095 SubExprs.reserve(E->getNumSubExprs());
8096 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8097 SubExprs, &ArgumentChanged))
8098 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008099
Douglas Gregorb98b1992009-08-11 05:31:07 +00008100 if (!getDerived().AlwaysRebuild() &&
8101 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008102 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008103
Douglas Gregorb98b1992009-08-11 05:31:07 +00008104 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8105 move_arg(SubExprs),
8106 E->getRParenLoc());
8107}
8108
Mike Stump1eb44332009-09-09 15:08:12 +00008109template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008110ExprResult
John McCall454feb92009-12-08 09:21:05 +00008111TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008112 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008113
John McCallc6ac9c32011-02-04 18:33:18 +00008114 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8115 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8116
8117 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008118 blockScope->TheDecl->setBlockMissingReturnType(
8119 oldBlock->blockMissingReturnType());
Fariborz Jahanianff365592011-05-05 17:18:12 +00008120
Chris Lattner686775d2011-07-20 06:58:45 +00008121 SmallVector<ParmVarDecl*, 4> params;
8122 SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008123
8124 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008125 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8126 oldBlock->param_begin(),
8127 oldBlock->param_size(),
8128 0, paramTypes, &params))
Douglas Gregor92be2a52011-12-10 00:23:21 +00008129 return ExprError();
John McCallc6ac9c32011-02-04 18:33:18 +00008130
8131 const FunctionType *exprFunctionType = E->getFunctionType();
8132 QualType exprResultType = exprFunctionType->getResultType();
8133 if (!exprResultType.isNull()) {
8134 if (!exprResultType->isDependentType())
8135 blockScope->ReturnType = exprResultType;
8136 else if (exprResultType != getSema().Context.DependentTy)
8137 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008138 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00008139
8140 // If the return type has not been determined yet, leave it as a dependent
8141 // type; it'll get set when we process the body.
John McCallc6ac9c32011-02-04 18:33:18 +00008142 if (blockScope->ReturnType.isNull())
8143 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregora779d9c2011-01-19 21:32:01 +00008144
8145 // Don't allow returning a objc interface by value.
John McCallc6ac9c32011-02-04 18:33:18 +00008146 if (blockScope->ReturnType->isObjCObjectType()) {
8147 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00008148 diag::err_object_cannot_be_passed_returned_by_value)
John McCallc6ac9c32011-02-04 18:33:18 +00008149 << 0 << blockScope->ReturnType;
Douglas Gregora779d9c2011-01-19 21:32:01 +00008150 return ExprError();
8151 }
John McCall711c52b2011-01-05 12:14:39 +00008152
John McCallc6ac9c32011-02-04 18:33:18 +00008153 QualType functionType = getDerived().RebuildFunctionProtoType(
8154 blockScope->ReturnType,
8155 paramTypes.data(),
8156 paramTypes.size(),
8157 oldBlock->isVariadic(),
Douglas Gregorc938c162011-01-26 05:01:58 +00008158 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008159 exprFunctionType->getExtInfo());
8160 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008161
8162 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008163 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008164 blockScope->TheDecl->setParams(params);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008165
8166 // If the return type wasn't explicitly set, it will have been marked as a
8167 // dependent type (DependentTy); clear out the return type setting so
8168 // we will deduce the return type when type-checking the block's body.
John McCallc6ac9c32011-02-04 18:33:18 +00008169 if (blockScope->ReturnType == getSema().Context.DependentTy)
8170 blockScope->ReturnType = QualType();
Douglas Gregora779d9c2011-01-19 21:32:01 +00008171
John McCall711c52b2011-01-05 12:14:39 +00008172 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008173 StmtResult body = getDerived().TransformStmt(E->getBody());
8174 if (body.isInvalid())
John McCall711c52b2011-01-05 12:14:39 +00008175 return ExprError();
8176
John McCallc6ac9c32011-02-04 18:33:18 +00008177#ifndef NDEBUG
8178 // In builds with assertions, make sure that we captured everything we
8179 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008180 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8181 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8182 e = oldBlock->capture_end(); i != e; ++i) {
8183 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008184
Douglas Gregorfc921372011-05-20 15:32:55 +00008185 // Ignore parameter packs.
8186 if (isa<ParmVarDecl>(oldCapture) &&
8187 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8188 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008189
Douglas Gregorfc921372011-05-20 15:32:55 +00008190 VarDecl *newCapture =
8191 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8192 oldCapture));
8193 assert(blockScope->CaptureMap.count(newCapture));
8194 }
John McCallc6ac9c32011-02-04 18:33:18 +00008195 }
8196#endif
8197
8198 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8199 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008200}
8201
Mike Stump1eb44332009-09-09 15:08:12 +00008202template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008203ExprResult
John McCall454feb92009-12-08 09:21:05 +00008204TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008205 ValueDecl *ND
8206 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8207 E->getDecl()));
8208 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00008209 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00008210
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008211 if (!getDerived().AlwaysRebuild() &&
8212 ND == E->getDecl()) {
8213 // Mark it referenced in the new context regardless.
8214 // FIXME: this is a bit instantiation-specific.
8215 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
8216
John McCall3fa5cae2010-10-26 07:05:15 +00008217 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008218 }
8219
Abramo Bagnara25777432010-08-11 22:01:17 +00008220 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregor40d96a62011-02-28 21:54:11 +00008221 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnara25777432010-08-11 22:01:17 +00008222 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008223}
Mike Stump1eb44332009-09-09 15:08:12 +00008224
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008225template<typename Derived>
8226ExprResult
8227TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008228 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008229}
Eli Friedman276b0612011-10-11 02:20:01 +00008230
8231template<typename Derived>
8232ExprResult
8233TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008234 QualType RetTy = getDerived().TransformType(E->getType());
8235 bool ArgumentChanged = false;
8236 ASTOwningVector<Expr*> SubExprs(SemaRef);
8237 SubExprs.reserve(E->getNumSubExprs());
8238 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8239 SubExprs, &ArgumentChanged))
8240 return ExprError();
8241
8242 if (!getDerived().AlwaysRebuild() &&
8243 !ArgumentChanged)
8244 return SemaRef.Owned(E);
8245
8246 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8247 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008248}
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008249
Douglas Gregorb98b1992009-08-11 05:31:07 +00008250//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008251// Type reconstruction
8252//===----------------------------------------------------------------------===//
8253
Mike Stump1eb44332009-09-09 15:08:12 +00008254template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008255QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8256 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008257 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008258 getDerived().getBaseEntity());
8259}
8260
Mike Stump1eb44332009-09-09 15:08:12 +00008261template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008262QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8263 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008264 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008265 getDerived().getBaseEntity());
8266}
8267
Mike Stump1eb44332009-09-09 15:08:12 +00008268template<typename Derived>
8269QualType
John McCall85737a72009-10-30 00:06:24 +00008270TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8271 bool WrittenAsLValue,
8272 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008273 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008274 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008275}
8276
8277template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008278QualType
John McCall85737a72009-10-30 00:06:24 +00008279TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8280 QualType ClassType,
8281 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008282 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008283 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008284}
8285
8286template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008287QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008288TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8289 ArrayType::ArraySizeModifier SizeMod,
8290 const llvm::APInt *Size,
8291 Expr *SizeExpr,
8292 unsigned IndexTypeQuals,
8293 SourceRange BracketsRange) {
8294 if (SizeExpr || !Size)
8295 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8296 IndexTypeQuals, BracketsRange,
8297 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008298
8299 QualType Types[] = {
8300 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8301 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8302 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008303 };
8304 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8305 QualType SizeType;
8306 for (unsigned I = 0; I != NumTypes; ++I)
8307 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8308 SizeType = Types[I];
8309 break;
8310 }
Mike Stump1eb44332009-09-09 15:08:12 +00008311
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008312 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
8313 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00008314 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008315 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008316 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008317}
Mike Stump1eb44332009-09-09 15:08:12 +00008318
Douglas Gregor577f75a2009-08-04 16:50:30 +00008319template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008320QualType
8321TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008322 ArrayType::ArraySizeModifier SizeMod,
8323 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008324 unsigned IndexTypeQuals,
8325 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008326 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008327 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008328}
8329
8330template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008331QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008332TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008333 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008334 unsigned IndexTypeQuals,
8335 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008336 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008337 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008338}
Mike Stump1eb44332009-09-09 15:08:12 +00008339
Douglas Gregor577f75a2009-08-04 16:50:30 +00008340template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008341QualType
8342TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008343 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008344 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008345 unsigned IndexTypeQuals,
8346 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008347 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008348 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008349 IndexTypeQuals, BracketsRange);
8350}
8351
8352template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008353QualType
8354TreeTransform<Derived>::RebuildDependentSizedArrayType(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>
8365QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008366 unsigned NumElements,
8367 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008368 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008369 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008370}
Mike Stump1eb44332009-09-09 15:08:12 +00008371
Douglas Gregor577f75a2009-08-04 16:50:30 +00008372template<typename Derived>
8373QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8374 unsigned NumElements,
8375 SourceLocation AttributeLoc) {
8376 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8377 NumElements, true);
8378 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008379 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8380 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008381 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
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>
Mike Stump1eb44332009-09-09 15:08:12 +00008385QualType
8386TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008387 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008388 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008389 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008390}
Mike Stump1eb44332009-09-09 15:08:12 +00008391
Douglas Gregor577f75a2009-08-04 16:50:30 +00008392template<typename Derived>
8393QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00008394 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008395 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00008396 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00008397 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00008398 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00008399 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00008400 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregorc938c162011-01-26 05:01:58 +00008401 Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008402 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00008403 getDerived().getBaseEntity(),
8404 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008405}
Mike Stump1eb44332009-09-09 15:08:12 +00008406
Douglas Gregor577f75a2009-08-04 16:50:30 +00008407template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00008408QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8409 return SemaRef.Context.getFunctionNoProtoType(T);
8410}
8411
8412template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00008413QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8414 assert(D && "no decl found");
8415 if (D->isInvalidDecl()) return QualType();
8416
Douglas Gregor92e986e2010-04-22 16:44:27 +00008417 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00008418 TypeDecl *Ty;
8419 if (isa<UsingDecl>(D)) {
8420 UsingDecl *Using = cast<UsingDecl>(D);
8421 assert(Using->isTypeName() &&
8422 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8423
8424 // A valid resolved using typename decl points to exactly one type decl.
8425 assert(++Using->shadow_begin() == Using->shadow_end());
8426 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00008427
John McCalled976492009-12-04 22:46:56 +00008428 } else {
8429 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8430 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8431 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8432 }
8433
8434 return SemaRef.Context.getTypeDeclType(Ty);
8435}
8436
8437template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008438QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8439 SourceLocation Loc) {
8440 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008441}
8442
8443template<typename Derived>
8444QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8445 return SemaRef.Context.getTypeOfType(Underlying);
8446}
8447
8448template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008449QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8450 SourceLocation Loc) {
8451 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008452}
8453
8454template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00008455QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8456 UnaryTransformType::UTTKind UKind,
8457 SourceLocation Loc) {
8458 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8459}
8460
8461template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00008462QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00008463 TemplateName Template,
8464 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00008465 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00008466 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008467}
Mike Stump1eb44332009-09-09 15:08:12 +00008468
Douglas Gregordcee1a12009-08-06 05:28:30 +00008469template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00008470QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
8471 SourceLocation KWLoc) {
8472 return SemaRef.BuildAtomicType(ValueType, KWLoc);
8473}
8474
8475template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008476TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008477TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00008478 bool TemplateKW,
8479 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008480 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00008481 Template);
8482}
8483
8484template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008485TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008486TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8487 const IdentifierInfo &Name,
8488 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00008489 QualType ObjectType,
8490 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008491 UnqualifiedId TemplateName;
8492 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008493 Sema::TemplateTy Template;
8494 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008495 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008496 SS,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008497 TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00008498 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008499 /*EnteringContext=*/false,
8500 Template);
John McCall43fed0d2010-11-12 08:19:04 +00008501 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00008502}
Mike Stump1eb44332009-09-09 15:08:12 +00008503
Douglas Gregorb98b1992009-08-11 05:31:07 +00008504template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008505TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008506TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008507 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008508 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008509 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008510 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008511 // FIXME: Bogus location information.
8512 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8513 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008514 Sema::TemplateTy Template;
8515 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008516 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008517 SS,
8518 Name,
John McCallb3d87482010-08-24 05:47:05 +00008519 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008520 /*EnteringContext=*/false,
8521 Template);
8522 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008523}
Sean Huntc3021132010-05-05 15:23:54 +00008524
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008525template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008526ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008527TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8528 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00008529 Expr *OrigCallee,
8530 Expr *First,
8531 Expr *Second) {
8532 Expr *Callee = OrigCallee->IgnoreParenCasts();
8533 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00008534
Douglas Gregorb98b1992009-08-11 05:31:07 +00008535 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00008536 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00008537 if (!First->getType()->isOverloadableType() &&
8538 !Second->getType()->isOverloadableType())
8539 return getSema().CreateBuiltinArraySubscriptExpr(First,
8540 Callee->getLocStart(),
8541 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00008542 } else if (Op == OO_Arrow) {
8543 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00008544 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8545 } else if (Second == 0 || isPostIncDec) {
8546 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008547 // The argument is not of overloadable type, so try to create a
8548 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00008549 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008550 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00008551
John McCall9ae2f072010-08-23 23:25:46 +00008552 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008553 }
8554 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008555 if (!First->getType()->isOverloadableType() &&
8556 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008557 // Neither of the arguments is an overloadable type, so try to
8558 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00008559 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008560 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00008561 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008562 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008563 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008564
Douglas Gregorb98b1992009-08-11 05:31:07 +00008565 return move(Result);
8566 }
8567 }
Mike Stump1eb44332009-09-09 15:08:12 +00008568
8569 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00008570 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00008571 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00008572
John McCall9ae2f072010-08-23 23:25:46 +00008573 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00008574 assert(ULE->requiresADL());
8575
8576 // FIXME: Do we have to check
8577 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00008578 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00008579 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008580 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00008581 }
Mike Stump1eb44332009-09-09 15:08:12 +00008582
Douglas Gregorb98b1992009-08-11 05:31:07 +00008583 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00008584 Expr *Args[2] = { First, Second };
8585 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00008586
Douglas Gregorb98b1992009-08-11 05:31:07 +00008587 // Create the overloaded operator invocation for unary operators.
8588 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00008589 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008590 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00008591 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008592 }
Mike Stump1eb44332009-09-09 15:08:12 +00008593
Douglas Gregor5b8968c2011-07-15 16:25:15 +00008594 if (Op == OO_Subscript) {
8595 SourceLocation LBrace;
8596 SourceLocation RBrace;
8597
8598 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
8599 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
8600 LBrace = SourceLocation::getFromRawEncoding(
8601 NameLoc.CXXOperatorName.BeginOpNameLoc);
8602 RBrace = SourceLocation::getFromRawEncoding(
8603 NameLoc.CXXOperatorName.EndOpNameLoc);
8604 } else {
8605 LBrace = Callee->getLocStart();
8606 RBrace = OpLoc;
8607 }
8608
8609 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
8610 First, Second);
8611 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00008612
Douglas Gregorb98b1992009-08-11 05:31:07 +00008613 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00008614 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008615 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00008616 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8617 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008618 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008619
Mike Stump1eb44332009-09-09 15:08:12 +00008620 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008621}
Mike Stump1eb44332009-09-09 15:08:12 +00008622
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008623template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008624ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00008625TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008626 SourceLocation OperatorLoc,
8627 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00008628 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008629 TypeSourceInfo *ScopeType,
8630 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008631 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008632 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00008633 QualType BaseType = Base->getType();
8634 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008635 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00008636 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00008637 !BaseType->getAs<PointerType>()->getPointeeType()
8638 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008639 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00008640 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008641 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008642 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008643 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008644 /*FIXME?*/true);
8645 }
Abramo Bagnara25777432010-08-11 22:01:17 +00008646
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008647 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00008648 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8649 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8650 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8651 NameInfo.setNamedTypeInfo(DestroyedType);
8652
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008653 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00008654
John McCall9ae2f072010-08-23 23:25:46 +00008655 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008656 OperatorLoc, isArrow,
8657 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00008658 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008659 /*TemplateArgs*/ 0);
8660}
8661
Douglas Gregor577f75a2009-08-04 16:50:30 +00008662} // end namespace clang
8663
8664#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H