blob: 6bbb8316e59c269980c010d1dcf705042a389593 [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,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000421 SourceLocation NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000422 QualType ObjectType = QualType(),
423 NamedDecl *FirstQualifierInScope = 0);
424
Douglas Gregor577f75a2009-08-04 16:50:30 +0000425 /// \brief Transform the given template argument.
426 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000427 /// By default, this operation transforms the type, expression, or
428 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000429 /// new template argument from the transformed result. Subclasses may
430 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000431 ///
432 /// Returns true if there was an error.
433 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
434 TemplateArgumentLoc &Output);
435
Douglas Gregorfcc12532010-12-20 17:31:10 +0000436 /// \brief Transform the given set of template arguments.
437 ///
438 /// By default, this operation transforms all of the template arguments
439 /// in the input set using \c TransformTemplateArgument(), and appends
440 /// the transformed arguments to the output list.
441 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000442 /// Note that this overload of \c TransformTemplateArguments() is merely
443 /// a convenience function. Subclasses that wish to override this behavior
444 /// should override the iterator-based member template version.
445 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000446 /// \param Inputs The set of template arguments to be transformed.
447 ///
448 /// \param NumInputs The number of template arguments in \p Inputs.
449 ///
450 /// \param Outputs The set of transformed template arguments output by this
451 /// routine.
452 ///
453 /// Returns true if an error occurred.
454 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
455 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000456 TemplateArgumentListInfo &Outputs) {
457 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
458 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000459
460 /// \brief Transform the given set of template arguments.
461 ///
462 /// By default, this operation transforms all of the template arguments
463 /// in the input set using \c TransformTemplateArgument(), and appends
464 /// the transformed arguments to the output list.
465 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000466 /// \param First An iterator to the first template argument.
467 ///
468 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000469 ///
470 /// \param Outputs The set of transformed template arguments output by this
471 /// routine.
472 ///
473 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000474 template<typename InputIterator>
475 bool TransformTemplateArguments(InputIterator First,
476 InputIterator Last,
477 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000478
John McCall833ca992009-10-29 08:12:44 +0000479 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
480 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
481 TemplateArgumentLoc &ArgLoc);
482
John McCalla93c9342009-12-07 02:54:59 +0000483 /// \brief Fakes up a TypeSourceInfo for a type.
484 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
485 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000486 getDerived().getBaseLocation());
487 }
Mike Stump1eb44332009-09-09 15:08:12 +0000488
John McCalla2becad2009-10-21 00:40:46 +0000489#define ABSTRACT_TYPELOC(CLASS, PARENT)
490#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000491 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000492#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000493
John Wiegley28bbe4b2011-04-28 01:08:34 +0000494 StmtResult
495 TransformSEHHandler(Stmt *Handler);
496
John McCall43fed0d2010-11-12 08:19:04 +0000497 QualType
498 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
499 TemplateSpecializationTypeLoc TL,
500 TemplateName Template);
501
502 QualType
503 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
504 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000505 TemplateName Template,
506 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000507
508 QualType
509 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000510 DependentTemplateSpecializationTypeLoc TL,
511 NestedNameSpecifierLoc QualifierLoc);
512
John McCall21ef0fa2010-03-11 09:03:00 +0000513 /// \brief Transforms the parameters of a function type into the
514 /// given vectors.
515 ///
516 /// The result vectors should be kept in sync; null entries in the
517 /// variables vector are acceptable.
518 ///
519 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000520 bool TransformFunctionTypeParams(SourceLocation Loc,
521 ParmVarDecl **Params, unsigned NumParams,
522 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000523 SmallVectorImpl<QualType> &PTypes,
524 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000525
526 /// \brief Transforms a single function-type parameter. Return null
527 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000528 ///
529 /// \param indexAdjustment - A number to add to the parameter's
530 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000531 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000532 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000533 llvm::Optional<unsigned> NumExpansions,
534 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000535
John McCall43fed0d2010-11-12 08:19:04 +0000536 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000537
John McCall60d7b3a2010-08-24 06:29:42 +0000538 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
539 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000540
Douglas Gregor43959a92009-08-20 07:17:43 +0000541#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000542 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000543#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000544 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000545#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000546#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000547
Douglas Gregor577f75a2009-08-04 16:50:30 +0000548 /// \brief Build a new pointer type given its pointee type.
549 ///
550 /// By default, performs semantic analysis when building the pointer type.
551 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000552 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000553
554 /// \brief Build a new block pointer type given its pointee type.
555 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000556 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000557 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000558 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000559
John McCall85737a72009-10-30 00:06:24 +0000560 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000561 ///
John McCall85737a72009-10-30 00:06:24 +0000562 /// By default, performs semantic analysis when building the
563 /// reference type. Subclasses may override this routine to provide
564 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000565 ///
John McCall85737a72009-10-30 00:06:24 +0000566 /// \param LValue whether the type was written with an lvalue sigil
567 /// or an rvalue sigil.
568 QualType RebuildReferenceType(QualType ReferentType,
569 bool LValue,
570 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000571
Douglas Gregor577f75a2009-08-04 16:50:30 +0000572 /// \brief Build a new member pointer type given the pointee type and the
573 /// class type it refers into.
574 ///
575 /// By default, performs semantic analysis when building the member pointer
576 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000577 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
578 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000579
Douglas Gregor577f75a2009-08-04 16:50:30 +0000580 /// \brief Build a new array type given the element type, size
581 /// modifier, size of the array (if known), size expression, and index type
582 /// qualifiers.
583 ///
584 /// By default, performs semantic analysis when building the array type.
585 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000586 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000587 QualType RebuildArrayType(QualType ElementType,
588 ArrayType::ArraySizeModifier SizeMod,
589 const llvm::APInt *Size,
590 Expr *SizeExpr,
591 unsigned IndexTypeQuals,
592 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000593
Douglas Gregor577f75a2009-08-04 16:50:30 +0000594 /// \brief Build a new constant array type given the element type, size
595 /// modifier, (known) size of the array, and index type qualifiers.
596 ///
597 /// By default, performs semantic analysis when building the array type.
598 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000599 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000600 ArrayType::ArraySizeModifier SizeMod,
601 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000602 unsigned IndexTypeQuals,
603 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000604
Douglas Gregor577f75a2009-08-04 16:50:30 +0000605 /// \brief Build a new incomplete array type given the element type, size
606 /// modifier, and index type qualifiers.
607 ///
608 /// By default, performs semantic analysis when building the array type.
609 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000610 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000611 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000612 unsigned IndexTypeQuals,
613 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000614
Mike Stump1eb44332009-09-09 15:08:12 +0000615 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000616 /// size modifier, size expression, and index type qualifiers.
617 ///
618 /// By default, performs semantic analysis when building the array type.
619 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000620 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000621 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000622 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000623 unsigned IndexTypeQuals,
624 SourceRange BracketsRange);
625
Mike Stump1eb44332009-09-09 15:08:12 +0000626 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000627 /// size modifier, size expression, and index type qualifiers.
628 ///
629 /// By default, performs semantic analysis when building the array type.
630 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000631 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000632 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000633 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000634 unsigned IndexTypeQuals,
635 SourceRange BracketsRange);
636
637 /// \brief Build a new vector type given the element type and
638 /// number of elements.
639 ///
640 /// By default, performs semantic analysis when building the vector type.
641 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000642 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000643 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000644
Douglas Gregor577f75a2009-08-04 16:50:30 +0000645 /// \brief Build a new extended vector type given the element type and
646 /// number of elements.
647 ///
648 /// By default, performs semantic analysis when building the vector type.
649 /// Subclasses may override this routine to provide different behavior.
650 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
651 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000652
653 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000654 /// given the element type and number of elements.
655 ///
656 /// By default, performs semantic analysis when building the vector type.
657 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000658 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000659 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000660 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000661
Douglas Gregor577f75a2009-08-04 16:50:30 +0000662 /// \brief Build a new function type.
663 ///
664 /// By default, performs semantic analysis when building the function type.
665 /// Subclasses may override this routine to provide different behavior.
666 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000667 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000668 unsigned NumParamTypes,
Eli Friedmanfa869542010-08-05 02:54:05 +0000669 bool Variadic, unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000670 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000671 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000672
John McCalla2becad2009-10-21 00:40:46 +0000673 /// \brief Build a new unprototyped function type.
674 QualType RebuildFunctionNoProtoType(QualType ResultType);
675
John McCalled976492009-12-04 22:46:56 +0000676 /// \brief Rebuild an unresolved typename type, given the decl that
677 /// the UnresolvedUsingTypenameDecl was transformed to.
678 QualType RebuildUnresolvedUsingType(Decl *D);
679
Douglas Gregor577f75a2009-08-04 16:50:30 +0000680 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000681 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000682 return SemaRef.Context.getTypeDeclType(Typedef);
683 }
684
685 /// \brief Build a new class/struct/union type.
686 QualType RebuildRecordType(RecordDecl *Record) {
687 return SemaRef.Context.getTypeDeclType(Record);
688 }
689
690 /// \brief Build a new Enum type.
691 QualType RebuildEnumType(EnumDecl *Enum) {
692 return SemaRef.Context.getTypeDeclType(Enum);
693 }
John McCall7da24312009-09-05 00:15:47 +0000694
Mike Stump1eb44332009-09-09 15:08:12 +0000695 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000696 ///
697 /// By default, performs semantic analysis when building the typeof type.
698 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000699 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000700
Mike Stump1eb44332009-09-09 15:08:12 +0000701 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000702 ///
703 /// By default, builds a new TypeOfType with the given underlying type.
704 QualType RebuildTypeOfType(QualType Underlying);
705
Sean Huntca63c202011-05-24 22:41:36 +0000706 /// \brief Build a new unary transform type.
707 QualType RebuildUnaryTransformType(QualType BaseType,
708 UnaryTransformType::UTTKind UKind,
709 SourceLocation Loc);
710
Mike Stump1eb44332009-09-09 15:08:12 +0000711 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000712 ///
713 /// By default, performs semantic analysis when building the decltype type.
714 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000715 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000716
Richard Smith34b41d92011-02-20 03:19:35 +0000717 /// \brief Build a new C++0x auto type.
718 ///
719 /// By default, builds a new AutoType with the given deduced type.
720 QualType RebuildAutoType(QualType Deduced) {
721 return SemaRef.Context.getAutoType(Deduced);
722 }
723
Douglas Gregor577f75a2009-08-04 16:50:30 +0000724 /// \brief Build a new template specialization type.
725 ///
726 /// By default, performs semantic analysis when building the template
727 /// specialization type. Subclasses may override this routine to provide
728 /// different behavior.
729 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000730 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000731 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000732
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000733 /// \brief Build a new parenthesized type.
734 ///
735 /// By default, builds a new ParenType type from the inner type.
736 /// Subclasses may override this routine to provide different behavior.
737 QualType RebuildParenType(QualType InnerType) {
738 return SemaRef.Context.getParenType(InnerType);
739 }
740
Douglas Gregor577f75a2009-08-04 16:50:30 +0000741 /// \brief Build a new qualified name type.
742 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000743 /// By default, builds a new ElaboratedType type from the keyword,
744 /// the nested-name-specifier and the named type.
745 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000746 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
747 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000748 NestedNameSpecifierLoc QualifierLoc,
749 QualType Named) {
750 return SemaRef.Context.getElaboratedType(Keyword,
751 QualifierLoc.getNestedNameSpecifier(),
752 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000753 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000754
755 /// \brief Build a new typename type that refers to a template-id.
756 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000757 /// By default, builds a new DependentNameType type from the
758 /// nested-name-specifier and the given type. Subclasses may override
759 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000760 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000761 ElaboratedTypeKeyword Keyword,
762 NestedNameSpecifierLoc QualifierLoc,
763 const IdentifierInfo *Name,
764 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000765 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000766 // Rebuild the template name.
767 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000768 CXXScopeSpec SS;
769 SS.Adopt(QualifierLoc);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000770 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000771 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000772
773 if (InstName.isNull())
774 return QualType();
775
776 // If it's still dependent, make a dependent specialization.
777 if (InstName.getAsDependentTemplateName())
778 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
779 QualifierLoc.getNestedNameSpecifier(),
780 Name,
781 Args);
782
783 // Otherwise, make an elaborated type wrapping a non-dependent
784 // specialization.
785 QualType T =
786 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
787 if (T.isNull()) return QualType();
788
789 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
790 return T;
791
792 return SemaRef.Context.getElaboratedType(Keyword,
793 QualifierLoc.getNestedNameSpecifier(),
794 T);
795 }
796
Douglas Gregor577f75a2009-08-04 16:50:30 +0000797 /// \brief Build a new typename type that refers to an identifier.
798 ///
799 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000800 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000801 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000802 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000803 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000804 NestedNameSpecifierLoc QualifierLoc,
805 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000806 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000807 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000808 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000809
Douglas Gregor2494dd02011-03-01 01:34:45 +0000810 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000811 // If the name is still dependent, just build a new dependent name type.
812 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor2494dd02011-03-01 01:34:45 +0000813 return SemaRef.Context.getDependentNameType(Keyword,
814 QualifierLoc.getNestedNameSpecifier(),
815 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000816 }
817
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000818 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000819 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000820 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000821
822 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
823
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000824 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000825 // into a non-dependent elaborated-type-specifier. Find the tag we're
826 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000827 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000828 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
829 if (!DC)
830 return QualType();
831
John McCall56138762010-05-27 06:40:31 +0000832 if (SemaRef.RequireCompleteDeclContext(SS, DC))
833 return QualType();
834
Douglas Gregor40336422010-03-31 22:19:08 +0000835 TagDecl *Tag = 0;
836 SemaRef.LookupQualifiedName(Result, DC);
837 switch (Result.getResultKind()) {
838 case LookupResult::NotFound:
839 case LookupResult::NotFoundInCurrentInstantiation:
840 break;
Sean Huntc3021132010-05-05 15:23:54 +0000841
Douglas Gregor40336422010-03-31 22:19:08 +0000842 case LookupResult::Found:
843 Tag = Result.getAsSingle<TagDecl>();
844 break;
Sean Huntc3021132010-05-05 15:23:54 +0000845
Douglas Gregor40336422010-03-31 22:19:08 +0000846 case LookupResult::FoundOverloaded:
847 case LookupResult::FoundUnresolvedValue:
848 llvm_unreachable("Tag lookup cannot find non-tags");
849 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000850
Douglas Gregor40336422010-03-31 22:19:08 +0000851 case LookupResult::Ambiguous:
852 // Let the LookupResult structure handle ambiguities.
853 return QualType();
854 }
855
856 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000857 // Check where the name exists but isn't a tag type and use that to emit
858 // better diagnostics.
859 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
860 SemaRef.LookupQualifiedName(Result, DC);
861 switch (Result.getResultKind()) {
862 case LookupResult::Found:
863 case LookupResult::FoundOverloaded:
864 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000865 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000866 unsigned Kind = 0;
867 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000868 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
869 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000870 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
871 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
872 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000873 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000874 default:
875 // FIXME: Would be nice to highlight just the source range.
876 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
877 << Kind << Id << DC;
878 break;
879 }
Douglas Gregor40336422010-03-31 22:19:08 +0000880 return QualType();
881 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000882
Richard Trieubbf34c02011-06-10 03:11:26 +0000883 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
884 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000885 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000886 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
887 return QualType();
888 }
889
890 // Build the elaborated-type-specifier type.
891 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor2494dd02011-03-01 01:34:45 +0000892 return SemaRef.Context.getElaboratedType(Keyword,
893 QualifierLoc.getNestedNameSpecifier(),
894 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000895 }
Mike Stump1eb44332009-09-09 15:08:12 +0000896
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000897 /// \brief Build a new pack expansion type.
898 ///
899 /// By default, builds a new PackExpansionType type from the given pattern.
900 /// Subclasses may override this routine to provide different behavior.
901 QualType RebuildPackExpansionType(QualType Pattern,
902 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000903 SourceLocation EllipsisLoc,
904 llvm::Optional<unsigned> NumExpansions) {
905 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
906 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000907 }
908
Eli Friedmanb001de72011-10-06 23:00:33 +0000909 /// \brief Build a new atomic type given its value type.
910 ///
911 /// By default, performs semantic analysis when building the atomic type.
912 /// Subclasses may override this routine to provide different behavior.
913 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
914
Douglas Gregord1067e52009-08-06 06:41:21 +0000915 /// \brief Build a new template name given a nested name specifier, a flag
916 /// indicating whether the "template" keyword was provided, and the template
917 /// that the template name refers to.
918 ///
919 /// By default, builds the new template name directly. Subclasses may override
920 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000921 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000922 bool TemplateKW,
923 TemplateDecl *Template);
924
Douglas Gregord1067e52009-08-06 06:41:21 +0000925 /// \brief Build a new template name given a nested name specifier and the
926 /// name that is referred to as a template.
927 ///
928 /// By default, performs semantic analysis to determine whether the name can
929 /// be resolved to a specific template, then builds the appropriate kind of
930 /// template name. Subclasses may override this routine to provide different
931 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000932 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
933 const IdentifierInfo &Name,
934 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000935 QualType ObjectType,
936 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000937
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000938 /// \brief Build a new template name given a nested name specifier and the
939 /// overloaded operator name that is referred to as a template.
940 ///
941 /// By default, performs semantic analysis to determine whether the name can
942 /// be resolved to a specific template, then builds the appropriate kind of
943 /// template name. Subclasses may override this routine to provide different
944 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000945 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000946 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000947 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000948 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000949
950 /// \brief Build a new template name given a template template parameter pack
951 /// and the
952 ///
953 /// By default, performs semantic analysis to determine whether the name can
954 /// be resolved to a specific template, then builds the appropriate kind of
955 /// template name. Subclasses may override this routine to provide different
956 /// behavior.
957 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
958 const TemplateArgument &ArgPack) {
959 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
960 }
961
Douglas Gregor43959a92009-08-20 07:17:43 +0000962 /// \brief Build a new compound statement.
963 ///
964 /// By default, performs semantic analysis to build the new statement.
965 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000966 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000967 MultiStmtArg Statements,
968 SourceLocation RBraceLoc,
969 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000970 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +0000971 IsStmtExpr);
972 }
973
974 /// \brief Build a new case statement.
975 ///
976 /// By default, performs semantic analysis to build the new statement.
977 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000978 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000979 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000980 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000981 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000982 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000983 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000984 ColonLoc);
985 }
Mike Stump1eb44332009-09-09 15:08:12 +0000986
Douglas Gregor43959a92009-08-20 07:17:43 +0000987 /// \brief Attach the body to a new case statement.
988 ///
989 /// By default, performs semantic analysis to build the new statement.
990 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000991 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000992 getSema().ActOnCaseStmtBody(S, Body);
993 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000994 }
Mike Stump1eb44332009-09-09 15:08:12 +0000995
Douglas Gregor43959a92009-08-20 07:17:43 +0000996 /// \brief Build a new default statement.
997 ///
998 /// By default, performs semantic analysis to build the new statement.
999 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001000 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001001 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001002 Stmt *SubStmt) {
1003 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001004 /*CurScope=*/0);
1005 }
Mike Stump1eb44332009-09-09 15:08:12 +00001006
Douglas Gregor43959a92009-08-20 07:17:43 +00001007 /// \brief Build a new label statement.
1008 ///
1009 /// By default, performs semantic analysis to build the new statement.
1010 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001011 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1012 SourceLocation ColonLoc, Stmt *SubStmt) {
1013 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001014 }
Mike Stump1eb44332009-09-09 15:08:12 +00001015
Douglas Gregor43959a92009-08-20 07:17:43 +00001016 /// \brief Build a new "if" statement.
1017 ///
1018 /// By default, performs semantic analysis to build the new statement.
1019 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001020 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattner57ad3782011-02-17 20:34:02 +00001021 VarDecl *CondVar, Stmt *Then,
1022 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001023 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001024 }
Mike Stump1eb44332009-09-09 15:08:12 +00001025
Douglas Gregor43959a92009-08-20 07:17:43 +00001026 /// \brief Start building a new switch statement.
1027 ///
1028 /// By default, performs semantic analysis to build the new statement.
1029 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001030 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001031 Expr *Cond, VarDecl *CondVar) {
John McCall9ae2f072010-08-23 23:25:46 +00001032 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001033 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001034 }
Mike Stump1eb44332009-09-09 15:08:12 +00001035
Douglas Gregor43959a92009-08-20 07:17:43 +00001036 /// \brief Attach the body to the switch statement.
1037 ///
1038 /// By default, performs semantic analysis to build the new statement.
1039 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001040 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001041 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001042 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001043 }
1044
1045 /// \brief Build a new while statement.
1046 ///
1047 /// By default, performs semantic analysis to build the new statement.
1048 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001049 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1050 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001051 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001052 }
Mike Stump1eb44332009-09-09 15:08:12 +00001053
Douglas Gregor43959a92009-08-20 07:17:43 +00001054 /// \brief Build a new do-while statement.
1055 ///
1056 /// By default, performs semantic analysis to build the new statement.
1057 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001058 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001059 SourceLocation WhileLoc, SourceLocation LParenLoc,
1060 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001061 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1062 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001063 }
1064
1065 /// \brief Build a new for statement.
1066 ///
1067 /// By default, performs semantic analysis to build the new statement.
1068 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001069 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1070 Stmt *Init, Sema::FullExprArg Cond,
1071 VarDecl *CondVar, Sema::FullExprArg Inc,
1072 SourceLocation RParenLoc, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001073 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001074 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001075 }
Mike Stump1eb44332009-09-09 15:08:12 +00001076
Douglas Gregor43959a92009-08-20 07:17:43 +00001077 /// \brief Build a new goto statement.
1078 ///
1079 /// By default, performs semantic analysis to build the new statement.
1080 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001081 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1082 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001083 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001084 }
1085
1086 /// \brief Build a new indirect goto statement.
1087 ///
1088 /// By default, performs semantic analysis to build the new statement.
1089 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001090 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001091 SourceLocation StarLoc,
1092 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001093 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001094 }
Mike Stump1eb44332009-09-09 15:08:12 +00001095
Douglas Gregor43959a92009-08-20 07:17:43 +00001096 /// \brief Build a new return statement.
1097 ///
1098 /// By default, performs semantic analysis to build the new statement.
1099 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001100 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001101 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001102 }
Mike Stump1eb44332009-09-09 15:08:12 +00001103
Douglas Gregor43959a92009-08-20 07:17:43 +00001104 /// \brief Build a new declaration statement.
1105 ///
1106 /// By default, performs semantic analysis to build the new statement.
1107 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001108 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001109 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001110 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001111 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1112 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001113 }
Mike Stump1eb44332009-09-09 15:08:12 +00001114
Anders Carlsson703e3942010-01-24 05:50:09 +00001115 /// \brief Build a new inline asm statement.
1116 ///
1117 /// By default, performs semantic analysis to build the new statement.
1118 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001119 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001120 bool IsSimple,
1121 bool IsVolatile,
1122 unsigned NumOutputs,
1123 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001124 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001125 MultiExprArg Constraints,
1126 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001127 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001128 MultiExprArg Clobbers,
1129 SourceLocation RParenLoc,
1130 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001131 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001132 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001133 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001134 RParenLoc, MSAsm);
1135 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001136
1137 /// \brief Build a new Objective-C @try statement.
1138 ///
1139 /// By default, performs semantic analysis to build the new statement.
1140 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001141 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001142 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001143 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001144 Stmt *Finally) {
1145 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1146 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001147 }
1148
Douglas Gregorbe270a02010-04-26 17:57:08 +00001149 /// \brief Rebuild an Objective-C exception declaration.
1150 ///
1151 /// By default, performs semantic analysis to build the new declaration.
1152 /// Subclasses may override this routine to provide different behavior.
1153 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1154 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001155 return getSema().BuildObjCExceptionDecl(TInfo, T,
1156 ExceptionDecl->getInnerLocStart(),
1157 ExceptionDecl->getLocation(),
1158 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001159 }
Sean Huntc3021132010-05-05 15:23:54 +00001160
Douglas Gregorbe270a02010-04-26 17:57:08 +00001161 /// \brief Build a new Objective-C @catch statement.
1162 ///
1163 /// By default, performs semantic analysis to build the new statement.
1164 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001165 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001166 SourceLocation RParenLoc,
1167 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001168 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001169 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001170 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001171 }
Sean Huntc3021132010-05-05 15:23:54 +00001172
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001173 /// \brief Build a new Objective-C @finally statement.
1174 ///
1175 /// By default, performs semantic analysis to build the new statement.
1176 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001177 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001178 Stmt *Body) {
1179 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001180 }
Sean Huntc3021132010-05-05 15:23:54 +00001181
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001182 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001183 ///
1184 /// By default, performs semantic analysis to build the new statement.
1185 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001186 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001187 Expr *Operand) {
1188 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001189 }
Sean Huntc3021132010-05-05 15:23:54 +00001190
John McCall07524032011-07-27 21:50:02 +00001191 /// \brief Rebuild the operand to an Objective-C @synchronized statement.
1192 ///
1193 /// By default, performs semantic analysis to build the new statement.
1194 /// Subclasses may override this routine to provide different behavior.
1195 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1196 Expr *object) {
1197 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1198 }
1199
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001200 /// \brief Build a new Objective-C @synchronized statement.
1201 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001202 /// By default, performs semantic analysis to build the new statement.
1203 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001204 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001205 Expr *Object, Stmt *Body) {
1206 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001207 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001208
John McCallf85e1932011-06-15 23:02:42 +00001209 /// \brief Build a new Objective-C @autoreleasepool statement.
1210 ///
1211 /// By default, performs semantic analysis to build the new statement.
1212 /// Subclasses may override this routine to provide different behavior.
1213 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1214 Stmt *Body) {
1215 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1216 }
John McCall990567c2011-07-27 01:07:15 +00001217
1218 /// \brief Build the collection operand to a new Objective-C fast
1219 /// enumeration statement.
1220 ///
1221 /// By default, performs semantic analysis to build the new statement.
1222 /// Subclasses may override this routine to provide different behavior.
1223 ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc,
1224 Expr *collection) {
1225 return getSema().ActOnObjCForCollectionOperand(forLoc, collection);
1226 }
John McCallf85e1932011-06-15 23:02:42 +00001227
Douglas Gregorc3203e72010-04-22 23:10:45 +00001228 /// \brief Build a new Objective-C fast enumeration statement.
1229 ///
1230 /// By default, performs semantic analysis to build the new statement.
1231 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001232 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001233 SourceLocation LParenLoc,
1234 Stmt *Element,
1235 Expr *Collection,
1236 SourceLocation RParenLoc,
1237 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001238 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001239 Element,
1240 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001241 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001242 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001243 }
Sean Huntc3021132010-05-05 15:23:54 +00001244
Douglas Gregor43959a92009-08-20 07:17:43 +00001245 /// \brief Build a new C++ exception declaration.
1246 ///
1247 /// By default, performs semantic analysis to build the new decaration.
1248 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001249 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001250 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001251 SourceLocation StartLoc,
1252 SourceLocation IdLoc,
1253 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001254 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1255 StartLoc, IdLoc, Id);
1256 if (Var)
1257 getSema().CurContext->addDecl(Var);
1258 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001259 }
1260
1261 /// \brief Build a new C++ catch statement.
1262 ///
1263 /// By default, performs semantic analysis to build the new statement.
1264 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001265 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001266 VarDecl *ExceptionDecl,
1267 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001268 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1269 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001270 }
Mike Stump1eb44332009-09-09 15:08:12 +00001271
Douglas Gregor43959a92009-08-20 07:17:43 +00001272 /// \brief Build a new C++ try statement.
1273 ///
1274 /// By default, performs semantic analysis to build the new statement.
1275 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001276 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001277 Stmt *TryBlock,
1278 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001279 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001280 }
Mike Stump1eb44332009-09-09 15:08:12 +00001281
Richard Smithad762fc2011-04-14 22:09:26 +00001282 /// \brief Build a new C++0x range-based for statement.
1283 ///
1284 /// By default, performs semantic analysis to build the new statement.
1285 /// Subclasses may override this routine to provide different behavior.
1286 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1287 SourceLocation ColonLoc,
1288 Stmt *Range, Stmt *BeginEnd,
1289 Expr *Cond, Expr *Inc,
1290 Stmt *LoopVar,
1291 SourceLocation RParenLoc) {
1292 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1293 Cond, Inc, LoopVar, RParenLoc);
1294 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001295
1296 /// \brief Build a new C++0x range-based for statement.
1297 ///
1298 /// By default, performs semantic analysis to build the new statement.
1299 /// Subclasses may override this routine to provide different behavior.
1300 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
1301 bool IsIfExists,
1302 NestedNameSpecifierLoc QualifierLoc,
1303 DeclarationNameInfo NameInfo,
1304 Stmt *Nested) {
1305 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1306 QualifierLoc, NameInfo, Nested);
1307 }
1308
Richard Smithad762fc2011-04-14 22:09:26 +00001309 /// \brief Attach body to a C++0x range-based for statement.
1310 ///
1311 /// By default, performs semantic analysis to finish the new statement.
1312 /// Subclasses may override this routine to provide different behavior.
1313 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1314 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1315 }
1316
John Wiegley28bbe4b2011-04-28 01:08:34 +00001317 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1318 SourceLocation TryLoc,
1319 Stmt *TryBlock,
1320 Stmt *Handler) {
1321 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1322 }
1323
1324 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1325 Expr *FilterExpr,
1326 Stmt *Block) {
1327 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1328 }
1329
1330 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1331 Stmt *Block) {
1332 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1333 }
1334
Douglas Gregorb98b1992009-08-11 05:31:07 +00001335 /// \brief Build a new expression that references a declaration.
1336 ///
1337 /// By default, performs semantic analysis to build the new expression.
1338 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001339 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001340 LookupResult &R,
1341 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001342 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1343 }
1344
1345
1346 /// \brief Build a new expression that references a declaration.
1347 ///
1348 /// By default, performs semantic analysis to build the new expression.
1349 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001350 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001351 ValueDecl *VD,
1352 const DeclarationNameInfo &NameInfo,
1353 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001354 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001355 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001356
1357 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001358
1359 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001360 }
Mike Stump1eb44332009-09-09 15:08:12 +00001361
Douglas Gregorb98b1992009-08-11 05:31:07 +00001362 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001363 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001364 /// By default, performs semantic analysis to build the new expression.
1365 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001366 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001367 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001368 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001369 }
1370
Douglas Gregora71d8192009-09-04 17:36:40 +00001371 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001372 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001373 /// By default, performs semantic analysis to build the new expression.
1374 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001375 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001376 SourceLocation OperatorLoc,
1377 bool isArrow,
1378 CXXScopeSpec &SS,
1379 TypeSourceInfo *ScopeType,
1380 SourceLocation CCLoc,
1381 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001382 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001383
Douglas Gregorb98b1992009-08-11 05:31:07 +00001384 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001385 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001386 /// By default, performs semantic analysis to build the new expression.
1387 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001388 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001389 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001390 Expr *SubExpr) {
1391 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001392 }
Mike Stump1eb44332009-09-09 15:08:12 +00001393
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001394 /// \brief Build a new builtin offsetof expression.
1395 ///
1396 /// By default, performs semantic analysis to build the new expression.
1397 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001398 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001399 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001400 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001401 unsigned NumComponents,
1402 SourceLocation RParenLoc) {
1403 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1404 NumComponents, RParenLoc);
1405 }
Sean Huntc3021132010-05-05 15:23:54 +00001406
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001407 /// \brief Build a new sizeof, alignof or vec_step expression with a
1408 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001409 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001410 /// By default, performs semantic analysis to build the new expression.
1411 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001412 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1413 SourceLocation OpLoc,
1414 UnaryExprOrTypeTrait ExprKind,
1415 SourceRange R) {
1416 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001417 }
1418
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001419 /// \brief Build a new sizeof, alignof or vec step expression with an
1420 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001421 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001422 /// By default, performs semantic analysis to build the new expression.
1423 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001424 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1425 UnaryExprOrTypeTrait ExprKind,
1426 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001427 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001428 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001429 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001430 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001431
Douglas Gregorb98b1992009-08-11 05:31:07 +00001432 return move(Result);
1433 }
Mike Stump1eb44332009-09-09 15:08:12 +00001434
Douglas Gregorb98b1992009-08-11 05:31:07 +00001435 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001436 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001437 /// By default, performs semantic analysis to build the new expression.
1438 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001439 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001440 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001441 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001442 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001443 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1444 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001445 RBracketLoc);
1446 }
1447
1448 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001449 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001450 /// By default, performs semantic analysis to build the new expression.
1451 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001452 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001453 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001454 SourceLocation RParenLoc,
1455 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001456 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001457 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001458 }
1459
1460 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001461 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001462 /// By default, performs semantic analysis to build the new expression.
1463 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001464 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001465 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001466 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001467 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001468 const DeclarationNameInfo &MemberNameInfo,
1469 ValueDecl *Member,
1470 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001471 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001472 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001473 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1474 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001475 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001476 // We have a reference to an unnamed field. This is always the
1477 // base of an anonymous struct/union member access, i.e. the
1478 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001479 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001480 assert(Member->getType()->isRecordType() &&
1481 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001482
Richard Smith9138b4e2011-10-26 19:06:56 +00001483 BaseResult =
1484 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001485 QualifierLoc.getNestedNameSpecifier(),
1486 FoundDecl, Member);
1487 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001488 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001489 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001490 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001491 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001492 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001493 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001494 cast<FieldDecl>(Member)->getType(),
1495 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001496 return getSema().Owned(ME);
1497 }
Mike Stump1eb44332009-09-09 15:08:12 +00001498
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001499 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001500 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001501
John Wiegley429bb272011-04-08 18:41:53 +00001502 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001503 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001504
John McCall6bb80172010-03-30 21:47:33 +00001505 // FIXME: this involves duplicating earlier analysis in a lot of
1506 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001507 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001508 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001509 R.resolveKind();
1510
John McCall9ae2f072010-08-23 23:25:46 +00001511 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001512 SS, TemplateKWLoc,
1513 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001514 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001515 }
Mike Stump1eb44332009-09-09 15:08:12 +00001516
Douglas Gregorb98b1992009-08-11 05:31:07 +00001517 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001518 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001519 /// By default, performs semantic analysis to build the new expression.
1520 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001521 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001522 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001523 Expr *LHS, Expr *RHS) {
1524 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001525 }
1526
1527 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001528 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001529 /// By default, performs semantic analysis to build the new expression.
1530 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001531 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001532 SourceLocation QuestionLoc,
1533 Expr *LHS,
1534 SourceLocation ColonLoc,
1535 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001536 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1537 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001538 }
1539
Douglas Gregorb98b1992009-08-11 05:31:07 +00001540 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001541 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001542 /// By default, performs semantic analysis to build the new expression.
1543 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001544 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001545 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001546 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001547 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001548 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001549 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001550 }
Mike Stump1eb44332009-09-09 15:08:12 +00001551
Douglas Gregorb98b1992009-08-11 05:31:07 +00001552 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001553 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001554 /// By default, performs semantic analysis to build the new expression.
1555 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001556 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001557 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001558 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001559 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001560 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001561 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001562 }
Mike Stump1eb44332009-09-09 15:08:12 +00001563
Douglas Gregorb98b1992009-08-11 05:31:07 +00001564 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001565 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001566 /// By default, performs semantic analysis to build the new expression.
1567 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001568 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001569 SourceLocation OpLoc,
1570 SourceLocation AccessorLoc,
1571 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001572
John McCall129e2df2009-11-30 22:42:35 +00001573 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001574 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001575 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001576 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001577 SS, SourceLocation(),
1578 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001579 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001580 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001581 }
Mike Stump1eb44332009-09-09 15:08:12 +00001582
Douglas Gregorb98b1992009-08-11 05:31:07 +00001583 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001584 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001585 /// By default, performs semantic analysis to build the new expression.
1586 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001587 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001588 MultiExprArg Inits,
1589 SourceLocation RBraceLoc,
1590 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001591 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001592 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1593 if (Result.isInvalid() || ResultTy->isDependentType())
1594 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001595
Douglas Gregore48319a2009-11-09 17:16:50 +00001596 // Patch in the result type we were given, which may have been computed
1597 // when the initial InitListExpr was built.
1598 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1599 ILE->setType(ResultTy);
1600 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001601 }
Mike Stump1eb44332009-09-09 15:08:12 +00001602
Douglas Gregorb98b1992009-08-11 05:31:07 +00001603 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001604 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001605 /// By default, performs semantic analysis to build the new expression.
1606 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001607 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001608 MultiExprArg ArrayExprs,
1609 SourceLocation EqualOrColonLoc,
1610 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001611 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001612 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001613 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001614 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001615 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001616 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001617
Douglas Gregorb98b1992009-08-11 05:31:07 +00001618 ArrayExprs.release();
1619 return move(Result);
1620 }
Mike Stump1eb44332009-09-09 15:08:12 +00001621
Douglas Gregorb98b1992009-08-11 05:31:07 +00001622 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001623 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001624 /// By default, builds the implicit value initialization without performing
1625 /// any semantic analysis. Subclasses may override this routine to provide
1626 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001627 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001628 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1629 }
Mike Stump1eb44332009-09-09 15:08:12 +00001630
Douglas Gregorb98b1992009-08-11 05:31:07 +00001631 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001632 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001633 /// By default, performs semantic analysis to build the new expression.
1634 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001635 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001636 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001637 SourceLocation RParenLoc) {
1638 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001639 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001640 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001641 }
1642
1643 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001644 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001645 /// By default, performs semantic analysis to build the new expression.
1646 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001647 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001648 MultiExprArg SubExprs,
1649 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001650 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001651 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001652 }
Mike Stump1eb44332009-09-09 15:08:12 +00001653
Douglas Gregorb98b1992009-08-11 05:31:07 +00001654 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001655 ///
1656 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001657 /// rather than attempting to map the label statement itself.
1658 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001659 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001660 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001661 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001662 }
Mike Stump1eb44332009-09-09 15:08:12 +00001663
Douglas Gregorb98b1992009-08-11 05:31:07 +00001664 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001665 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001666 /// By default, performs semantic analysis to build the new expression.
1667 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001668 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001669 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001670 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001671 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001672 }
Mike Stump1eb44332009-09-09 15:08:12 +00001673
Douglas Gregorb98b1992009-08-11 05:31:07 +00001674 /// \brief Build a new __builtin_choose_expr expression.
1675 ///
1676 /// By default, performs semantic analysis to build the new expression.
1677 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001678 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001679 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001680 SourceLocation RParenLoc) {
1681 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001682 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001683 RParenLoc);
1684 }
Mike Stump1eb44332009-09-09 15:08:12 +00001685
Peter Collingbournef111d932011-04-15 00:35:48 +00001686 /// \brief Build a new generic selection expression.
1687 ///
1688 /// By default, performs semantic analysis to build the new expression.
1689 /// Subclasses may override this routine to provide different behavior.
1690 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1691 SourceLocation DefaultLoc,
1692 SourceLocation RParenLoc,
1693 Expr *ControllingExpr,
1694 TypeSourceInfo **Types,
1695 Expr **Exprs,
1696 unsigned NumAssocs) {
1697 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1698 ControllingExpr, Types, Exprs,
1699 NumAssocs);
1700 }
1701
Douglas Gregorb98b1992009-08-11 05:31:07 +00001702 /// \brief Build a new overloaded operator call expression.
1703 ///
1704 /// By default, performs semantic analysis to build the new expression.
1705 /// The semantic analysis provides the behavior of template instantiation,
1706 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001707 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001708 /// argument-dependent lookup, etc. Subclasses may override this routine to
1709 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001710 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001711 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001712 Expr *Callee,
1713 Expr *First,
1714 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001715
1716 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001717 /// reinterpret_cast.
1718 ///
1719 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001720 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001721 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001722 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001723 Stmt::StmtClass Class,
1724 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001725 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001726 SourceLocation RAngleLoc,
1727 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001728 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001729 SourceLocation RParenLoc) {
1730 switch (Class) {
1731 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001732 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001733 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001734 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001735
1736 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001737 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001738 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001739 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001740
Douglas Gregorb98b1992009-08-11 05:31:07 +00001741 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001742 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001743 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001744 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001745 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001746
Douglas Gregorb98b1992009-08-11 05:31:07 +00001747 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001748 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001749 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001750 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001751
Douglas Gregorb98b1992009-08-11 05:31:07 +00001752 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001753 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001754 }
Mike Stump1eb44332009-09-09 15:08:12 +00001755
John McCallf312b1e2010-08-26 23:41:50 +00001756 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001757 }
Mike Stump1eb44332009-09-09 15:08:12 +00001758
Douglas Gregorb98b1992009-08-11 05:31:07 +00001759 /// \brief Build a new C++ static_cast expression.
1760 ///
1761 /// By default, performs semantic analysis to build the new expression.
1762 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001763 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001764 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001765 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001766 SourceLocation RAngleLoc,
1767 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001768 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001769 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001770 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001771 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001772 SourceRange(LAngleLoc, RAngleLoc),
1773 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001774 }
1775
1776 /// \brief Build a new C++ dynamic_cast expression.
1777 ///
1778 /// By default, performs semantic analysis to build the new expression.
1779 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001780 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001781 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001782 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001783 SourceLocation RAngleLoc,
1784 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001785 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001786 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001787 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001788 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001789 SourceRange(LAngleLoc, RAngleLoc),
1790 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791 }
1792
1793 /// \brief Build a new C++ reinterpret_cast expression.
1794 ///
1795 /// By default, performs semantic analysis to build the new expression.
1796 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001797 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001798 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001799 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001800 SourceLocation RAngleLoc,
1801 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001802 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001803 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001804 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001805 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001806 SourceRange(LAngleLoc, RAngleLoc),
1807 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001808 }
1809
1810 /// \brief Build a new C++ const_cast expression.
1811 ///
1812 /// By default, performs semantic analysis to build the new expression.
1813 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001814 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001815 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001816 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001817 SourceLocation RAngleLoc,
1818 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001819 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001820 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001821 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001822 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001823 SourceRange(LAngleLoc, RAngleLoc),
1824 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001825 }
Mike Stump1eb44332009-09-09 15:08:12 +00001826
Douglas Gregorb98b1992009-08-11 05:31:07 +00001827 /// \brief Build a new C++ functional-style cast expression.
1828 ///
1829 /// By default, performs semantic analysis to build the new expression.
1830 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001831 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1832 SourceLocation LParenLoc,
1833 Expr *Sub,
1834 SourceLocation RParenLoc) {
1835 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001836 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001837 RParenLoc);
1838 }
Mike Stump1eb44332009-09-09 15:08:12 +00001839
Douglas Gregorb98b1992009-08-11 05:31:07 +00001840 /// \brief Build a new C++ typeid(type) expression.
1841 ///
1842 /// By default, performs semantic analysis to build the new expression.
1843 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001844 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001845 SourceLocation TypeidLoc,
1846 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001847 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001848 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001849 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001850 }
Mike Stump1eb44332009-09-09 15:08:12 +00001851
Francois Pichet01b7c302010-09-08 12:20:18 +00001852
Douglas Gregorb98b1992009-08-11 05:31:07 +00001853 /// \brief Build a new C++ typeid(expr) expression.
1854 ///
1855 /// By default, performs semantic analysis to build the new expression.
1856 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001857 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001858 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001859 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001860 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001861 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001862 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001863 }
1864
Francois Pichet01b7c302010-09-08 12:20:18 +00001865 /// \brief Build a new C++ __uuidof(type) expression.
1866 ///
1867 /// By default, performs semantic analysis to build the new expression.
1868 /// Subclasses may override this routine to provide different behavior.
1869 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1870 SourceLocation TypeidLoc,
1871 TypeSourceInfo *Operand,
1872 SourceLocation RParenLoc) {
1873 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1874 RParenLoc);
1875 }
1876
1877 /// \brief Build a new C++ __uuidof(expr) expression.
1878 ///
1879 /// By default, performs semantic analysis to build the new expression.
1880 /// Subclasses may override this routine to provide different behavior.
1881 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1882 SourceLocation TypeidLoc,
1883 Expr *Operand,
1884 SourceLocation RParenLoc) {
1885 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1886 RParenLoc);
1887 }
1888
Douglas Gregorb98b1992009-08-11 05:31:07 +00001889 /// \brief Build a new C++ "this" expression.
1890 ///
1891 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001892 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001893 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001894 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001895 QualType ThisType,
1896 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001897 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001898 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001899 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1900 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001901 }
1902
1903 /// \brief Build a new C++ throw expression.
1904 ///
1905 /// By default, performs semantic analysis to build the new expression.
1906 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001907 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1908 bool IsThrownVariableInScope) {
1909 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001910 }
1911
1912 /// \brief Build a new C++ default-argument expression.
1913 ///
1914 /// By default, builds a new default-argument expression, which does not
1915 /// require any semantic analysis. Subclasses may override this routine to
1916 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001917 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001918 ParmVarDecl *Param) {
1919 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1920 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001921 }
1922
1923 /// \brief Build a new C++ zero-initialization expression.
1924 ///
1925 /// By default, performs semantic analysis to build the new expression.
1926 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001927 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1928 SourceLocation LParenLoc,
1929 SourceLocation RParenLoc) {
1930 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001931 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001932 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001933 }
Mike Stump1eb44332009-09-09 15:08:12 +00001934
Douglas Gregorb98b1992009-08-11 05:31:07 +00001935 /// \brief Build a new C++ "new" expression.
1936 ///
1937 /// By default, performs semantic analysis to build the new expression.
1938 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001939 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001940 bool UseGlobal,
1941 SourceLocation PlacementLParen,
1942 MultiExprArg PlacementArgs,
1943 SourceLocation PlacementRParen,
1944 SourceRange TypeIdParens,
1945 QualType AllocatedType,
1946 TypeSourceInfo *AllocatedTypeInfo,
1947 Expr *ArraySize,
1948 SourceLocation ConstructorLParen,
1949 MultiExprArg ConstructorArgs,
1950 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001951 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001952 PlacementLParen,
1953 move(PlacementArgs),
1954 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001955 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001956 AllocatedType,
1957 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001958 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001959 ConstructorLParen,
1960 move(ConstructorArgs),
1961 ConstructorRParen);
1962 }
Mike Stump1eb44332009-09-09 15:08:12 +00001963
Douglas Gregorb98b1992009-08-11 05:31:07 +00001964 /// \brief Build a new C++ "delete" expression.
1965 ///
1966 /// By default, performs semantic analysis to build the new expression.
1967 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001968 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001969 bool IsGlobalDelete,
1970 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001971 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001972 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001973 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001974 }
Mike Stump1eb44332009-09-09 15:08:12 +00001975
Douglas Gregorb98b1992009-08-11 05:31:07 +00001976 /// \brief Build a new unary type trait expression.
1977 ///
1978 /// By default, performs semantic analysis to build the new expression.
1979 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001980 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001981 SourceLocation StartLoc,
1982 TypeSourceInfo *T,
1983 SourceLocation RParenLoc) {
1984 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001985 }
1986
Francois Pichet6ad6f282010-12-07 00:08:36 +00001987 /// \brief Build a new binary type trait expression.
1988 ///
1989 /// By default, performs semantic analysis to build the new expression.
1990 /// Subclasses may override this routine to provide different behavior.
1991 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1992 SourceLocation StartLoc,
1993 TypeSourceInfo *LhsT,
1994 TypeSourceInfo *RhsT,
1995 SourceLocation RParenLoc) {
1996 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1997 }
1998
John Wiegley21ff2e52011-04-28 00:16:57 +00001999 /// \brief Build a new array type trait expression.
2000 ///
2001 /// By default, performs semantic analysis to build the new expression.
2002 /// Subclasses may override this routine to provide different behavior.
2003 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2004 SourceLocation StartLoc,
2005 TypeSourceInfo *TSInfo,
2006 Expr *DimExpr,
2007 SourceLocation RParenLoc) {
2008 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2009 }
2010
John Wiegley55262202011-04-25 06:54:41 +00002011 /// \brief Build a new expression trait expression.
2012 ///
2013 /// By default, performs semantic analysis to build the new expression.
2014 /// Subclasses may override this routine to provide different behavior.
2015 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2016 SourceLocation StartLoc,
2017 Expr *Queried,
2018 SourceLocation RParenLoc) {
2019 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2020 }
2021
Mike Stump1eb44332009-09-09 15:08:12 +00002022 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002023 /// expression.
2024 ///
2025 /// By default, performs semantic analysis to build the new expression.
2026 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002027 ExprResult RebuildDependentScopeDeclRefExpr(
2028 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002029 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002030 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002031 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002032 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002033 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002034
2035 if (TemplateArgs)
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002036 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
2037 NameInfo, *TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002038
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002039 return getSema().BuildQualifiedDeclarationNameExpr(SS, TemplateKWLoc,
2040 NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002041 }
2042
2043 /// \brief Build a new template-id expression.
2044 ///
2045 /// By default, performs semantic analysis to build the new expression.
2046 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002047 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002048 SourceLocation TemplateKWLoc,
2049 LookupResult &R,
2050 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00002051 const TemplateArgumentListInfo &TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002052 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2053 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002054 }
2055
2056 /// \brief Build a new object-construction expression.
2057 ///
2058 /// By default, performs semantic analysis to build the new expression.
2059 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002060 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002061 SourceLocation Loc,
2062 CXXConstructorDecl *Constructor,
2063 bool IsElidable,
2064 MultiExprArg Args,
2065 bool HadMultipleCandidates,
2066 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002067 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002068 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00002069 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00002070 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002071 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002072 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002073
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002074 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002075 move_arg(ConvertedArgs),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002076 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002077 RequiresZeroInit, ConstructKind,
2078 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002079 }
2080
2081 /// \brief Build a new object-construction expression.
2082 ///
2083 /// By default, performs semantic analysis to build the new expression.
2084 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002085 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2086 SourceLocation LParenLoc,
2087 MultiExprArg Args,
2088 SourceLocation RParenLoc) {
2089 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002090 LParenLoc,
2091 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002092 RParenLoc);
2093 }
2094
2095 /// \brief Build a new object-construction expression.
2096 ///
2097 /// By default, performs semantic analysis to build the new expression.
2098 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002099 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2100 SourceLocation LParenLoc,
2101 MultiExprArg Args,
2102 SourceLocation RParenLoc) {
2103 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002104 LParenLoc,
2105 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002106 RParenLoc);
2107 }
Mike Stump1eb44332009-09-09 15:08:12 +00002108
Douglas Gregorb98b1992009-08-11 05:31:07 +00002109 /// \brief Build a new member reference expression.
2110 ///
2111 /// By default, performs semantic analysis to build the new expression.
2112 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002113 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002114 QualType BaseType,
2115 bool IsArrow,
2116 SourceLocation OperatorLoc,
2117 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002118 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002119 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002120 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002121 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002122 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002123 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002124
John McCall9ae2f072010-08-23 23:25:46 +00002125 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002126 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002127 SS, TemplateKWLoc,
2128 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002129 MemberNameInfo,
2130 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002131 }
2132
John McCall129e2df2009-11-30 22:42:35 +00002133 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002134 ///
2135 /// By default, performs semantic analysis to build the new expression.
2136 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002137 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2138 SourceLocation OperatorLoc,
2139 bool IsArrow,
2140 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002141 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002142 NamedDecl *FirstQualifierInScope,
2143 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002144 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002145 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002146 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002147
John McCall9ae2f072010-08-23 23:25:46 +00002148 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002149 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002150 SS, TemplateKWLoc,
2151 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002152 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002153 }
Mike Stump1eb44332009-09-09 15:08:12 +00002154
Sebastian Redl2e156222010-09-10 20:55:43 +00002155 /// \brief Build a new noexcept expression.
2156 ///
2157 /// By default, performs semantic analysis to build the new expression.
2158 /// Subclasses may override this routine to provide different behavior.
2159 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2160 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2161 }
2162
Douglas Gregoree8aff02011-01-04 17:33:58 +00002163 /// \brief Build a new expression to compute the length of a parameter pack.
2164 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2165 SourceLocation PackLoc,
2166 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002167 llvm::Optional<unsigned> Length) {
2168 if (Length)
2169 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2170 OperatorLoc, Pack, PackLoc,
2171 RParenLoc, *Length);
2172
Douglas Gregoree8aff02011-01-04 17:33:58 +00002173 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2174 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002175 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002176 }
2177
Douglas Gregorb98b1992009-08-11 05:31:07 +00002178 /// \brief Build a new Objective-C @encode expression.
2179 ///
2180 /// By default, performs semantic analysis to build the new expression.
2181 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002182 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002183 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002184 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002185 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002186 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002187 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002188
Douglas Gregor92e986e2010-04-22 16:44:27 +00002189 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002190 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002191 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002192 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002193 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002194 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002195 MultiExprArg Args,
2196 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002197 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2198 ReceiverTypeInfo->getType(),
2199 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002200 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002201 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002202 }
2203
2204 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002205 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002206 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002207 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002208 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002209 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002210 MultiExprArg Args,
2211 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002212 return SemaRef.BuildInstanceMessage(Receiver,
2213 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002214 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002215 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002216 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002217 }
2218
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002219 /// \brief Build a new Objective-C ivar reference expression.
2220 ///
2221 /// By default, performs semantic analysis to build the new expression.
2222 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002223 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002224 SourceLocation IvarLoc,
2225 bool IsArrow, bool IsFreeIvar) {
2226 // FIXME: We lose track of the IsFreeIvar bit.
2227 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002228 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002229 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2230 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002231 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002232 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002233 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002234 false);
John Wiegley429bb272011-04-08 18:41:53 +00002235 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002236 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002237
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002238 if (Result.get())
2239 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002240
John Wiegley429bb272011-04-08 18:41:53 +00002241 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002242 /*FIXME:*/IvarLoc, IsArrow,
2243 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002244 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002245 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002246 /*TemplateArgs=*/0);
2247 }
Douglas Gregore3303542010-04-26 20:47:02 +00002248
2249 /// \brief Build a new Objective-C property reference expression.
2250 ///
2251 /// By default, performs semantic analysis to build the new expression.
2252 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002253 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002254 ObjCPropertyDecl *Property,
2255 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002256 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002257 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002258 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2259 Sema::LookupMemberName);
2260 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002261 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002262 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002263 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002264 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002265 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002266
Douglas Gregore3303542010-04-26 20:47:02 +00002267 if (Result.get())
2268 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002269
John Wiegley429bb272011-04-08 18:41:53 +00002270 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002271 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002272 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002273 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002274 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002275 /*TemplateArgs=*/0);
2276 }
Sean Huntc3021132010-05-05 15:23:54 +00002277
John McCall12f78a62010-12-02 01:19:52 +00002278 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002279 ///
2280 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002281 /// Subclasses may override this routine to provide different behavior.
2282 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2283 ObjCMethodDecl *Getter,
2284 ObjCMethodDecl *Setter,
2285 SourceLocation PropertyLoc) {
2286 // Since these expressions can only be value-dependent, we do not
2287 // need to perform semantic analysis again.
2288 return Owned(
2289 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2290 VK_LValue, OK_ObjCProperty,
2291 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002292 }
2293
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002294 /// \brief Build a new Objective-C "isa" expression.
2295 ///
2296 /// By default, performs semantic analysis to build the new expression.
2297 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002298 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002299 bool IsArrow) {
2300 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002301 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002302 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2303 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002304 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002305 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002306 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002307 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002308 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002309
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002310 if (Result.get())
2311 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002312
John Wiegley429bb272011-04-08 18:41:53 +00002313 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002314 /*FIXME:*/IsaLoc, IsArrow,
2315 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002316 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002317 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002318 /*TemplateArgs=*/0);
2319 }
Sean Huntc3021132010-05-05 15:23:54 +00002320
Douglas Gregorb98b1992009-08-11 05:31:07 +00002321 /// \brief Build a new shuffle vector expression.
2322 ///
2323 /// By default, performs semantic analysis to build the new expression.
2324 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002325 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002326 MultiExprArg SubExprs,
2327 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002328 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002329 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002330 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2331 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2332 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2333 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002334
Douglas Gregorb98b1992009-08-11 05:31:07 +00002335 // Build a reference to the __builtin_shufflevector builtin
2336 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002337 ExprResult Callee
2338 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2339 VK_LValue, BuiltinLoc));
2340 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2341 if (Callee.isInvalid())
2342 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002343
2344 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002345 unsigned NumSubExprs = SubExprs.size();
2346 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002347 ExprResult TheCall = SemaRef.Owned(
2348 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002349 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002350 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002351 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002352 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002353
Douglas Gregorb98b1992009-08-11 05:31:07 +00002354 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002355 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002356 }
John McCall43fed0d2010-11-12 08:19:04 +00002357
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002358 /// \brief Build a new template argument pack expansion.
2359 ///
2360 /// By default, performs semantic analysis to build a new pack expansion
2361 /// for a template argument. Subclasses may override this routine to provide
2362 /// different behavior.
2363 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002364 SourceLocation EllipsisLoc,
2365 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002366 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002367 case TemplateArgument::Expression: {
2368 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002369 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2370 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002371 if (Result.isInvalid())
2372 return TemplateArgumentLoc();
2373
2374 return TemplateArgumentLoc(Result.get(), Result.get());
2375 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002376
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002377 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002378 return TemplateArgumentLoc(TemplateArgument(
2379 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002380 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002381 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002382 Pattern.getTemplateNameLoc(),
2383 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002384
2385 case TemplateArgument::Null:
2386 case TemplateArgument::Integral:
2387 case TemplateArgument::Declaration:
2388 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002389 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002390 llvm_unreachable("Pack expansion pattern has no parameter packs");
2391
2392 case TemplateArgument::Type:
2393 if (TypeSourceInfo *Expansion
2394 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002395 EllipsisLoc,
2396 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002397 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2398 Expansion);
2399 break;
2400 }
2401
2402 return TemplateArgumentLoc();
2403 }
2404
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002405 /// \brief Build a new expression pack expansion.
2406 ///
2407 /// By default, performs semantic analysis to build a new pack expansion
2408 /// for an expression. Subclasses may override this routine to provide
2409 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002410 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2411 llvm::Optional<unsigned> NumExpansions) {
2412 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002413 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002414
2415 /// \brief Build a new atomic operation expression.
2416 ///
2417 /// By default, performs semantic analysis to build the new expression.
2418 /// Subclasses may override this routine to provide different behavior.
2419 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2420 MultiExprArg SubExprs,
2421 QualType RetTy,
2422 AtomicExpr::AtomicOp Op,
2423 SourceLocation RParenLoc) {
2424 // Just create the expression; there is not any interesting semantic
2425 // analysis here because we can't actually build an AtomicExpr until
2426 // we are sure it is semantically sound.
2427 unsigned NumSubExprs = SubExprs.size();
2428 Expr **Subs = (Expr **)SubExprs.release();
2429 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2430 NumSubExprs, RetTy, Op,
2431 RParenLoc);
2432 }
2433
John McCall43fed0d2010-11-12 08:19:04 +00002434private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002435 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2436 QualType ObjectType,
2437 NamedDecl *FirstQualifierInScope,
2438 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002439
2440 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2441 QualType ObjectType,
2442 NamedDecl *FirstQualifierInScope,
2443 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002444};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002445
Douglas Gregor43959a92009-08-20 07:17:43 +00002446template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002447StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002448 if (!S)
2449 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002450
Douglas Gregor43959a92009-08-20 07:17:43 +00002451 switch (S->getStmtClass()) {
2452 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002453
Douglas Gregor43959a92009-08-20 07:17:43 +00002454 // Transform individual statement nodes
2455#define STMT(Node, Parent) \
2456 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002457#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002458#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002459#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002460
Douglas Gregor43959a92009-08-20 07:17:43 +00002461 // Transform expressions by calling TransformExpr.
2462#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002463#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002464#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002465#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002466 {
John McCall60d7b3a2010-08-24 06:29:42 +00002467 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002468 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002469 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002470
John McCall9ae2f072010-08-23 23:25:46 +00002471 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002472 }
Mike Stump1eb44332009-09-09 15:08:12 +00002473 }
2474
John McCall3fa5cae2010-10-26 07:05:15 +00002475 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002476}
Mike Stump1eb44332009-09-09 15:08:12 +00002477
2478
Douglas Gregor670444e2009-08-04 22:27:00 +00002479template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002480ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002481 if (!E)
2482 return SemaRef.Owned(E);
2483
2484 switch (E->getStmtClass()) {
2485 case Stmt::NoStmtClass: break;
2486#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002487#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002488#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002489 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002490#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002491 }
2492
John McCall3fa5cae2010-10-26 07:05:15 +00002493 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002494}
2495
2496template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002497bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2498 unsigned NumInputs,
2499 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002500 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002501 bool *ArgChanged) {
2502 for (unsigned I = 0; I != NumInputs; ++I) {
2503 // If requested, drop call arguments that need to be dropped.
2504 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2505 if (ArgChanged)
2506 *ArgChanged = true;
2507
2508 break;
2509 }
2510
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002511 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2512 Expr *Pattern = Expansion->getPattern();
2513
Chris Lattner686775d2011-07-20 06:58:45 +00002514 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002515 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2516 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2517
2518 // Determine whether the set of unexpanded parameter packs can and should
2519 // be expanded.
2520 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002521 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002522 llvm::Optional<unsigned> OrigNumExpansions
2523 = Expansion->getNumExpansions();
2524 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002525 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2526 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002527 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002528 Expand, RetainExpansion,
2529 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002530 return true;
2531
2532 if (!Expand) {
2533 // The transform has determined that we should perform a simple
2534 // transformation on the pack expansion, producing another pack
2535 // expansion.
2536 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2537 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2538 if (OutPattern.isInvalid())
2539 return true;
2540
2541 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002542 Expansion->getEllipsisLoc(),
2543 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002544 if (Out.isInvalid())
2545 return true;
2546
2547 if (ArgChanged)
2548 *ArgChanged = true;
2549 Outputs.push_back(Out.get());
2550 continue;
2551 }
John McCallc8fc90a2011-07-06 07:30:07 +00002552
2553 // Record right away that the argument was changed. This needs
2554 // to happen even if the array expands to nothing.
2555 if (ArgChanged) *ArgChanged = true;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002556
2557 // The transform has determined that we should perform an elementwise
2558 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002559 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002560 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2561 ExprResult Out = getDerived().TransformExpr(Pattern);
2562 if (Out.isInvalid())
2563 return true;
2564
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002565 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002566 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2567 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002568 if (Out.isInvalid())
2569 return true;
2570 }
2571
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002572 Outputs.push_back(Out.get());
2573 }
2574
2575 continue;
2576 }
2577
Douglas Gregoraa165f82011-01-03 19:04:46 +00002578 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2579 if (Result.isInvalid())
2580 return true;
2581
2582 if (Result.get() != Inputs[I] && ArgChanged)
2583 *ArgChanged = true;
2584
2585 Outputs.push_back(Result.get());
2586 }
2587
2588 return false;
2589}
2590
2591template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002592NestedNameSpecifierLoc
2593TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2594 NestedNameSpecifierLoc NNS,
2595 QualType ObjectType,
2596 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002597 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002598 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2599 Qualifier = Qualifier.getPrefix())
2600 Qualifiers.push_back(Qualifier);
2601
2602 CXXScopeSpec SS;
2603 while (!Qualifiers.empty()) {
2604 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2605 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2606
2607 switch (QNNS->getKind()) {
2608 case NestedNameSpecifier::Identifier:
2609 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2610 *QNNS->getAsIdentifier(),
2611 Q.getLocalBeginLoc(),
2612 Q.getLocalEndLoc(),
2613 ObjectType, false, SS,
2614 FirstQualifierInScope, false))
2615 return NestedNameSpecifierLoc();
2616
2617 break;
2618
2619 case NestedNameSpecifier::Namespace: {
2620 NamespaceDecl *NS
2621 = cast_or_null<NamespaceDecl>(
2622 getDerived().TransformDecl(
2623 Q.getLocalBeginLoc(),
2624 QNNS->getAsNamespace()));
2625 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2626 break;
2627 }
2628
2629 case NestedNameSpecifier::NamespaceAlias: {
2630 NamespaceAliasDecl *Alias
2631 = cast_or_null<NamespaceAliasDecl>(
2632 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2633 QNNS->getAsNamespaceAlias()));
2634 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2635 Q.getLocalEndLoc());
2636 break;
2637 }
2638
2639 case NestedNameSpecifier::Global:
2640 // There is no meaningful transformation that one could perform on the
2641 // global scope.
2642 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2643 break;
2644
2645 case NestedNameSpecifier::TypeSpecWithTemplate:
2646 case NestedNameSpecifier::TypeSpec: {
2647 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2648 FirstQualifierInScope, SS);
2649
2650 if (!TL)
2651 return NestedNameSpecifierLoc();
2652
2653 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2654 (SemaRef.getLangOptions().CPlusPlus0x &&
2655 TL.getType()->isEnumeralType())) {
2656 assert(!TL.getType().hasLocalQualifiers() &&
2657 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002658 if (TL.getType()->isEnumeralType())
2659 SemaRef.Diag(TL.getBeginLoc(),
2660 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002661 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2662 Q.getLocalEndLoc());
2663 break;
2664 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002665 // If the nested-name-specifier is an invalid type def, don't emit an
2666 // error because a previous error should have already been emitted.
2667 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2668 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2669 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2670 << TL.getType() << SS.getRange();
2671 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002672 return NestedNameSpecifierLoc();
2673 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002674 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002675
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002676 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002677 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002678 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002679 }
2680
2681 // Don't rebuild the nested-name-specifier if we don't have to.
2682 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2683 !getDerived().AlwaysRebuild())
2684 return NNS;
2685
2686 // If we can re-use the source-location data from the original
2687 // nested-name-specifier, do so.
2688 if (SS.location_size() == NNS.getDataLength() &&
2689 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2690 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2691
2692 // Allocate new nested-name-specifier location information.
2693 return SS.getWithLocInContext(SemaRef.Context);
2694}
2695
2696template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002697DeclarationNameInfo
2698TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002699::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002700 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002701 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002702 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002703
2704 switch (Name.getNameKind()) {
2705 case DeclarationName::Identifier:
2706 case DeclarationName::ObjCZeroArgSelector:
2707 case DeclarationName::ObjCOneArgSelector:
2708 case DeclarationName::ObjCMultiArgSelector:
2709 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002710 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002711 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002712 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002713
Douglas Gregor81499bb2009-09-03 22:13:48 +00002714 case DeclarationName::CXXConstructorName:
2715 case DeclarationName::CXXDestructorName:
2716 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002717 TypeSourceInfo *NewTInfo;
2718 CanQualType NewCanTy;
2719 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002720 NewTInfo = getDerived().TransformType(OldTInfo);
2721 if (!NewTInfo)
2722 return DeclarationNameInfo();
2723 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002724 }
2725 else {
2726 NewTInfo = 0;
2727 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002728 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002729 if (NewT.isNull())
2730 return DeclarationNameInfo();
2731 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2732 }
Mike Stump1eb44332009-09-09 15:08:12 +00002733
Abramo Bagnara25777432010-08-11 22:01:17 +00002734 DeclarationName NewName
2735 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2736 NewCanTy);
2737 DeclarationNameInfo NewNameInfo(NameInfo);
2738 NewNameInfo.setName(NewName);
2739 NewNameInfo.setNamedTypeInfo(NewTInfo);
2740 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002741 }
Mike Stump1eb44332009-09-09 15:08:12 +00002742 }
2743
David Blaikieb219cfc2011-09-23 05:06:16 +00002744 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002745}
2746
2747template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002748TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002749TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2750 TemplateName Name,
2751 SourceLocation NameLoc,
2752 QualType ObjectType,
2753 NamedDecl *FirstQualifierInScope) {
2754 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2755 TemplateDecl *Template = QTN->getTemplateDecl();
2756 assert(Template && "qualified template name must refer to a template");
2757
2758 TemplateDecl *TransTemplate
2759 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2760 Template));
2761 if (!TransTemplate)
2762 return TemplateName();
2763
2764 if (!getDerived().AlwaysRebuild() &&
2765 SS.getScopeRep() == QTN->getQualifier() &&
2766 TransTemplate == Template)
2767 return Name;
2768
2769 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2770 TransTemplate);
2771 }
2772
2773 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2774 if (SS.getScopeRep()) {
2775 // These apply to the scope specifier, not the template.
2776 ObjectType = QualType();
2777 FirstQualifierInScope = 0;
2778 }
2779
2780 if (!getDerived().AlwaysRebuild() &&
2781 SS.getScopeRep() == DTN->getQualifier() &&
2782 ObjectType.isNull())
2783 return Name;
2784
2785 if (DTN->isIdentifier()) {
2786 return getDerived().RebuildTemplateName(SS,
2787 *DTN->getIdentifier(),
2788 NameLoc,
2789 ObjectType,
2790 FirstQualifierInScope);
2791 }
2792
2793 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2794 ObjectType);
2795 }
2796
2797 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2798 TemplateDecl *TransTemplate
2799 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2800 Template));
2801 if (!TransTemplate)
2802 return TemplateName();
2803
2804 if (!getDerived().AlwaysRebuild() &&
2805 TransTemplate == Template)
2806 return Name;
2807
2808 return TemplateName(TransTemplate);
2809 }
2810
2811 if (SubstTemplateTemplateParmPackStorage *SubstPack
2812 = Name.getAsSubstTemplateTemplateParmPack()) {
2813 TemplateTemplateParmDecl *TransParam
2814 = cast_or_null<TemplateTemplateParmDecl>(
2815 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2816 if (!TransParam)
2817 return TemplateName();
2818
2819 if (!getDerived().AlwaysRebuild() &&
2820 TransParam == SubstPack->getParameterPack())
2821 return Name;
2822
2823 return getDerived().RebuildTemplateName(TransParam,
2824 SubstPack->getArgumentPack());
2825 }
2826
2827 // These should be getting filtered out before they reach the AST.
2828 llvm_unreachable("overloaded function decl survived to here");
2829 return TemplateName();
2830}
2831
2832template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002833void TreeTransform<Derived>::InventTemplateArgumentLoc(
2834 const TemplateArgument &Arg,
2835 TemplateArgumentLoc &Output) {
2836 SourceLocation Loc = getDerived().getBaseLocation();
2837 switch (Arg.getKind()) {
2838 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002839 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002840 break;
2841
2842 case TemplateArgument::Type:
2843 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002844 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002845
John McCall833ca992009-10-29 08:12:44 +00002846 break;
2847
Douglas Gregor788cd062009-11-11 01:00:40 +00002848 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002849 case TemplateArgument::TemplateExpansion: {
2850 NestedNameSpecifierLocBuilder Builder;
2851 TemplateName Template = Arg.getAsTemplate();
2852 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2853 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2854 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2855 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2856
2857 if (Arg.getKind() == TemplateArgument::Template)
2858 Output = TemplateArgumentLoc(Arg,
2859 Builder.getWithLocInContext(SemaRef.Context),
2860 Loc);
2861 else
2862 Output = TemplateArgumentLoc(Arg,
2863 Builder.getWithLocInContext(SemaRef.Context),
2864 Loc, Loc);
2865
Douglas Gregor788cd062009-11-11 01:00:40 +00002866 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002867 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002868
John McCall833ca992009-10-29 08:12:44 +00002869 case TemplateArgument::Expression:
2870 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2871 break;
2872
2873 case TemplateArgument::Declaration:
2874 case TemplateArgument::Integral:
2875 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002876 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002877 break;
2878 }
2879}
2880
2881template<typename Derived>
2882bool TreeTransform<Derived>::TransformTemplateArgument(
2883 const TemplateArgumentLoc &Input,
2884 TemplateArgumentLoc &Output) {
2885 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002886 switch (Arg.getKind()) {
2887 case TemplateArgument::Null:
2888 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002889 Output = Input;
2890 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002891
Douglas Gregor670444e2009-08-04 22:27:00 +00002892 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002893 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002894 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002895 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002896
2897 DI = getDerived().TransformType(DI);
2898 if (!DI) return true;
2899
2900 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2901 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002902 }
Mike Stump1eb44332009-09-09 15:08:12 +00002903
Douglas Gregor670444e2009-08-04 22:27:00 +00002904 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002905 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002906 DeclarationName Name;
2907 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2908 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002909 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002910 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002911 if (!D) return true;
2912
John McCall828bff22009-10-29 18:45:58 +00002913 Expr *SourceExpr = Input.getSourceDeclExpression();
2914 if (SourceExpr) {
2915 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00002916 Sema::ConstantEvaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002917 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002918 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002919 }
2920
2921 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002922 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002923 }
Mike Stump1eb44332009-09-09 15:08:12 +00002924
Douglas Gregor788cd062009-11-11 01:00:40 +00002925 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002926 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2927 if (QualifierLoc) {
2928 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2929 if (!QualifierLoc)
2930 return true;
2931 }
2932
Douglas Gregor1d752d72011-03-02 18:46:51 +00002933 CXXScopeSpec SS;
2934 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00002935 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00002936 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2937 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00002938 if (Template.isNull())
2939 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002940
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002941 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00002942 Input.getTemplateNameLoc());
2943 return false;
2944 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002945
2946 case TemplateArgument::TemplateExpansion:
2947 llvm_unreachable("Caller should expand pack expansions");
2948
Douglas Gregor670444e2009-08-04 22:27:00 +00002949 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00002950 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00002951 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00002952 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002953
John McCall833ca992009-10-29 08:12:44 +00002954 Expr *InputExpr = Input.getSourceExpression();
2955 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2956
Chris Lattner223de242011-04-25 20:37:58 +00002957 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall833ca992009-10-29 08:12:44 +00002958 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002959 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002960 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002961 }
Mike Stump1eb44332009-09-09 15:08:12 +00002962
Douglas Gregor670444e2009-08-04 22:27:00 +00002963 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00002964 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00002965 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002966 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002967 AEnd = Arg.pack_end();
2968 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002969
John McCall833ca992009-10-29 08:12:44 +00002970 // FIXME: preserve source information here when we start
2971 // caring about parameter packs.
2972
John McCall828bff22009-10-29 18:45:58 +00002973 TemplateArgumentLoc InputArg;
2974 TemplateArgumentLoc OutputArg;
2975 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2976 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002977 return true;
2978
John McCall828bff22009-10-29 18:45:58 +00002979 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002980 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002981
2982 TemplateArgument *TransformedArgsPtr
2983 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2984 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2985 TransformedArgsPtr);
2986 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2987 TransformedArgs.size()),
2988 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002989 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002990 }
2991 }
Mike Stump1eb44332009-09-09 15:08:12 +00002992
Douglas Gregor670444e2009-08-04 22:27:00 +00002993 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002994 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002995}
2996
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002997/// \brief Iterator adaptor that invents template argument location information
2998/// for each of the template arguments in its underlying iterator.
2999template<typename Derived, typename InputIterator>
3000class TemplateArgumentLocInventIterator {
3001 TreeTransform<Derived> &Self;
3002 InputIterator Iter;
3003
3004public:
3005 typedef TemplateArgumentLoc value_type;
3006 typedef TemplateArgumentLoc reference;
3007 typedef typename std::iterator_traits<InputIterator>::difference_type
3008 difference_type;
3009 typedef std::input_iterator_tag iterator_category;
3010
3011 class pointer {
3012 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003013
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003014 public:
3015 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3016
3017 const TemplateArgumentLoc *operator->() const { return &Arg; }
3018 };
3019
3020 TemplateArgumentLocInventIterator() { }
3021
3022 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3023 InputIterator Iter)
3024 : Self(Self), Iter(Iter) { }
3025
3026 TemplateArgumentLocInventIterator &operator++() {
3027 ++Iter;
3028 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003029 }
3030
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003031 TemplateArgumentLocInventIterator operator++(int) {
3032 TemplateArgumentLocInventIterator Old(*this);
3033 ++(*this);
3034 return Old;
3035 }
3036
3037 reference operator*() const {
3038 TemplateArgumentLoc Result;
3039 Self.InventTemplateArgumentLoc(*Iter, Result);
3040 return Result;
3041 }
3042
3043 pointer operator->() const { return pointer(**this); }
3044
3045 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3046 const TemplateArgumentLocInventIterator &Y) {
3047 return X.Iter == Y.Iter;
3048 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003049
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003050 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3051 const TemplateArgumentLocInventIterator &Y) {
3052 return X.Iter != Y.Iter;
3053 }
3054};
3055
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003056template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003057template<typename InputIterator>
3058bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3059 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003060 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003061 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003062 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003063 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003064
3065 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3066 // Unpack argument packs, which we translate them into separate
3067 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003068 // FIXME: We could do much better if we could guarantee that the
3069 // TemplateArgumentLocInfo for the pack expansion would be usable for
3070 // all of the template arguments in the argument pack.
3071 typedef TemplateArgumentLocInventIterator<Derived,
3072 TemplateArgument::pack_iterator>
3073 PackLocIterator;
3074 if (TransformTemplateArguments(PackLocIterator(*this,
3075 In.getArgument().pack_begin()),
3076 PackLocIterator(*this,
3077 In.getArgument().pack_end()),
3078 Outputs))
3079 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003080
3081 continue;
3082 }
3083
3084 if (In.getArgument().isPackExpansion()) {
3085 // We have a pack expansion, for which we will be substituting into
3086 // the pattern.
3087 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003088 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003089 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003090 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3091 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003092
Chris Lattner686775d2011-07-20 06:58:45 +00003093 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003094 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3095 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3096
3097 // Determine whether the set of unexpanded parameter packs can and should
3098 // be expanded.
3099 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003100 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003101 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003102 if (getDerived().TryExpandParameterPacks(Ellipsis,
3103 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003104 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003105 Expand,
3106 RetainExpansion,
3107 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003108 return true;
3109
3110 if (!Expand) {
3111 // The transform has determined that we should perform a simple
3112 // transformation on the pack expansion, producing another pack
3113 // expansion.
3114 TemplateArgumentLoc OutPattern;
3115 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3116 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3117 return true;
3118
Douglas Gregorcded4f62011-01-14 17:04:44 +00003119 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3120 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003121 if (Out.getArgument().isNull())
3122 return true;
3123
3124 Outputs.addArgument(Out);
3125 continue;
3126 }
3127
3128 // The transform has determined that we should perform an elementwise
3129 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003130 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003131 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3132
3133 if (getDerived().TransformTemplateArgument(Pattern, Out))
3134 return true;
3135
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003136 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003137 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3138 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003139 if (Out.getArgument().isNull())
3140 return true;
3141 }
3142
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003143 Outputs.addArgument(Out);
3144 }
3145
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003146 // If we're supposed to retain a pack expansion, do so by temporarily
3147 // forgetting the partially-substituted parameter pack.
3148 if (RetainExpansion) {
3149 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3150
3151 if (getDerived().TransformTemplateArgument(Pattern, Out))
3152 return true;
3153
Douglas Gregorcded4f62011-01-14 17:04:44 +00003154 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3155 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003156 if (Out.getArgument().isNull())
3157 return true;
3158
3159 Outputs.addArgument(Out);
3160 }
Douglas Gregord3731192011-01-10 07:32:04 +00003161
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003162 continue;
3163 }
3164
3165 // The simple case:
3166 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003167 return true;
3168
3169 Outputs.addArgument(Out);
3170 }
3171
3172 return false;
3173
3174}
3175
Douglas Gregor577f75a2009-08-04 16:50:30 +00003176//===----------------------------------------------------------------------===//
3177// Type transformation
3178//===----------------------------------------------------------------------===//
3179
3180template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003181QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003182 if (getDerived().AlreadyTransformed(T))
3183 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003184
John McCalla2becad2009-10-21 00:40:46 +00003185 // Temporary workaround. All of these transformations should
3186 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003187 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3188 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003189
John McCall43fed0d2010-11-12 08:19:04 +00003190 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003191
John McCalla2becad2009-10-21 00:40:46 +00003192 if (!NewDI)
3193 return QualType();
3194
3195 return NewDI->getType();
3196}
3197
3198template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003199TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003200 // Refine the base location to the type's location.
3201 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3202 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003203 if (getDerived().AlreadyTransformed(DI->getType()))
3204 return DI;
3205
3206 TypeLocBuilder TLB;
3207
3208 TypeLoc TL = DI->getTypeLoc();
3209 TLB.reserve(TL.getFullDataSize());
3210
John McCall43fed0d2010-11-12 08:19:04 +00003211 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003212 if (Result.isNull())
3213 return 0;
3214
John McCalla93c9342009-12-07 02:54:59 +00003215 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003216}
3217
3218template<typename Derived>
3219QualType
John McCall43fed0d2010-11-12 08:19:04 +00003220TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003221 switch (T.getTypeLocClass()) {
3222#define ABSTRACT_TYPELOC(CLASS, PARENT)
3223#define TYPELOC(CLASS, PARENT) \
3224 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003225 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003226#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003227 }
Mike Stump1eb44332009-09-09 15:08:12 +00003228
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003229 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003230 return QualType();
3231}
3232
3233/// FIXME: By default, this routine adds type qualifiers only to types
3234/// that can have qualifiers, and silently suppresses those qualifiers
3235/// that are not permitted (e.g., qualifiers on reference or function
3236/// types). This is the right thing for template instantiation, but
3237/// probably not for other clients.
3238template<typename Derived>
3239QualType
3240TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003241 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003242 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003243
John McCall43fed0d2010-11-12 08:19:04 +00003244 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003245 if (Result.isNull())
3246 return QualType();
3247
3248 // Silently suppress qualifiers if the result type can't be qualified.
3249 // FIXME: this is the right thing for template instantiation, but
3250 // probably not for other clients.
3251 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003252 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003253
John McCallf85e1932011-06-15 23:02:42 +00003254 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003255 // resulting type.
3256 if (Quals.hasObjCLifetime()) {
3257 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3258 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003259 else if (Result.getObjCLifetime()) {
Douglas Gregore559ca12011-06-17 22:11:49 +00003260 // Objective-C ARC:
3261 // A lifetime qualifier applied to a substituted template parameter
3262 // overrides the lifetime qualifier from the template argument.
3263 if (const SubstTemplateTypeParmType *SubstTypeParam
3264 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3265 QualType Replacement = SubstTypeParam->getReplacementType();
3266 Qualifiers Qs = Replacement.getQualifiers();
3267 Qs.removeObjCLifetime();
3268 Replacement
3269 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3270 Qs);
3271 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3272 SubstTypeParam->getReplacedParameter(),
3273 Replacement);
3274 TLB.TypeWasModifiedSafely(Result);
3275 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003276 // Otherwise, complain about the addition of a qualifier to an
3277 // already-qualified type.
3278 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003279 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003280 << Result << R;
3281
Douglas Gregore559ca12011-06-17 22:11:49 +00003282 Quals.removeObjCLifetime();
3283 }
3284 }
3285 }
John McCall28654742010-06-05 06:41:15 +00003286 if (!Quals.empty()) {
3287 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3288 TLB.push<QualifiedTypeLoc>(Result);
3289 // No location information to preserve.
3290 }
John McCalla2becad2009-10-21 00:40:46 +00003291
3292 return Result;
3293}
3294
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003295template<typename Derived>
3296TypeLoc
3297TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3298 QualType ObjectType,
3299 NamedDecl *UnqualLookup,
3300 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003301 QualType T = TL.getType();
3302 if (getDerived().AlreadyTransformed(T))
3303 return TL;
3304
3305 TypeLocBuilder TLB;
3306 QualType Result;
3307
3308 if (isa<TemplateSpecializationType>(T)) {
3309 TemplateSpecializationTypeLoc SpecTL
3310 = cast<TemplateSpecializationTypeLoc>(TL);
3311
3312 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003313 getDerived().TransformTemplateName(SS,
3314 SpecTL.getTypePtr()->getTemplateName(),
3315 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003316 ObjectType, UnqualLookup);
3317 if (Template.isNull())
3318 return TypeLoc();
3319
3320 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3321 Template);
3322 } else if (isa<DependentTemplateSpecializationType>(T)) {
3323 DependentTemplateSpecializationTypeLoc SpecTL
3324 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3325
Douglas Gregora88f09f2011-02-28 17:23:35 +00003326 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003327 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003328 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003329 SpecTL.getNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003330 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003331 if (Template.isNull())
3332 return TypeLoc();
3333
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003334 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003335 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003336 Template,
3337 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003338 } else {
3339 // Nothing special needs to be done for these.
3340 Result = getDerived().TransformType(TLB, TL);
3341 }
3342
3343 if (Result.isNull())
3344 return TypeLoc();
3345
3346 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3347}
3348
Douglas Gregorb71d8212011-03-02 18:32:08 +00003349template<typename Derived>
3350TypeSourceInfo *
3351TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3352 QualType ObjectType,
3353 NamedDecl *UnqualLookup,
3354 CXXScopeSpec &SS) {
3355 // FIXME: Painfully copy-paste from the above!
3356
3357 QualType T = TSInfo->getType();
3358 if (getDerived().AlreadyTransformed(T))
3359 return TSInfo;
3360
3361 TypeLocBuilder TLB;
3362 QualType Result;
3363
3364 TypeLoc TL = TSInfo->getTypeLoc();
3365 if (isa<TemplateSpecializationType>(T)) {
3366 TemplateSpecializationTypeLoc SpecTL
3367 = cast<TemplateSpecializationTypeLoc>(TL);
3368
3369 TemplateName Template
3370 = getDerived().TransformTemplateName(SS,
3371 SpecTL.getTypePtr()->getTemplateName(),
3372 SpecTL.getTemplateNameLoc(),
3373 ObjectType, UnqualLookup);
3374 if (Template.isNull())
3375 return 0;
3376
3377 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3378 Template);
3379 } else if (isa<DependentTemplateSpecializationType>(T)) {
3380 DependentTemplateSpecializationTypeLoc SpecTL
3381 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3382
3383 TemplateName Template
3384 = getDerived().RebuildTemplateName(SS,
3385 *SpecTL.getTypePtr()->getIdentifier(),
3386 SpecTL.getNameLoc(),
3387 ObjectType, UnqualLookup);
3388 if (Template.isNull())
3389 return 0;
3390
3391 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3392 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003393 Template,
3394 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003395 } else {
3396 // Nothing special needs to be done for these.
3397 Result = getDerived().TransformType(TLB, TL);
3398 }
3399
3400 if (Result.isNull())
3401 return 0;
3402
3403 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3404}
3405
John McCalla2becad2009-10-21 00:40:46 +00003406template <class TyLoc> static inline
3407QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3408 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3409 NewT.setNameLoc(T.getNameLoc());
3410 return T.getType();
3411}
3412
John McCalla2becad2009-10-21 00:40:46 +00003413template<typename Derived>
3414QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003415 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003416 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3417 NewT.setBuiltinLoc(T.getBuiltinLoc());
3418 if (T.needsExtraLocalData())
3419 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3420 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003421}
Mike Stump1eb44332009-09-09 15:08:12 +00003422
Douglas Gregor577f75a2009-08-04 16:50:30 +00003423template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003424QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003425 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003426 // FIXME: recurse?
3427 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003428}
Mike Stump1eb44332009-09-09 15:08:12 +00003429
Douglas Gregor577f75a2009-08-04 16:50:30 +00003430template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003431QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003432 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003433 QualType PointeeType
3434 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003435 if (PointeeType.isNull())
3436 return QualType();
3437
3438 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003439 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003440 // A dependent pointer type 'T *' has is being transformed such
3441 // that an Objective-C class type is being replaced for 'T'. The
3442 // resulting pointer type is an ObjCObjectPointerType, not a
3443 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003444 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003445
John McCallc12c5bb2010-05-15 11:32:37 +00003446 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3447 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003448 return Result;
3449 }
John McCall43fed0d2010-11-12 08:19:04 +00003450
Douglas Gregor92e986e2010-04-22 16:44:27 +00003451 if (getDerived().AlwaysRebuild() ||
3452 PointeeType != TL.getPointeeLoc().getType()) {
3453 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3454 if (Result.isNull())
3455 return QualType();
3456 }
John McCallf85e1932011-06-15 23:02:42 +00003457
3458 // Objective-C ARC can add lifetime qualifiers to the type that we're
3459 // pointing to.
3460 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3461
Douglas Gregor92e986e2010-04-22 16:44:27 +00003462 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3463 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003464 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003465}
Mike Stump1eb44332009-09-09 15:08:12 +00003466
3467template<typename Derived>
3468QualType
John McCalla2becad2009-10-21 00:40:46 +00003469TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003470 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003471 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003472 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3473 if (PointeeType.isNull())
3474 return QualType();
3475
3476 QualType Result = TL.getType();
3477 if (getDerived().AlwaysRebuild() ||
3478 PointeeType != TL.getPointeeLoc().getType()) {
3479 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003480 TL.getSigilLoc());
3481 if (Result.isNull())
3482 return QualType();
3483 }
3484
Douglas Gregor39968ad2010-04-22 16:50:51 +00003485 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003486 NewT.setSigilLoc(TL.getSigilLoc());
3487 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003488}
3489
John McCall85737a72009-10-30 00:06:24 +00003490/// Transforms a reference type. Note that somewhat paradoxically we
3491/// don't care whether the type itself is an l-value type or an r-value
3492/// type; we only care if the type was *written* as an l-value type
3493/// or an r-value type.
3494template<typename Derived>
3495QualType
3496TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003497 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003498 const ReferenceType *T = TL.getTypePtr();
3499
3500 // Note that this works with the pointee-as-written.
3501 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3502 if (PointeeType.isNull())
3503 return QualType();
3504
3505 QualType Result = TL.getType();
3506 if (getDerived().AlwaysRebuild() ||
3507 PointeeType != T->getPointeeTypeAsWritten()) {
3508 Result = getDerived().RebuildReferenceType(PointeeType,
3509 T->isSpelledAsLValue(),
3510 TL.getSigilLoc());
3511 if (Result.isNull())
3512 return QualType();
3513 }
3514
John McCallf85e1932011-06-15 23:02:42 +00003515 // Objective-C ARC can add lifetime qualifiers to the type that we're
3516 // referring to.
3517 TLB.TypeWasModifiedSafely(
3518 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3519
John McCall85737a72009-10-30 00:06:24 +00003520 // r-value references can be rebuilt as l-value references.
3521 ReferenceTypeLoc NewTL;
3522 if (isa<LValueReferenceType>(Result))
3523 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3524 else
3525 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3526 NewTL.setSigilLoc(TL.getSigilLoc());
3527
3528 return Result;
3529}
3530
Mike Stump1eb44332009-09-09 15:08:12 +00003531template<typename Derived>
3532QualType
John McCalla2becad2009-10-21 00:40:46 +00003533TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003534 LValueReferenceTypeLoc TL) {
3535 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003536}
3537
Mike Stump1eb44332009-09-09 15:08:12 +00003538template<typename Derived>
3539QualType
John McCalla2becad2009-10-21 00:40:46 +00003540TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003541 RValueReferenceTypeLoc TL) {
3542 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003543}
Mike Stump1eb44332009-09-09 15:08:12 +00003544
Douglas Gregor577f75a2009-08-04 16:50:30 +00003545template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003546QualType
John McCalla2becad2009-10-21 00:40:46 +00003547TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003548 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003549 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003550 if (PointeeType.isNull())
3551 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003552
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003553 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3554 TypeSourceInfo* NewClsTInfo = 0;
3555 if (OldClsTInfo) {
3556 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3557 if (!NewClsTInfo)
3558 return QualType();
3559 }
3560
3561 const MemberPointerType *T = TL.getTypePtr();
3562 QualType OldClsType = QualType(T->getClass(), 0);
3563 QualType NewClsType;
3564 if (NewClsTInfo)
3565 NewClsType = NewClsTInfo->getType();
3566 else {
3567 NewClsType = getDerived().TransformType(OldClsType);
3568 if (NewClsType.isNull())
3569 return QualType();
3570 }
Mike Stump1eb44332009-09-09 15:08:12 +00003571
John McCalla2becad2009-10-21 00:40:46 +00003572 QualType Result = TL.getType();
3573 if (getDerived().AlwaysRebuild() ||
3574 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003575 NewClsType != OldClsType) {
3576 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003577 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003578 if (Result.isNull())
3579 return QualType();
3580 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003581
John McCalla2becad2009-10-21 00:40:46 +00003582 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3583 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003584 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003585
3586 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003587}
3588
Mike Stump1eb44332009-09-09 15:08:12 +00003589template<typename Derived>
3590QualType
John McCalla2becad2009-10-21 00:40:46 +00003591TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003592 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003593 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003594 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003595 if (ElementType.isNull())
3596 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003597
John McCalla2becad2009-10-21 00:40:46 +00003598 QualType Result = TL.getType();
3599 if (getDerived().AlwaysRebuild() ||
3600 ElementType != T->getElementType()) {
3601 Result = getDerived().RebuildConstantArrayType(ElementType,
3602 T->getSizeModifier(),
3603 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003604 T->getIndexTypeCVRQualifiers(),
3605 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003606 if (Result.isNull())
3607 return QualType();
3608 }
Eli Friedman457a3772012-01-25 22:19:07 +00003609
3610 // We might have either a ConstantArrayType or a VariableArrayType now:
3611 // a ConstantArrayType is allowed to have an element type which is a
3612 // VariableArrayType if the type is dependent. Fortunately, all array
3613 // types have the same location layout.
3614 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003615 NewTL.setLBracketLoc(TL.getLBracketLoc());
3616 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003617
John McCalla2becad2009-10-21 00:40:46 +00003618 Expr *Size = TL.getSizeExpr();
3619 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003620 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3621 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003622 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3623 }
3624 NewTL.setSizeExpr(Size);
3625
3626 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003627}
Mike Stump1eb44332009-09-09 15:08:12 +00003628
Douglas Gregor577f75a2009-08-04 16:50:30 +00003629template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003630QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003631 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003632 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003633 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003634 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003635 if (ElementType.isNull())
3636 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003637
John McCalla2becad2009-10-21 00:40:46 +00003638 QualType Result = TL.getType();
3639 if (getDerived().AlwaysRebuild() ||
3640 ElementType != T->getElementType()) {
3641 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003642 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003643 T->getIndexTypeCVRQualifiers(),
3644 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003645 if (Result.isNull())
3646 return QualType();
3647 }
Sean Huntc3021132010-05-05 15:23:54 +00003648
John McCalla2becad2009-10-21 00:40:46 +00003649 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3650 NewTL.setLBracketLoc(TL.getLBracketLoc());
3651 NewTL.setRBracketLoc(TL.getRBracketLoc());
3652 NewTL.setSizeExpr(0);
3653
3654 return Result;
3655}
3656
3657template<typename Derived>
3658QualType
3659TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003660 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003661 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003662 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3663 if (ElementType.isNull())
3664 return QualType();
3665
John McCall60d7b3a2010-08-24 06:29:42 +00003666 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003667 = getDerived().TransformExpr(T->getSizeExpr());
3668 if (SizeResult.isInvalid())
3669 return QualType();
3670
John McCall9ae2f072010-08-23 23:25:46 +00003671 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003672
3673 QualType Result = TL.getType();
3674 if (getDerived().AlwaysRebuild() ||
3675 ElementType != T->getElementType() ||
3676 Size != T->getSizeExpr()) {
3677 Result = getDerived().RebuildVariableArrayType(ElementType,
3678 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003679 Size,
John McCalla2becad2009-10-21 00:40:46 +00003680 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003681 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003682 if (Result.isNull())
3683 return QualType();
3684 }
Sean Huntc3021132010-05-05 15:23:54 +00003685
John McCalla2becad2009-10-21 00:40:46 +00003686 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3687 NewTL.setLBracketLoc(TL.getLBracketLoc());
3688 NewTL.setRBracketLoc(TL.getRBracketLoc());
3689 NewTL.setSizeExpr(Size);
3690
3691 return Result;
3692}
3693
3694template<typename Derived>
3695QualType
3696TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003697 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003698 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003699 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3700 if (ElementType.isNull())
3701 return QualType();
3702
Richard Smithf6702a32011-12-20 02:08:33 +00003703 // Array bounds are constant expressions.
3704 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3705 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003706
John McCall3b657512011-01-19 10:06:00 +00003707 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3708 Expr *origSize = TL.getSizeExpr();
3709 if (!origSize) origSize = T->getSizeExpr();
3710
3711 ExprResult sizeResult
3712 = getDerived().TransformExpr(origSize);
3713 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003714 return QualType();
3715
John McCall3b657512011-01-19 10:06:00 +00003716 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003717
3718 QualType Result = TL.getType();
3719 if (getDerived().AlwaysRebuild() ||
3720 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003721 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003722 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3723 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003724 size,
John McCalla2becad2009-10-21 00:40:46 +00003725 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003726 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003727 if (Result.isNull())
3728 return QualType();
3729 }
John McCalla2becad2009-10-21 00:40:46 +00003730
3731 // We might have any sort of array type now, but fortunately they
3732 // all have the same location layout.
3733 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3734 NewTL.setLBracketLoc(TL.getLBracketLoc());
3735 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003736 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003737
3738 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003739}
Mike Stump1eb44332009-09-09 15:08:12 +00003740
3741template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003742QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003743 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003744 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003745 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003746
3747 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003748 QualType ElementType = getDerived().TransformType(T->getElementType());
3749 if (ElementType.isNull())
3750 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003751
Richard Smithf6702a32011-12-20 02:08:33 +00003752 // Vector sizes are constant expressions.
3753 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3754 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003755
John McCall60d7b3a2010-08-24 06:29:42 +00003756 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003757 if (Size.isInvalid())
3758 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003759
John McCalla2becad2009-10-21 00:40:46 +00003760 QualType Result = TL.getType();
3761 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003762 ElementType != T->getElementType() ||
3763 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003764 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003765 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003766 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003767 if (Result.isNull())
3768 return QualType();
3769 }
John McCalla2becad2009-10-21 00:40:46 +00003770
3771 // Result might be dependent or not.
3772 if (isa<DependentSizedExtVectorType>(Result)) {
3773 DependentSizedExtVectorTypeLoc NewTL
3774 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3775 NewTL.setNameLoc(TL.getNameLoc());
3776 } else {
3777 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3778 NewTL.setNameLoc(TL.getNameLoc());
3779 }
3780
3781 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003782}
Mike Stump1eb44332009-09-09 15:08:12 +00003783
3784template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003785QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003786 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003787 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003788 QualType ElementType = getDerived().TransformType(T->getElementType());
3789 if (ElementType.isNull())
3790 return QualType();
3791
John McCalla2becad2009-10-21 00:40:46 +00003792 QualType Result = TL.getType();
3793 if (getDerived().AlwaysRebuild() ||
3794 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003795 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003796 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003797 if (Result.isNull())
3798 return QualType();
3799 }
Sean Huntc3021132010-05-05 15:23:54 +00003800
John McCalla2becad2009-10-21 00:40:46 +00003801 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3802 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003803
John McCalla2becad2009-10-21 00:40:46 +00003804 return Result;
3805}
3806
3807template<typename Derived>
3808QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003809 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003810 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003811 QualType ElementType = getDerived().TransformType(T->getElementType());
3812 if (ElementType.isNull())
3813 return QualType();
3814
3815 QualType Result = TL.getType();
3816 if (getDerived().AlwaysRebuild() ||
3817 ElementType != T->getElementType()) {
3818 Result = getDerived().RebuildExtVectorType(ElementType,
3819 T->getNumElements(),
3820 /*FIXME*/ SourceLocation());
3821 if (Result.isNull())
3822 return QualType();
3823 }
Sean Huntc3021132010-05-05 15:23:54 +00003824
John McCalla2becad2009-10-21 00:40:46 +00003825 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3826 NewTL.setNameLoc(TL.getNameLoc());
3827
3828 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003829}
Mike Stump1eb44332009-09-09 15:08:12 +00003830
3831template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003832ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003833TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003834 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003835 llvm::Optional<unsigned> NumExpansions,
3836 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003837 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003838 TypeSourceInfo *NewDI = 0;
3839
3840 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3841 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003842 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003843 TypeLoc OldTL = OldDI->getTypeLoc();
3844 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3845
3846 TypeLocBuilder TLB;
3847 TypeLoc NewTL = OldDI->getTypeLoc();
3848 TLB.reserve(NewTL.getFullDataSize());
3849
3850 QualType Result = getDerived().TransformType(TLB,
3851 OldExpansionTL.getPatternLoc());
3852 if (Result.isNull())
3853 return 0;
3854
3855 Result = RebuildPackExpansionType(Result,
3856 OldExpansionTL.getPatternLoc().getSourceRange(),
3857 OldExpansionTL.getEllipsisLoc(),
3858 NumExpansions);
3859 if (Result.isNull())
3860 return 0;
3861
3862 PackExpansionTypeLoc NewExpansionTL
3863 = TLB.push<PackExpansionTypeLoc>(Result);
3864 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3865 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3866 } else
3867 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003868 if (!NewDI)
3869 return 0;
3870
John McCallfb44de92011-05-01 22:35:37 +00003871 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003872 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003873
3874 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3875 OldParm->getDeclContext(),
3876 OldParm->getInnerLocStart(),
3877 OldParm->getLocation(),
3878 OldParm->getIdentifier(),
3879 NewDI->getType(),
3880 NewDI,
3881 OldParm->getStorageClass(),
3882 OldParm->getStorageClassAsWritten(),
3883 /* DefArg */ NULL);
3884 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3885 OldParm->getFunctionScopeIndex() + indexAdjustment);
3886 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003887}
3888
3889template<typename Derived>
3890bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003891 TransformFunctionTypeParams(SourceLocation Loc,
3892 ParmVarDecl **Params, unsigned NumParams,
3893 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003894 SmallVectorImpl<QualType> &OutParamTypes,
3895 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003896 int indexAdjustment = 0;
3897
Douglas Gregora009b592011-01-07 00:20:55 +00003898 for (unsigned i = 0; i != NumParams; ++i) {
3899 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003900 assert(OldParm->getFunctionScopeIndex() == i);
3901
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003902 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003903 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003904 if (OldParm->isParameterPack()) {
3905 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003906 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003907
Douglas Gregor603cfb42011-01-05 23:12:31 +00003908 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003909 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3910 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3911 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3912 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003913 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3914
Douglas Gregor603cfb42011-01-05 23:12:31 +00003915 // Determine whether we should expand the parameter packs.
3916 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003917 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003918 llvm::Optional<unsigned> OrigNumExpansions
3919 = ExpansionTL.getTypePtr()->getNumExpansions();
3920 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003921 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3922 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003923 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003924 ShouldExpand,
3925 RetainExpansion,
3926 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003927 return true;
3928 }
3929
3930 if (ShouldExpand) {
3931 // Expand the function parameter pack into multiple, separate
3932 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003933 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003934 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003935 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3936 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003937 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003938 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003939 OrigNumExpansions,
3940 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003941 if (!NewParm)
3942 return true;
3943
Douglas Gregora009b592011-01-07 00:20:55 +00003944 OutParamTypes.push_back(NewParm->getType());
3945 if (PVars)
3946 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003947 }
Douglas Gregord3731192011-01-10 07:32:04 +00003948
3949 // If we're supposed to retain a pack expansion, do so by temporarily
3950 // forgetting the partially-substituted parameter pack.
3951 if (RetainExpansion) {
3952 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3953 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003954 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003955 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003956 OrigNumExpansions,
3957 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00003958 if (!NewParm)
3959 return true;
3960
3961 OutParamTypes.push_back(NewParm->getType());
3962 if (PVars)
3963 PVars->push_back(NewParm);
3964 }
3965
John McCallfb44de92011-05-01 22:35:37 +00003966 // The next parameter should have the same adjustment as the
3967 // last thing we pushed, but we post-incremented indexAdjustment
3968 // on every push. Also, if we push nothing, the adjustment should
3969 // go down by one.
3970 indexAdjustment--;
3971
Douglas Gregor603cfb42011-01-05 23:12:31 +00003972 // We're done with the pack expansion.
3973 continue;
3974 }
3975
3976 // We'll substitute the parameter now without expanding the pack
3977 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00003978 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3979 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003980 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003981 NumExpansions,
3982 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003983 } else {
3984 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003985 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003986 llvm::Optional<unsigned>(),
3987 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003988 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00003989
John McCall21ef0fa2010-03-11 09:03:00 +00003990 if (!NewParm)
3991 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003992
Douglas Gregora009b592011-01-07 00:20:55 +00003993 OutParamTypes.push_back(NewParm->getType());
3994 if (PVars)
3995 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003996 continue;
3997 }
John McCall21ef0fa2010-03-11 09:03:00 +00003998
3999 // Deal with the possibility that we don't have a parameter
4000 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004001 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004002 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004003 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004004 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004005 if (const PackExpansionType *Expansion
4006 = dyn_cast<PackExpansionType>(OldType)) {
4007 // We have a function parameter pack that may need to be expanded.
4008 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004009 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004010 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4011
4012 // Determine whether we should expand the parameter packs.
4013 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004014 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004015 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00004016 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00004017 ShouldExpand,
4018 RetainExpansion,
4019 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004020 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004021 }
4022
4023 if (ShouldExpand) {
4024 // Expand the function parameter pack into multiple, separate
4025 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004026 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004027 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4028 QualType NewType = getDerived().TransformType(Pattern);
4029 if (NewType.isNull())
4030 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004031
Douglas Gregora009b592011-01-07 00:20:55 +00004032 OutParamTypes.push_back(NewType);
4033 if (PVars)
4034 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004035 }
4036
4037 // We're done with the pack expansion.
4038 continue;
4039 }
4040
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004041 // If we're supposed to retain a pack expansion, do so by temporarily
4042 // forgetting the partially-substituted parameter pack.
4043 if (RetainExpansion) {
4044 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4045 QualType NewType = getDerived().TransformType(Pattern);
4046 if (NewType.isNull())
4047 return true;
4048
4049 OutParamTypes.push_back(NewType);
4050 if (PVars)
4051 PVars->push_back(0);
4052 }
Douglas Gregord3731192011-01-10 07:32:04 +00004053
Douglas Gregor603cfb42011-01-05 23:12:31 +00004054 // We'll substitute the parameter now without expanding the pack
4055 // expansion.
4056 OldType = Expansion->getPattern();
4057 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004058 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4059 NewType = getDerived().TransformType(OldType);
4060 } else {
4061 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004062 }
4063
Douglas Gregor603cfb42011-01-05 23:12:31 +00004064 if (NewType.isNull())
4065 return true;
4066
4067 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004068 NewType = getSema().Context.getPackExpansionType(NewType,
4069 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004070
Douglas Gregora009b592011-01-07 00:20:55 +00004071 OutParamTypes.push_back(NewType);
4072 if (PVars)
4073 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004074 }
4075
John McCallfb44de92011-05-01 22:35:37 +00004076#ifndef NDEBUG
4077 if (PVars) {
4078 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4079 if (ParmVarDecl *parm = (*PVars)[i])
4080 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004081 }
John McCallfb44de92011-05-01 22:35:37 +00004082#endif
4083
4084 return false;
4085}
John McCall21ef0fa2010-03-11 09:03:00 +00004086
4087template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004088QualType
John McCalla2becad2009-10-21 00:40:46 +00004089TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004090 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004091 // Transform the parameters and return type.
4092 //
4093 // We instantiate in source order, with the return type first followed by
4094 // the parameters, because users tend to expect this (even if they shouldn't
4095 // rely on it!).
4096 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00004097 // When the function has a trailing return type, we instantiate the
4098 // parameters before the return type, since the return type can then refer
4099 // to the parameters themselves (via decltype, sizeof, etc.).
4100 //
Chris Lattner686775d2011-07-20 06:58:45 +00004101 SmallVector<QualType, 4> ParamTypes;
4102 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004103 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004104
Douglas Gregordab60ad2010-10-01 18:44:50 +00004105 QualType ResultType;
4106
4107 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00004108 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4109 TL.getParmArray(),
4110 TL.getNumArgs(),
4111 TL.getTypePtr()->arg_type_begin(),
4112 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004113 return QualType();
4114
4115 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4116 if (ResultType.isNull())
4117 return QualType();
4118 }
4119 else {
4120 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4121 if (ResultType.isNull())
4122 return QualType();
4123
Douglas Gregora009b592011-01-07 00:20:55 +00004124 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4125 TL.getParmArray(),
4126 TL.getNumArgs(),
4127 TL.getTypePtr()->arg_type_begin(),
4128 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004129 return QualType();
4130 }
4131
John McCalla2becad2009-10-21 00:40:46 +00004132 QualType Result = TL.getType();
4133 if (getDerived().AlwaysRebuild() ||
4134 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004135 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004136 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4137 Result = getDerived().RebuildFunctionProtoType(ResultType,
4138 ParamTypes.data(),
4139 ParamTypes.size(),
4140 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004141 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004142 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004143 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004144 if (Result.isNull())
4145 return QualType();
4146 }
Mike Stump1eb44332009-09-09 15:08:12 +00004147
John McCalla2becad2009-10-21 00:40:46 +00004148 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(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(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004152 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4153 NewTL.setArg(i, ParamDecls[i]);
4154
4155 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004156}
Mike Stump1eb44332009-09-09 15:08:12 +00004157
Douglas Gregor577f75a2009-08-04 16:50:30 +00004158template<typename Derived>
4159QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004160 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004161 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004162 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004163 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4164 if (ResultType.isNull())
4165 return QualType();
4166
4167 QualType Result = TL.getType();
4168 if (getDerived().AlwaysRebuild() ||
4169 ResultType != T->getResultType())
4170 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4171
4172 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004173 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4174 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004175 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004176
4177 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004178}
Mike Stump1eb44332009-09-09 15:08:12 +00004179
John McCalled976492009-12-04 22:46:56 +00004180template<typename Derived> QualType
4181TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004182 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004183 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004184 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004185 if (!D)
4186 return QualType();
4187
4188 QualType Result = TL.getType();
4189 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4190 Result = getDerived().RebuildUnresolvedUsingType(D);
4191 if (Result.isNull())
4192 return QualType();
4193 }
4194
4195 // We might get an arbitrary type spec type back. We should at
4196 // least always get a type spec type, though.
4197 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4198 NewTL.setNameLoc(TL.getNameLoc());
4199
4200 return Result;
4201}
4202
Douglas Gregor577f75a2009-08-04 16:50:30 +00004203template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004204QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004205 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004206 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004207 TypedefNameDecl *Typedef
4208 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4209 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004210 if (!Typedef)
4211 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004212
John McCalla2becad2009-10-21 00:40:46 +00004213 QualType Result = TL.getType();
4214 if (getDerived().AlwaysRebuild() ||
4215 Typedef != T->getDecl()) {
4216 Result = getDerived().RebuildTypedefType(Typedef);
4217 if (Result.isNull())
4218 return QualType();
4219 }
Mike Stump1eb44332009-09-09 15:08:12 +00004220
John McCalla2becad2009-10-21 00:40:46 +00004221 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4222 NewTL.setNameLoc(TL.getNameLoc());
4223
4224 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004225}
Mike Stump1eb44332009-09-09 15:08:12 +00004226
Douglas Gregor577f75a2009-08-04 16:50:30 +00004227template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004228QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004229 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004230 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004231 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004232
John McCall60d7b3a2010-08-24 06:29:42 +00004233 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004234 if (E.isInvalid())
4235 return QualType();
4236
John McCalla2becad2009-10-21 00:40:46 +00004237 QualType Result = TL.getType();
4238 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004239 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004240 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004241 if (Result.isNull())
4242 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004243 }
John McCalla2becad2009-10-21 00:40:46 +00004244 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004245
John McCalla2becad2009-10-21 00:40:46 +00004246 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004247 NewTL.setTypeofLoc(TL.getTypeofLoc());
4248 NewTL.setLParenLoc(TL.getLParenLoc());
4249 NewTL.setRParenLoc(TL.getRParenLoc());
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>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004256 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004257 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4258 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4259 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004260 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004261
John McCalla2becad2009-10-21 00:40:46 +00004262 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004263 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4264 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004265 if (Result.isNull())
4266 return QualType();
4267 }
Mike Stump1eb44332009-09-09 15:08:12 +00004268
John McCalla2becad2009-10-21 00:40:46 +00004269 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004270 NewTL.setTypeofLoc(TL.getTypeofLoc());
4271 NewTL.setLParenLoc(TL.getLParenLoc());
4272 NewTL.setRParenLoc(TL.getRParenLoc());
4273 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004274
4275 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004276}
Mike Stump1eb44332009-09-09 15:08:12 +00004277
4278template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004279QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004280 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004281 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004282
Douglas Gregor670444e2009-08-04 22:27:00 +00004283 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004284 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004285
John McCall60d7b3a2010-08-24 06:29:42 +00004286 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004287 if (E.isInvalid())
4288 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004289
John McCalla2becad2009-10-21 00:40:46 +00004290 QualType Result = TL.getType();
4291 if (getDerived().AlwaysRebuild() ||
4292 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004293 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004294 if (Result.isNull())
4295 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004296 }
John McCalla2becad2009-10-21 00:40:46 +00004297 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004298
John McCalla2becad2009-10-21 00:40:46 +00004299 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4300 NewTL.setNameLoc(TL.getNameLoc());
4301
4302 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004303}
4304
4305template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004306QualType TreeTransform<Derived>::TransformUnaryTransformType(
4307 TypeLocBuilder &TLB,
4308 UnaryTransformTypeLoc TL) {
4309 QualType Result = TL.getType();
4310 if (Result->isDependentType()) {
4311 const UnaryTransformType *T = TL.getTypePtr();
4312 QualType NewBase =
4313 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4314 Result = getDerived().RebuildUnaryTransformType(NewBase,
4315 T->getUTTKind(),
4316 TL.getKWLoc());
4317 if (Result.isNull())
4318 return QualType();
4319 }
4320
4321 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4322 NewTL.setKWLoc(TL.getKWLoc());
4323 NewTL.setParensRange(TL.getParensRange());
4324 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4325 return Result;
4326}
4327
4328template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004329QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4330 AutoTypeLoc TL) {
4331 const AutoType *T = TL.getTypePtr();
4332 QualType OldDeduced = T->getDeducedType();
4333 QualType NewDeduced;
4334 if (!OldDeduced.isNull()) {
4335 NewDeduced = getDerived().TransformType(OldDeduced);
4336 if (NewDeduced.isNull())
4337 return QualType();
4338 }
4339
4340 QualType Result = TL.getType();
4341 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4342 Result = getDerived().RebuildAutoType(NewDeduced);
4343 if (Result.isNull())
4344 return QualType();
4345 }
4346
4347 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4348 NewTL.setNameLoc(TL.getNameLoc());
4349
4350 return Result;
4351}
4352
4353template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004354QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004355 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004356 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004357 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004358 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4359 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004360 if (!Record)
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 Record != T->getDecl()) {
4366 Result = getDerived().RebuildRecordType(Record);
4367 if (Result.isNull())
4368 return QualType();
4369 }
Mike Stump1eb44332009-09-09 15:08:12 +00004370
John McCalla2becad2009-10-21 00:40:46 +00004371 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4372 NewTL.setNameLoc(TL.getNameLoc());
4373
4374 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004375}
Mike Stump1eb44332009-09-09 15:08:12 +00004376
4377template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004378QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004379 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004380 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004381 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004382 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4383 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004384 if (!Enum)
4385 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004386
John McCalla2becad2009-10-21 00:40:46 +00004387 QualType Result = TL.getType();
4388 if (getDerived().AlwaysRebuild() ||
4389 Enum != T->getDecl()) {
4390 Result = getDerived().RebuildEnumType(Enum);
4391 if (Result.isNull())
4392 return QualType();
4393 }
Mike Stump1eb44332009-09-09 15:08:12 +00004394
John McCalla2becad2009-10-21 00:40:46 +00004395 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4396 NewTL.setNameLoc(TL.getNameLoc());
4397
4398 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004399}
John McCall7da24312009-09-05 00:15:47 +00004400
John McCall3cb0ebd2010-03-10 03:28:59 +00004401template<typename Derived>
4402QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4403 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004404 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004405 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4406 TL.getTypePtr()->getDecl());
4407 if (!D) return QualType();
4408
4409 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4410 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4411 return T;
4412}
4413
Douglas Gregor577f75a2009-08-04 16:50:30 +00004414template<typename Derived>
4415QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004416 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004417 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004418 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004419}
4420
Mike Stump1eb44332009-09-09 15:08:12 +00004421template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004422QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004423 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004424 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004425 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4426
4427 // Substitute into the replacement type, which itself might involve something
4428 // that needs to be transformed. This only tends to occur with default
4429 // template arguments of template template parameters.
4430 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4431 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4432 if (Replacement.isNull())
4433 return QualType();
4434
4435 // Always canonicalize the replacement type.
4436 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4437 QualType Result
4438 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4439 Replacement);
4440
4441 // Propagate type-source information.
4442 SubstTemplateTypeParmTypeLoc NewTL
4443 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4444 NewTL.setNameLoc(TL.getNameLoc());
4445 return Result;
4446
John McCall49a832b2009-10-18 09:09:24 +00004447}
4448
4449template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004450QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4451 TypeLocBuilder &TLB,
4452 SubstTemplateTypeParmPackTypeLoc TL) {
4453 return TransformTypeSpecType(TLB, TL);
4454}
4455
4456template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004457QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004458 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004459 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004460 const TemplateSpecializationType *T = TL.getTypePtr();
4461
Douglas Gregor1d752d72011-03-02 18:46:51 +00004462 // The nested-name-specifier never matters in a TemplateSpecializationType,
4463 // because we can't have a dependent nested-name-specifier anyway.
4464 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004465 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004466 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4467 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004468 if (Template.isNull())
4469 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004470
John McCall43fed0d2010-11-12 08:19:04 +00004471 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4472}
4473
Eli Friedmanb001de72011-10-06 23:00:33 +00004474template<typename Derived>
4475QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4476 AtomicTypeLoc TL) {
4477 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4478 if (ValueType.isNull())
4479 return QualType();
4480
4481 QualType Result = TL.getType();
4482 if (getDerived().AlwaysRebuild() ||
4483 ValueType != TL.getValueLoc().getType()) {
4484 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4485 if (Result.isNull())
4486 return QualType();
4487 }
4488
4489 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4490 NewTL.setKWLoc(TL.getKWLoc());
4491 NewTL.setLParenLoc(TL.getLParenLoc());
4492 NewTL.setRParenLoc(TL.getRParenLoc());
4493
4494 return Result;
4495}
4496
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004497namespace {
4498 /// \brief Simple iterator that traverses the template arguments in a
4499 /// container that provides a \c getArgLoc() member function.
4500 ///
4501 /// This iterator is intended to be used with the iterator form of
4502 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4503 template<typename ArgLocContainer>
4504 class TemplateArgumentLocContainerIterator {
4505 ArgLocContainer *Container;
4506 unsigned Index;
4507
4508 public:
4509 typedef TemplateArgumentLoc value_type;
4510 typedef TemplateArgumentLoc reference;
4511 typedef int difference_type;
4512 typedef std::input_iterator_tag iterator_category;
4513
4514 class pointer {
4515 TemplateArgumentLoc Arg;
4516
4517 public:
4518 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4519
4520 const TemplateArgumentLoc *operator->() const {
4521 return &Arg;
4522 }
4523 };
4524
4525
4526 TemplateArgumentLocContainerIterator() {}
4527
4528 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4529 unsigned Index)
4530 : Container(&Container), Index(Index) { }
4531
4532 TemplateArgumentLocContainerIterator &operator++() {
4533 ++Index;
4534 return *this;
4535 }
4536
4537 TemplateArgumentLocContainerIterator operator++(int) {
4538 TemplateArgumentLocContainerIterator Old(*this);
4539 ++(*this);
4540 return Old;
4541 }
4542
4543 TemplateArgumentLoc operator*() const {
4544 return Container->getArgLoc(Index);
4545 }
4546
4547 pointer operator->() const {
4548 return pointer(Container->getArgLoc(Index));
4549 }
4550
4551 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004552 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004553 return X.Container == Y.Container && X.Index == Y.Index;
4554 }
4555
4556 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004557 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004558 return !(X == Y);
4559 }
4560 };
4561}
4562
4563
John McCall43fed0d2010-11-12 08:19:04 +00004564template <typename Derived>
4565QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4566 TypeLocBuilder &TLB,
4567 TemplateSpecializationTypeLoc TL,
4568 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004569 TemplateArgumentListInfo NewTemplateArgs;
4570 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4571 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004572 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4573 ArgIterator;
4574 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4575 ArgIterator(TL, TL.getNumArgs()),
4576 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004577 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004578
John McCall833ca992009-10-29 08:12:44 +00004579 // FIXME: maybe don't rebuild if all the template arguments are the same.
4580
4581 QualType Result =
4582 getDerived().RebuildTemplateSpecializationType(Template,
4583 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004584 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004585
4586 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004587 // Specializations of template template parameters are represented as
4588 // TemplateSpecializationTypes, and substitution of type alias templates
4589 // within a dependent context can transform them into
4590 // DependentTemplateSpecializationTypes.
4591 if (isa<DependentTemplateSpecializationType>(Result)) {
4592 DependentTemplateSpecializationTypeLoc NewTL
4593 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4594 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4595 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4596 NewTL.setNameLoc(TL.getTemplateNameLoc());
4597 NewTL.setLAngleLoc(TL.getLAngleLoc());
4598 NewTL.setRAngleLoc(TL.getRAngleLoc());
4599 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4600 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4601 return Result;
4602 }
4603
John McCall833ca992009-10-29 08:12:44 +00004604 TemplateSpecializationTypeLoc NewTL
4605 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4606 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4607 NewTL.setLAngleLoc(TL.getLAngleLoc());
4608 NewTL.setRAngleLoc(TL.getRAngleLoc());
4609 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4610 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004611 }
Mike Stump1eb44332009-09-09 15:08:12 +00004612
John McCall833ca992009-10-29 08:12:44 +00004613 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004614}
Mike Stump1eb44332009-09-09 15:08:12 +00004615
Douglas Gregora88f09f2011-02-28 17:23:35 +00004616template <typename Derived>
4617QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4618 TypeLocBuilder &TLB,
4619 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004620 TemplateName Template,
4621 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004622 TemplateArgumentListInfo NewTemplateArgs;
4623 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4624 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4625 typedef TemplateArgumentLocContainerIterator<
4626 DependentTemplateSpecializationTypeLoc> ArgIterator;
4627 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4628 ArgIterator(TL, TL.getNumArgs()),
4629 NewTemplateArgs))
4630 return QualType();
4631
4632 // FIXME: maybe don't rebuild if all the template arguments are the same.
4633
4634 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4635 QualType Result
4636 = getSema().Context.getDependentTemplateSpecializationType(
4637 TL.getTypePtr()->getKeyword(),
4638 DTN->getQualifier(),
4639 DTN->getIdentifier(),
4640 NewTemplateArgs);
4641
4642 DependentTemplateSpecializationTypeLoc NewTL
4643 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4644 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004645
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004646 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregora88f09f2011-02-28 17:23:35 +00004647 NewTL.setNameLoc(TL.getNameLoc());
4648 NewTL.setLAngleLoc(TL.getLAngleLoc());
4649 NewTL.setRAngleLoc(TL.getRAngleLoc());
4650 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4651 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4652 return Result;
4653 }
4654
4655 QualType Result
4656 = getDerived().RebuildTemplateSpecializationType(Template,
4657 TL.getNameLoc(),
4658 NewTemplateArgs);
4659
4660 if (!Result.isNull()) {
4661 /// FIXME: Wrap this in an elaborated-type-specifier?
4662 TemplateSpecializationTypeLoc NewTL
4663 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4664 NewTL.setTemplateNameLoc(TL.getNameLoc());
4665 NewTL.setLAngleLoc(TL.getLAngleLoc());
4666 NewTL.setRAngleLoc(TL.getRAngleLoc());
4667 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4668 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4669 }
4670
4671 return Result;
4672}
4673
Mike Stump1eb44332009-09-09 15:08:12 +00004674template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004675QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004676TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004677 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004678 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004679
Douglas Gregor9e876872011-03-01 18:12:44 +00004680 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004681 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004682 if (TL.getQualifierLoc()) {
4683 QualifierLoc
4684 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4685 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004686 return QualType();
4687 }
Mike Stump1eb44332009-09-09 15:08:12 +00004688
John McCall43fed0d2010-11-12 08:19:04 +00004689 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4690 if (NamedT.isNull())
4691 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004692
Richard Smith3e4c6c42011-05-05 21:57:07 +00004693 // C++0x [dcl.type.elab]p2:
4694 // If the identifier resolves to a typedef-name or the simple-template-id
4695 // resolves to an alias template specialization, the
4696 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004697 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4698 if (const TemplateSpecializationType *TST =
4699 NamedT->getAs<TemplateSpecializationType>()) {
4700 TemplateName Template = TST->getTemplateName();
4701 if (TypeAliasTemplateDecl *TAT =
4702 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4703 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4704 diag::err_tag_reference_non_tag) << 4;
4705 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4706 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004707 }
4708 }
4709
John McCalla2becad2009-10-21 00:40:46 +00004710 QualType Result = TL.getType();
4711 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004712 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004713 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00004714 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004715 T->getKeyword(),
4716 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004717 if (Result.isNull())
4718 return QualType();
4719 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004720
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004721 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004722 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004723 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004724 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004725}
Mike Stump1eb44332009-09-09 15:08:12 +00004726
4727template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004728QualType TreeTransform<Derived>::TransformAttributedType(
4729 TypeLocBuilder &TLB,
4730 AttributedTypeLoc TL) {
4731 const AttributedType *oldType = TL.getTypePtr();
4732 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4733 if (modifiedType.isNull())
4734 return QualType();
4735
4736 QualType result = TL.getType();
4737
4738 // FIXME: dependent operand expressions?
4739 if (getDerived().AlwaysRebuild() ||
4740 modifiedType != oldType->getModifiedType()) {
4741 // TODO: this is really lame; we should really be rebuilding the
4742 // equivalent type from first principles.
4743 QualType equivalentType
4744 = getDerived().TransformType(oldType->getEquivalentType());
4745 if (equivalentType.isNull())
4746 return QualType();
4747 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4748 modifiedType,
4749 equivalentType);
4750 }
4751
4752 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4753 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4754 if (TL.hasAttrOperand())
4755 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4756 if (TL.hasAttrExprOperand())
4757 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4758 else if (TL.hasAttrEnumOperand())
4759 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4760
4761 return result;
4762}
4763
4764template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004765QualType
4766TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4767 ParenTypeLoc TL) {
4768 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4769 if (Inner.isNull())
4770 return QualType();
4771
4772 QualType Result = TL.getType();
4773 if (getDerived().AlwaysRebuild() ||
4774 Inner != TL.getInnerLoc().getType()) {
4775 Result = getDerived().RebuildParenType(Inner);
4776 if (Result.isNull())
4777 return QualType();
4778 }
4779
4780 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4781 NewTL.setLParenLoc(TL.getLParenLoc());
4782 NewTL.setRParenLoc(TL.getRParenLoc());
4783 return Result;
4784}
4785
4786template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004787QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004788 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004789 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004790
Douglas Gregor2494dd02011-03-01 01:34:45 +00004791 NestedNameSpecifierLoc QualifierLoc
4792 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4793 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004794 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004795
John McCall33500952010-06-11 00:33:02 +00004796 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004797 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCall33500952010-06-11 00:33:02 +00004798 TL.getKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004799 QualifierLoc,
4800 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004801 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004802 if (Result.isNull())
4803 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004804
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004805 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4806 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004807 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4808
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004809 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4810 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004811 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004812 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004813 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4814 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004815 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004816 NewTL.setNameLoc(TL.getNameLoc());
4817 }
John McCalla2becad2009-10-21 00:40:46 +00004818 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004819}
Mike Stump1eb44332009-09-09 15:08:12 +00004820
Douglas Gregor577f75a2009-08-04 16:50:30 +00004821template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004822QualType TreeTransform<Derived>::
4823 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004824 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004825 NestedNameSpecifierLoc QualifierLoc;
4826 if (TL.getQualifierLoc()) {
4827 QualifierLoc
4828 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4829 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004830 return QualType();
4831 }
4832
John McCall43fed0d2010-11-12 08:19:04 +00004833 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004834 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004835}
4836
4837template<typename Derived>
4838QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004839TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4840 DependentTemplateSpecializationTypeLoc TL,
4841 NestedNameSpecifierLoc QualifierLoc) {
4842 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4843
4844 TemplateArgumentListInfo NewTemplateArgs;
4845 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4846 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4847
4848 typedef TemplateArgumentLocContainerIterator<
4849 DependentTemplateSpecializationTypeLoc> ArgIterator;
4850 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4851 ArgIterator(TL, TL.getNumArgs()),
4852 NewTemplateArgs))
4853 return QualType();
4854
4855 QualType Result
4856 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4857 QualifierLoc,
4858 T->getIdentifier(),
4859 TL.getNameLoc(),
4860 NewTemplateArgs);
4861 if (Result.isNull())
4862 return QualType();
4863
4864 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4865 QualType NamedT = ElabT->getNamedType();
4866
4867 // Copy information relevant to the template specialization.
4868 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004869 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004870 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004871 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4872 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004873 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004874 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004875
4876 // Copy information relevant to the elaborated type.
4877 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4878 NewTL.setKeywordLoc(TL.getKeywordLoc());
4879 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004880 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4881 DependentTemplateSpecializationTypeLoc SpecTL
4882 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor944cdae2011-03-07 15:13:34 +00004883 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004884 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004885 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004886 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4887 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004888 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004889 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004890 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004891 TemplateSpecializationTypeLoc SpecTL
4892 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004893 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004894 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4895 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004896 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004897 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004898 }
4899 return Result;
4900}
4901
4902template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004903QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4904 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004905 QualType Pattern
4906 = getDerived().TransformType(TLB, TL.getPatternLoc());
4907 if (Pattern.isNull())
4908 return QualType();
4909
4910 QualType Result = TL.getType();
4911 if (getDerived().AlwaysRebuild() ||
4912 Pattern != TL.getPatternLoc().getType()) {
4913 Result = getDerived().RebuildPackExpansionType(Pattern,
4914 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004915 TL.getEllipsisLoc(),
4916 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004917 if (Result.isNull())
4918 return QualType();
4919 }
4920
4921 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4922 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4923 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004924}
4925
4926template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004927QualType
4928TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004929 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004930 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004931 TLB.pushFullCopy(TL);
4932 return TL.getType();
4933}
4934
4935template<typename Derived>
4936QualType
4937TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004938 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004939 // ObjCObjectType is never dependent.
4940 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004941 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004942}
Mike Stump1eb44332009-09-09 15:08:12 +00004943
4944template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004945QualType
4946TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004947 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004948 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004949 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004950 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004951}
4952
Douglas Gregor577f75a2009-08-04 16:50:30 +00004953//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004954// Statement transformation
4955//===----------------------------------------------------------------------===//
4956template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004957StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004958TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004959 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004960}
4961
4962template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004963StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004964TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4965 return getDerived().TransformCompoundStmt(S, false);
4966}
4967
4968template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004969StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004970TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004971 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004972 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004973 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004974 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004975 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4976 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004977 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004978 if (Result.isInvalid()) {
4979 // Immediately fail if this was a DeclStmt, since it's very
4980 // likely that this will cause problems for future statements.
4981 if (isa<DeclStmt>(*B))
4982 return StmtError();
4983
4984 // Otherwise, just keep processing substatements and fail later.
4985 SubStmtInvalid = true;
4986 continue;
4987 }
Mike Stump1eb44332009-09-09 15:08:12 +00004988
Douglas Gregor43959a92009-08-20 07:17:43 +00004989 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4990 Statements.push_back(Result.takeAs<Stmt>());
4991 }
Mike Stump1eb44332009-09-09 15:08:12 +00004992
John McCall7114cba2010-08-27 19:56:05 +00004993 if (SubStmtInvalid)
4994 return StmtError();
4995
Douglas Gregor43959a92009-08-20 07:17:43 +00004996 if (!getDerived().AlwaysRebuild() &&
4997 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004998 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004999
5000 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
5001 move_arg(Statements),
5002 S->getRBracLoc(),
5003 IsStmtExpr);
5004}
Mike Stump1eb44332009-09-09 15:08:12 +00005005
Douglas Gregor43959a92009-08-20 07:17:43 +00005006template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005007StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005008TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005009 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005010 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005011 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5012 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005013
Eli Friedman264c1f82009-11-19 03:14:00 +00005014 // Transform the left-hand case value.
5015 LHS = getDerived().TransformExpr(S->getLHS());
5016 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005017 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005018
Eli Friedman264c1f82009-11-19 03:14:00 +00005019 // Transform the right-hand case value (for the GNU case-range extension).
5020 RHS = getDerived().TransformExpr(S->getRHS());
5021 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005022 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005023 }
Mike Stump1eb44332009-09-09 15:08:12 +00005024
Douglas Gregor43959a92009-08-20 07:17:43 +00005025 // Build the case statement.
5026 // Case statements are always rebuilt so that they will attached to their
5027 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005028 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005029 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005030 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005031 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005032 S->getColonLoc());
5033 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005034 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005035
Douglas Gregor43959a92009-08-20 07:17:43 +00005036 // Transform the statement following the case
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
Douglas Gregor43959a92009-08-20 07:17:43 +00005041 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005042 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005043}
5044
5045template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005046StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005047TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005048 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005049 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005050 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005051 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005052
Douglas Gregor43959a92009-08-20 07:17:43 +00005053 // Default statements are always rebuilt
5054 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005055 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005056}
Mike Stump1eb44332009-09-09 15:08:12 +00005057
Douglas Gregor43959a92009-08-20 07:17:43 +00005058template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005059StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005060TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005061 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005062 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005063 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005064
Chris Lattner57ad3782011-02-17 20:34:02 +00005065 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5066 S->getDecl());
5067 if (!LD)
5068 return StmtError();
5069
5070
Douglas Gregor43959a92009-08-20 07:17:43 +00005071 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005072 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005073 cast<LabelDecl>(LD), SourceLocation(),
5074 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005075}
Mike Stump1eb44332009-09-09 15:08:12 +00005076
Douglas Gregor43959a92009-08-20 07:17:43 +00005077template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005078StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005079TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005080 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005081 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005082 VarDecl *ConditionVar = 0;
5083 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005084 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005085 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005086 getDerived().TransformDefinition(
5087 S->getConditionVariable()->getLocation(),
5088 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005089 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005090 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005091 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005092 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005093
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005094 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005095 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005096
5097 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005098 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005099 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5100 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005101 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005102 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005103
John McCall9ae2f072010-08-23 23:25:46 +00005104 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005105 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005106 }
Sean Huntc3021132010-05-05 15:23:54 +00005107
John McCall9ae2f072010-08-23 23:25:46 +00005108 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5109 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005110 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005111
Douglas Gregor43959a92009-08-20 07:17:43 +00005112 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005113 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005114 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005115 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005116
Douglas Gregor43959a92009-08-20 07:17:43 +00005117 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005118 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005119 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005120 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005121
Douglas Gregor43959a92009-08-20 07:17:43 +00005122 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005123 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005124 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005125 Then.get() == S->getThen() &&
5126 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005127 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005128
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005129 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005130 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005131 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005132}
5133
5134template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005135StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005136TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005137 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005138 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005139 VarDecl *ConditionVar = 0;
5140 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005141 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005142 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005143 getDerived().TransformDefinition(
5144 S->getConditionVariable()->getLocation(),
5145 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005146 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005147 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005148 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005149 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005150
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005151 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005152 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005153 }
Mike Stump1eb44332009-09-09 15:08:12 +00005154
Douglas Gregor43959a92009-08-20 07:17:43 +00005155 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005156 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005157 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005158 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005159 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005160 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005161
Douglas Gregor43959a92009-08-20 07:17:43 +00005162 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005163 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005164 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005165 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005166
Douglas Gregor43959a92009-08-20 07:17:43 +00005167 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005168 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5169 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005170}
Mike Stump1eb44332009-09-09 15:08:12 +00005171
Douglas Gregor43959a92009-08-20 07:17:43 +00005172template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005173StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005174TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005175 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005176 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005177 VarDecl *ConditionVar = 0;
5178 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005179 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005180 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005181 getDerived().TransformDefinition(
5182 S->getConditionVariable()->getLocation(),
5183 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005184 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005185 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005186 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005187 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005188
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005189 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005190 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005191
5192 if (S->getCond()) {
5193 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005194 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5195 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005196 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005197 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005198 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005199 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005200 }
Mike Stump1eb44332009-09-09 15:08:12 +00005201
John McCall9ae2f072010-08-23 23:25:46 +00005202 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5203 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005204 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005205
Douglas Gregor43959a92009-08-20 07:17:43 +00005206 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005207 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005208 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005209 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005210
Douglas Gregor43959a92009-08-20 07:17:43 +00005211 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005212 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005213 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005214 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005215 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005216
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005217 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005218 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005219}
Mike Stump1eb44332009-09-09 15:08:12 +00005220
Douglas Gregor43959a92009-08-20 07:17:43 +00005221template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005222StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005223TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005224 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005225 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005226 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005227 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005228
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005229 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005230 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005231 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005232 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005233
Douglas Gregor43959a92009-08-20 07:17:43 +00005234 if (!getDerived().AlwaysRebuild() &&
5235 Cond.get() == S->getCond() &&
5236 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005237 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005238
John McCall9ae2f072010-08-23 23:25:46 +00005239 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5240 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005241 S->getRParenLoc());
5242}
Mike Stump1eb44332009-09-09 15:08:12 +00005243
Douglas Gregor43959a92009-08-20 07:17:43 +00005244template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005245StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005246TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005247 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005248 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005249 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005250 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005251
Douglas Gregor43959a92009-08-20 07:17:43 +00005252 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005253 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005254 VarDecl *ConditionVar = 0;
5255 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005256 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005257 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005258 getDerived().TransformDefinition(
5259 S->getConditionVariable()->getLocation(),
5260 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005261 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005262 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005263 } else {
5264 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005265
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005266 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005267 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005268
5269 if (S->getCond()) {
5270 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005271 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5272 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005273 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005274 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005275
John McCall9ae2f072010-08-23 23:25:46 +00005276 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005277 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005278 }
Mike Stump1eb44332009-09-09 15:08:12 +00005279
John McCall9ae2f072010-08-23 23:25:46 +00005280 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5281 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005282 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005283
Douglas Gregor43959a92009-08-20 07:17:43 +00005284 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005285 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005286 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005287 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005288
John McCall9ae2f072010-08-23 23:25:46 +00005289 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5290 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005291 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005292
Douglas Gregor43959a92009-08-20 07:17:43 +00005293 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005294 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005295 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005296 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005297
Douglas Gregor43959a92009-08-20 07:17:43 +00005298 if (!getDerived().AlwaysRebuild() &&
5299 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005300 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005301 Inc.get() == S->getInc() &&
5302 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005303 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005304
Douglas Gregor43959a92009-08-20 07:17:43 +00005305 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005306 Init.get(), FullCond, ConditionVar,
5307 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005308}
5309
5310template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005311StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005312TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005313 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5314 S->getLabel());
5315 if (!LD)
5316 return StmtError();
5317
Douglas Gregor43959a92009-08-20 07:17:43 +00005318 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005319 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005320 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005321}
5322
5323template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005324StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005325TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005326 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005327 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005328 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005329 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005330
Douglas Gregor43959a92009-08-20 07:17:43 +00005331 if (!getDerived().AlwaysRebuild() &&
5332 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005333 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005334
5335 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005336 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005337}
5338
5339template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005340StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005341TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005342 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005343}
Mike Stump1eb44332009-09-09 15:08:12 +00005344
Douglas Gregor43959a92009-08-20 07:17:43 +00005345template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005346StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005347TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005348 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005349}
Mike Stump1eb44332009-09-09 15:08:12 +00005350
Douglas Gregor43959a92009-08-20 07:17:43 +00005351template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005352StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005353TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005354 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005355 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005356 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005357
Mike Stump1eb44332009-09-09 15:08:12 +00005358 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005359 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005360 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005361}
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
Mike Stump1eb44332009-09-09 15:08:12 +00005365TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005366 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005367 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005368 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5369 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005370 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5371 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005372 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005373 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005374
Douglas Gregor43959a92009-08-20 07:17:43 +00005375 if (Transformed != *D)
5376 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005377
Douglas Gregor43959a92009-08-20 07:17:43 +00005378 Decls.push_back(Transformed);
5379 }
Mike Stump1eb44332009-09-09 15:08:12 +00005380
Douglas Gregor43959a92009-08-20 07:17:43 +00005381 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005382 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005383
5384 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005385 S->getStartLoc(), S->getEndLoc());
5386}
Mike Stump1eb44332009-09-09 15:08:12 +00005387
Douglas Gregor43959a92009-08-20 07:17:43 +00005388template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005389StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005390TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005391
John McCallca0408f2010-08-23 06:44:23 +00005392 ASTOwningVector<Expr*> Constraints(getSema());
5393 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005394 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005395
John McCall60d7b3a2010-08-24 06:29:42 +00005396 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005397 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005398
5399 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005400
Anders Carlsson703e3942010-01-24 05:50:09 +00005401 // Go through the outputs.
5402 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005403 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005404
Anders Carlsson703e3942010-01-24 05:50:09 +00005405 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005406 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005407
Anders Carlsson703e3942010-01-24 05:50:09 +00005408 // Transform the output expr.
5409 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005410 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005411 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005412 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005413
Anders Carlsson703e3942010-01-24 05:50:09 +00005414 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005415
John McCall9ae2f072010-08-23 23:25:46 +00005416 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005417 }
Sean Huntc3021132010-05-05 15:23:54 +00005418
Anders Carlsson703e3942010-01-24 05:50:09 +00005419 // Go through the inputs.
5420 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005421 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005422
Anders Carlsson703e3942010-01-24 05:50:09 +00005423 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005424 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005425
Anders Carlsson703e3942010-01-24 05:50:09 +00005426 // Transform the input expr.
5427 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005428 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005429 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005430 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005431
Anders Carlsson703e3942010-01-24 05:50:09 +00005432 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005433
John McCall9ae2f072010-08-23 23:25:46 +00005434 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005435 }
Sean Huntc3021132010-05-05 15:23:54 +00005436
Anders Carlsson703e3942010-01-24 05:50:09 +00005437 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005438 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005439
5440 // Go through the clobbers.
5441 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005442 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005443
5444 // No need to transform the asm string literal.
5445 AsmString = SemaRef.Owned(S->getAsmString());
5446
5447 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5448 S->isSimple(),
5449 S->isVolatile(),
5450 S->getNumOutputs(),
5451 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005452 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005453 move_arg(Constraints),
5454 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005455 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005456 move_arg(Clobbers),
5457 S->getRParenLoc(),
5458 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005459}
5460
5461
5462template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005463StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005464TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005465 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005466 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005467 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005468 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005469
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005470 // Transform the @catch statements (if present).
5471 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005472 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005473 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005474 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005475 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005476 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005477 if (Catch.get() != S->getCatchStmt(I))
5478 AnyCatchChanged = true;
5479 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005480 }
Sean Huntc3021132010-05-05 15:23:54 +00005481
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005482 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005483 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005484 if (S->getFinallyStmt()) {
5485 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5486 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005487 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005488 }
5489
5490 // If nothing changed, just retain this statement.
5491 if (!getDerived().AlwaysRebuild() &&
5492 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005493 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005494 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005495 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005496
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005497 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005498 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5499 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005500}
Mike Stump1eb44332009-09-09 15:08:12 +00005501
Douglas Gregor43959a92009-08-20 07:17:43 +00005502template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005503StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005504TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005505 // Transform the @catch parameter, if there is one.
5506 VarDecl *Var = 0;
5507 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5508 TypeSourceInfo *TSInfo = 0;
5509 if (FromVar->getTypeSourceInfo()) {
5510 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5511 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005512 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005513 }
Sean Huntc3021132010-05-05 15:23:54 +00005514
Douglas Gregorbe270a02010-04-26 17:57:08 +00005515 QualType T;
5516 if (TSInfo)
5517 T = TSInfo->getType();
5518 else {
5519 T = getDerived().TransformType(FromVar->getType());
5520 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005521 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005522 }
Sean Huntc3021132010-05-05 15:23:54 +00005523
Douglas Gregorbe270a02010-04-26 17:57:08 +00005524 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5525 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005526 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005527 }
Sean Huntc3021132010-05-05 15:23:54 +00005528
John McCall60d7b3a2010-08-24 06:29:42 +00005529 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005530 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005531 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005532
5533 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005534 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005535 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005536}
Mike Stump1eb44332009-09-09 15:08:12 +00005537
Douglas Gregor43959a92009-08-20 07:17:43 +00005538template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005539StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005540TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005541 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005542 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005543 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005544 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005545
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005546 // If nothing changed, just retain this statement.
5547 if (!getDerived().AlwaysRebuild() &&
5548 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005549 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005550
5551 // Build a new statement.
5552 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005553 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005554}
Mike Stump1eb44332009-09-09 15:08:12 +00005555
Douglas Gregor43959a92009-08-20 07:17:43 +00005556template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005557StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005558TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005559 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005560 if (S->getThrowExpr()) {
5561 Operand = getDerived().TransformExpr(S->getThrowExpr());
5562 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005563 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005564 }
Sean Huntc3021132010-05-05 15:23:54 +00005565
Douglas Gregord1377b22010-04-22 21:44:01 +00005566 if (!getDerived().AlwaysRebuild() &&
5567 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005568 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005569
John McCall9ae2f072010-08-23 23:25:46 +00005570 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005571}
Mike Stump1eb44332009-09-09 15:08:12 +00005572
Douglas Gregor43959a92009-08-20 07:17:43 +00005573template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005574StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005575TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005576 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005577 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005578 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005579 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005580 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005581 Object =
5582 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5583 Object.get());
5584 if (Object.isInvalid())
5585 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005586
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005587 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005588 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005589 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005590 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005591
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005592 // If nothing change, just retain the current statement.
5593 if (!getDerived().AlwaysRebuild() &&
5594 Object.get() == S->getSynchExpr() &&
5595 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005596 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005597
5598 // Build a new statement.
5599 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005600 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005601}
5602
5603template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005604StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005605TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5606 ObjCAutoreleasePoolStmt *S) {
5607 // Transform the body.
5608 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5609 if (Body.isInvalid())
5610 return StmtError();
5611
5612 // If nothing changed, just retain this statement.
5613 if (!getDerived().AlwaysRebuild() &&
5614 Body.get() == S->getSubStmt())
5615 return SemaRef.Owned(S);
5616
5617 // Build a new statement.
5618 return getDerived().RebuildObjCAutoreleasePoolStmt(
5619 S->getAtLoc(), Body.get());
5620}
5621
5622template<typename Derived>
5623StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005624TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005625 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005626 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005627 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005628 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005629 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005630
Douglas Gregorc3203e72010-04-22 23:10:45 +00005631 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005632 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005633 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005634 return StmtError();
John McCall990567c2011-07-27 01:07:15 +00005635 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5636 Collection.take());
5637 if (Collection.isInvalid())
5638 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005639
Douglas Gregorc3203e72010-04-22 23:10:45 +00005640 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005641 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005642 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005643 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005644
Douglas Gregorc3203e72010-04-22 23:10:45 +00005645 // If nothing changed, just retain this statement.
5646 if (!getDerived().AlwaysRebuild() &&
5647 Element.get() == S->getElement() &&
5648 Collection.get() == S->getCollection() &&
5649 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005650 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005651
Douglas Gregorc3203e72010-04-22 23:10:45 +00005652 // Build a new statement.
5653 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5654 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005655 Element.get(),
5656 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005657 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005658 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005659}
5660
5661
5662template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005663StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005664TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5665 // Transform the exception declaration, if any.
5666 VarDecl *Var = 0;
5667 if (S->getExceptionDecl()) {
5668 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005669 TypeSourceInfo *T = getDerived().TransformType(
5670 ExceptionDecl->getTypeSourceInfo());
5671 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005672 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005673
Douglas Gregor83cb9422010-09-09 17:09:21 +00005674 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005675 ExceptionDecl->getInnerLocStart(),
5676 ExceptionDecl->getLocation(),
5677 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005678 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005679 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005680 }
Mike Stump1eb44332009-09-09 15:08:12 +00005681
Douglas Gregor43959a92009-08-20 07:17:43 +00005682 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005683 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005684 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005685 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005686
Douglas Gregor43959a92009-08-20 07:17:43 +00005687 if (!getDerived().AlwaysRebuild() &&
5688 !Var &&
5689 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005690 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005691
5692 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5693 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005694 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005695}
Mike Stump1eb44332009-09-09 15:08:12 +00005696
Douglas Gregor43959a92009-08-20 07:17:43 +00005697template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005698StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005699TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5700 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005701 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005702 = getDerived().TransformCompoundStmt(S->getTryBlock());
5703 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005704 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005705
Douglas Gregor43959a92009-08-20 07:17:43 +00005706 // Transform the handlers.
5707 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005708 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005709 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005710 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005711 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5712 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005713 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005714
Douglas Gregor43959a92009-08-20 07:17:43 +00005715 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5716 Handlers.push_back(Handler.takeAs<Stmt>());
5717 }
Mike Stump1eb44332009-09-09 15:08:12 +00005718
Douglas Gregor43959a92009-08-20 07:17:43 +00005719 if (!getDerived().AlwaysRebuild() &&
5720 TryBlock.get() == S->getTryBlock() &&
5721 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005722 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005723
John McCall9ae2f072010-08-23 23:25:46 +00005724 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005725 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005726}
Mike Stump1eb44332009-09-09 15:08:12 +00005727
Richard Smithad762fc2011-04-14 22:09:26 +00005728template<typename Derived>
5729StmtResult
5730TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5731 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5732 if (Range.isInvalid())
5733 return StmtError();
5734
5735 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5736 if (BeginEnd.isInvalid())
5737 return StmtError();
5738
5739 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5740 if (Cond.isInvalid())
5741 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005742 if (Cond.get())
5743 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5744 if (Cond.isInvalid())
5745 return StmtError();
5746 if (Cond.get())
5747 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005748
5749 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5750 if (Inc.isInvalid())
5751 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005752 if (Inc.get())
5753 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005754
5755 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5756 if (LoopVar.isInvalid())
5757 return StmtError();
5758
5759 StmtResult NewStmt = S;
5760 if (getDerived().AlwaysRebuild() ||
5761 Range.get() != S->getRangeStmt() ||
5762 BeginEnd.get() != S->getBeginEndStmt() ||
5763 Cond.get() != S->getCond() ||
5764 Inc.get() != S->getInc() ||
5765 LoopVar.get() != S->getLoopVarStmt())
5766 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5767 S->getColonLoc(), Range.get(),
5768 BeginEnd.get(), Cond.get(),
5769 Inc.get(), LoopVar.get(),
5770 S->getRParenLoc());
5771
5772 StmtResult Body = getDerived().TransformStmt(S->getBody());
5773 if (Body.isInvalid())
5774 return StmtError();
5775
5776 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5777 // it now so we have a new statement to attach the body to.
5778 if (Body.get() != S->getBody() && NewStmt.get() == S)
5779 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5780 S->getColonLoc(), Range.get(),
5781 BeginEnd.get(), Cond.get(),
5782 Inc.get(), LoopVar.get(),
5783 S->getRParenLoc());
5784
5785 if (NewStmt.get() == S)
5786 return SemaRef.Owned(S);
5787
5788 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5789}
5790
John Wiegley28bbe4b2011-04-28 01:08:34 +00005791template<typename Derived>
5792StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005793TreeTransform<Derived>::TransformMSDependentExistsStmt(
5794 MSDependentExistsStmt *S) {
5795 // Transform the nested-name-specifier, if any.
5796 NestedNameSpecifierLoc QualifierLoc;
5797 if (S->getQualifierLoc()) {
5798 QualifierLoc
5799 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5800 if (!QualifierLoc)
5801 return StmtError();
5802 }
5803
5804 // Transform the declaration name.
5805 DeclarationNameInfo NameInfo = S->getNameInfo();
5806 if (NameInfo.getName()) {
5807 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5808 if (!NameInfo.getName())
5809 return StmtError();
5810 }
5811
5812 // Check whether anything changed.
5813 if (!getDerived().AlwaysRebuild() &&
5814 QualifierLoc == S->getQualifierLoc() &&
5815 NameInfo.getName() == S->getNameInfo().getName())
5816 return S;
5817
5818 // Determine whether this name exists, if we can.
5819 CXXScopeSpec SS;
5820 SS.Adopt(QualifierLoc);
5821 bool Dependent = false;
5822 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5823 case Sema::IER_Exists:
5824 if (S->isIfExists())
5825 break;
5826
5827 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5828
5829 case Sema::IER_DoesNotExist:
5830 if (S->isIfNotExists())
5831 break;
5832
5833 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5834
5835 case Sema::IER_Dependent:
5836 Dependent = true;
5837 break;
Douglas Gregor65019ac2011-10-25 03:44:56 +00005838
5839 case Sema::IER_Error:
5840 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005841 }
5842
5843 // We need to continue with the instantiation, so do so now.
5844 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5845 if (SubStmt.isInvalid())
5846 return StmtError();
5847
5848 // If we have resolved the name, just transform to the substatement.
5849 if (!Dependent)
5850 return SubStmt;
5851
5852 // The name is still dependent, so build a dependent expression again.
5853 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5854 S->isIfExists(),
5855 QualifierLoc,
5856 NameInfo,
5857 SubStmt.get());
5858}
5859
5860template<typename Derived>
5861StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00005862TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5863 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5864 if(TryBlock.isInvalid()) return StmtError();
5865
5866 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5867 if(!getDerived().AlwaysRebuild() &&
5868 TryBlock.get() == S->getTryBlock() &&
5869 Handler.get() == S->getHandler())
5870 return SemaRef.Owned(S);
5871
5872 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5873 S->getTryLoc(),
5874 TryBlock.take(),
5875 Handler.take());
5876}
5877
5878template<typename Derived>
5879StmtResult
5880TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5881 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5882 if(Block.isInvalid()) return StmtError();
5883
5884 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5885 Block.take());
5886}
5887
5888template<typename Derived>
5889StmtResult
5890TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5891 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5892 if(FilterExpr.isInvalid()) return StmtError();
5893
5894 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5895 if(Block.isInvalid()) return StmtError();
5896
5897 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5898 FilterExpr.take(),
5899 Block.take());
5900}
5901
5902template<typename Derived>
5903StmtResult
5904TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5905 if(isa<SEHFinallyStmt>(Handler))
5906 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5907 else
5908 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5909}
5910
Douglas Gregor43959a92009-08-20 07:17:43 +00005911//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005912// Expression transformation
5913//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005914template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005915ExprResult
John McCall454feb92009-12-08 09:21:05 +00005916TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005917 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005918}
Mike Stump1eb44332009-09-09 15:08:12 +00005919
5920template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005921ExprResult
John McCall454feb92009-12-08 09:21:05 +00005922TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005923 NestedNameSpecifierLoc QualifierLoc;
5924 if (E->getQualifierLoc()) {
5925 QualifierLoc
5926 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5927 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005928 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005929 }
John McCalldbd872f2009-12-08 09:08:17 +00005930
5931 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005932 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5933 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005934 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005935 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005936
John McCallec8045d2010-08-17 21:27:17 +00005937 DeclarationNameInfo NameInfo = E->getNameInfo();
5938 if (NameInfo.getName()) {
5939 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5940 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005941 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005942 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005943
5944 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00005945 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00005946 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005947 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00005948 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005949
5950 // Mark it referenced in the new context regardless.
5951 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00005952 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00005953
John McCall3fa5cae2010-10-26 07:05:15 +00005954 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00005955 }
John McCalldbd872f2009-12-08 09:08:17 +00005956
5957 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00005958 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005959 TemplateArgs = &TransArgs;
5960 TransArgs.setLAngleLoc(E->getLAngleLoc());
5961 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005962 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5963 E->getNumTemplateArgs(),
5964 TransArgs))
5965 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00005966 }
5967
Douglas Gregor40d96a62011-02-28 21:54:11 +00005968 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5969 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005970}
Mike Stump1eb44332009-09-09 15:08:12 +00005971
Douglas Gregorb98b1992009-08-11 05:31:07 +00005972template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005973ExprResult
John McCall454feb92009-12-08 09:21:05 +00005974TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005975 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005976}
Mike Stump1eb44332009-09-09 15:08:12 +00005977
Douglas Gregorb98b1992009-08-11 05:31:07 +00005978template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005979ExprResult
John McCall454feb92009-12-08 09:21:05 +00005980TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005981 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005982}
Mike Stump1eb44332009-09-09 15:08:12 +00005983
Douglas Gregorb98b1992009-08-11 05:31:07 +00005984template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005985ExprResult
John McCall454feb92009-12-08 09:21:05 +00005986TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005987 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005988}
Mike Stump1eb44332009-09-09 15:08:12 +00005989
Douglas Gregorb98b1992009-08-11 05:31:07 +00005990template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005991ExprResult
John McCall454feb92009-12-08 09:21:05 +00005992TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005993 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005994}
Mike Stump1eb44332009-09-09 15:08:12 +00005995
Douglas Gregorb98b1992009-08-11 05:31:07 +00005996template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005997ExprResult
John McCall454feb92009-12-08 09:21:05 +00005998TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005999 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006000}
6001
6002template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006003ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006004TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6005 ExprResult ControllingExpr =
6006 getDerived().TransformExpr(E->getControllingExpr());
6007 if (ControllingExpr.isInvalid())
6008 return ExprError();
6009
Chris Lattner686775d2011-07-20 06:58:45 +00006010 SmallVector<Expr *, 4> AssocExprs;
6011 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006012 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6013 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6014 if (TS) {
6015 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6016 if (!AssocType)
6017 return ExprError();
6018 AssocTypes.push_back(AssocType);
6019 } else {
6020 AssocTypes.push_back(0);
6021 }
6022
6023 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6024 if (AssocExpr.isInvalid())
6025 return ExprError();
6026 AssocExprs.push_back(AssocExpr.release());
6027 }
6028
6029 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6030 E->getDefaultLoc(),
6031 E->getRParenLoc(),
6032 ControllingExpr.release(),
6033 AssocTypes.data(),
6034 AssocExprs.data(),
6035 E->getNumAssocs());
6036}
6037
6038template<typename Derived>
6039ExprResult
John McCall454feb92009-12-08 09:21:05 +00006040TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006041 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006042 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006043 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006044
Douglas Gregorb98b1992009-08-11 05:31:07 +00006045 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006046 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006047
John McCall9ae2f072010-08-23 23:25:46 +00006048 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006049 E->getRParen());
6050}
6051
Mike Stump1eb44332009-09-09 15:08:12 +00006052template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006053ExprResult
John McCall454feb92009-12-08 09:21:05 +00006054TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006055 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006056 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006057 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006058
Douglas Gregorb98b1992009-08-11 05:31:07 +00006059 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006060 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006061
Douglas Gregorb98b1992009-08-11 05:31:07 +00006062 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6063 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006064 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006065}
Mike Stump1eb44332009-09-09 15:08:12 +00006066
Douglas Gregorb98b1992009-08-11 05:31:07 +00006067template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006068ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006069TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6070 // Transform the type.
6071 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6072 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006073 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006074
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006075 // Transform all of the components into components similar to what the
6076 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00006077 // FIXME: It would be slightly more efficient in the non-dependent case to
6078 // just map FieldDecls, rather than requiring the rebuilder to look for
6079 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006080 // template code that we don't care.
6081 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006082 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006083 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006084 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006085 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6086 const Node &ON = E->getComponent(I);
6087 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006088 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006089 Comp.LocStart = ON.getSourceRange().getBegin();
6090 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006091 switch (ON.getKind()) {
6092 case Node::Array: {
6093 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006094 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006095 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006096 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006097
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006098 ExprChanged = ExprChanged || Index.get() != FromIndex;
6099 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006100 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006101 break;
6102 }
Sean Huntc3021132010-05-05 15:23:54 +00006103
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006104 case Node::Field:
6105 case Node::Identifier:
6106 Comp.isBrackets = false;
6107 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006108 if (!Comp.U.IdentInfo)
6109 continue;
Sean Huntc3021132010-05-05 15:23:54 +00006110
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006111 break;
Sean Huntc3021132010-05-05 15:23:54 +00006112
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006113 case Node::Base:
6114 // Will be recomputed during the rebuild.
6115 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006116 }
Sean Huntc3021132010-05-05 15:23:54 +00006117
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006118 Components.push_back(Comp);
6119 }
Sean Huntc3021132010-05-05 15:23:54 +00006120
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006121 // If nothing changed, retain the existing expression.
6122 if (!getDerived().AlwaysRebuild() &&
6123 Type == E->getTypeSourceInfo() &&
6124 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006125 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006126
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006127 // Build a new offsetof expression.
6128 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6129 Components.data(), Components.size(),
6130 E->getRParenLoc());
6131}
6132
6133template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006134ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006135TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6136 assert(getDerived().AlreadyTransformed(E->getType()) &&
6137 "opaque value expression requires transformation");
6138 return SemaRef.Owned(E);
6139}
6140
6141template<typename Derived>
6142ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006143TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006144 // Rebuild the syntactic form. The original syntactic form has
6145 // opaque-value expressions in it, so strip those away and rebuild
6146 // the result. This is a really awful way of doing this, but the
6147 // better solution (rebuilding the semantic expressions and
6148 // rebinding OVEs as necessary) doesn't work; we'd need
6149 // TreeTransform to not strip away implicit conversions.
6150 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6151 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006152 if (result.isInvalid()) return ExprError();
6153
6154 // If that gives us a pseudo-object result back, the pseudo-object
6155 // expression must have been an lvalue-to-rvalue conversion which we
6156 // should reapply.
6157 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6158 result = SemaRef.checkPseudoObjectRValue(result.take());
6159
6160 return result;
6161}
6162
6163template<typename Derived>
6164ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006165TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6166 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006167 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006168 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006169
John McCalla93c9342009-12-07 02:54:59 +00006170 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006171 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006172 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006173
John McCall5ab75172009-11-04 07:28:41 +00006174 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006175 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006176
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006177 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6178 E->getKind(),
6179 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006180 }
Mike Stump1eb44332009-09-09 15:08:12 +00006181
John McCall60d7b3a2010-08-24 06:29:42 +00006182 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00006183 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006184 // C++0x [expr.sizeof]p1:
6185 // The operand is either an expression, which is an unevaluated operand
6186 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00006187 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006188
Douglas Gregorb98b1992009-08-11 05:31:07 +00006189 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6190 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006191 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006192
Douglas Gregorb98b1992009-08-11 05:31:07 +00006193 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006194 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006195 }
Mike Stump1eb44332009-09-09 15:08:12 +00006196
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006197 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6198 E->getOperatorLoc(),
6199 E->getKind(),
6200 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006201}
Mike Stump1eb44332009-09-09 15:08:12 +00006202
Douglas Gregorb98b1992009-08-11 05:31:07 +00006203template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006204ExprResult
John McCall454feb92009-12-08 09:21:05 +00006205TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006206 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006207 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006208 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006209
John McCall60d7b3a2010-08-24 06:29:42 +00006210 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006211 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006212 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006213
6214
Douglas Gregorb98b1992009-08-11 05:31:07 +00006215 if (!getDerived().AlwaysRebuild() &&
6216 LHS.get() == E->getLHS() &&
6217 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006218 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006219
John McCall9ae2f072010-08-23 23:25:46 +00006220 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006221 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006222 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006223 E->getRBracketLoc());
6224}
Mike Stump1eb44332009-09-09 15:08:12 +00006225
6226template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006227ExprResult
John McCall454feb92009-12-08 09:21:05 +00006228TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006229 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006230 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006231 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006232 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006233
6234 // Transform arguments.
6235 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006236 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006237 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6238 &ArgChanged))
6239 return ExprError();
6240
Douglas Gregorb98b1992009-08-11 05:31:07 +00006241 if (!getDerived().AlwaysRebuild() &&
6242 Callee.get() == E->getCallee() &&
6243 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006244 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump1eb44332009-09-09 15:08:12 +00006245
Douglas Gregorb98b1992009-08-11 05:31:07 +00006246 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006247 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006248 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006249 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006250 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006251 E->getRParenLoc());
6252}
Mike Stump1eb44332009-09-09 15:08:12 +00006253
6254template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006255ExprResult
John McCall454feb92009-12-08 09:21:05 +00006256TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006257 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006258 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006259 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006260
Douglas Gregor40d96a62011-02-28 21:54:11 +00006261 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006262 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006263 QualifierLoc
6264 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6265
6266 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006267 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006268 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006269 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006270
Eli Friedmanf595cc42009-12-04 06:40:45 +00006271 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006272 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6273 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006274 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006275 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006276
John McCall6bb80172010-03-30 21:47:33 +00006277 NamedDecl *FoundDecl = E->getFoundDecl();
6278 if (FoundDecl == E->getMemberDecl()) {
6279 FoundDecl = Member;
6280 } else {
6281 FoundDecl = cast_or_null<NamedDecl>(
6282 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6283 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006284 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006285 }
6286
Douglas Gregorb98b1992009-08-11 05:31:07 +00006287 if (!getDerived().AlwaysRebuild() &&
6288 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006289 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006290 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006291 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006292 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006293
Anders Carlsson1f240322009-12-22 05:24:09 +00006294 // Mark it referenced in the new context regardless.
6295 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006296 SemaRef.MarkMemberReferenced(E);
6297
John McCall3fa5cae2010-10-26 07:05:15 +00006298 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006299 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006300
John McCalld5532b62009-11-23 01:53:49 +00006301 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006302 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006303 TransArgs.setLAngleLoc(E->getLAngleLoc());
6304 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006305 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6306 E->getNumTemplateArgs(),
6307 TransArgs))
6308 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006309 }
Sean Huntc3021132010-05-05 15:23:54 +00006310
Douglas Gregorb98b1992009-08-11 05:31:07 +00006311 // FIXME: Bogus source location for the operator
6312 SourceLocation FakeOperatorLoc
6313 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6314
John McCallc2233c52010-01-15 08:34:02 +00006315 // FIXME: to do this check properly, we will need to preserve the
6316 // first-qualifier-in-scope here, just in case we had a dependent
6317 // base (and therefore couldn't do the check) and a
6318 // nested-name-qualifier (and therefore could do the lookup).
6319 NamedDecl *FirstQualifierInScope = 0;
6320
John McCall9ae2f072010-08-23 23:25:46 +00006321 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006322 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006323 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006324 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006325 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006326 Member,
John McCall6bb80172010-03-30 21:47:33 +00006327 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006328 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006329 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006330 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006331}
Mike Stump1eb44332009-09-09 15:08:12 +00006332
Douglas Gregorb98b1992009-08-11 05:31:07 +00006333template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006334ExprResult
John McCall454feb92009-12-08 09:21:05 +00006335TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006336 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006337 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006338 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006339
John McCall60d7b3a2010-08-24 06:29:42 +00006340 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006341 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006342 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006343
Douglas Gregorb98b1992009-08-11 05:31:07 +00006344 if (!getDerived().AlwaysRebuild() &&
6345 LHS.get() == E->getLHS() &&
6346 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006347 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006348
Douglas Gregorb98b1992009-08-11 05:31:07 +00006349 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006350 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006351}
6352
Mike Stump1eb44332009-09-09 15:08:12 +00006353template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006354ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006355TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006356 CompoundAssignOperator *E) {
6357 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006358}
Mike Stump1eb44332009-09-09 15:08:12 +00006359
Douglas Gregorb98b1992009-08-11 05:31:07 +00006360template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006361ExprResult TreeTransform<Derived>::
6362TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6363 // Just rebuild the common and RHS expressions and see whether we
6364 // get any changes.
6365
6366 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6367 if (commonExpr.isInvalid())
6368 return ExprError();
6369
6370 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6371 if (rhs.isInvalid())
6372 return ExprError();
6373
6374 if (!getDerived().AlwaysRebuild() &&
6375 commonExpr.get() == e->getCommon() &&
6376 rhs.get() == e->getFalseExpr())
6377 return SemaRef.Owned(e);
6378
6379 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6380 e->getQuestionLoc(),
6381 0,
6382 e->getColonLoc(),
6383 rhs.get());
6384}
6385
6386template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006387ExprResult
John McCall454feb92009-12-08 09:21:05 +00006388TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006389 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006390 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006391 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006392
John McCall60d7b3a2010-08-24 06:29:42 +00006393 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006394 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006395 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006396
John McCall60d7b3a2010-08-24 06:29:42 +00006397 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006398 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006399 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006400
Douglas Gregorb98b1992009-08-11 05:31:07 +00006401 if (!getDerived().AlwaysRebuild() &&
6402 Cond.get() == E->getCond() &&
6403 LHS.get() == E->getLHS() &&
6404 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006405 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006406
John McCall9ae2f072010-08-23 23:25:46 +00006407 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006408 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006409 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006410 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006411 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006412}
Mike Stump1eb44332009-09-09 15:08:12 +00006413
6414template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006415ExprResult
John McCall454feb92009-12-08 09:21:05 +00006416TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006417 // Implicit casts are eliminated during transformation, since they
6418 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006419 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006420}
Mike Stump1eb44332009-09-09 15:08:12 +00006421
Douglas Gregorb98b1992009-08-11 05:31:07 +00006422template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006423ExprResult
John McCall454feb92009-12-08 09:21:05 +00006424TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006425 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6426 if (!Type)
6427 return ExprError();
6428
John McCall60d7b3a2010-08-24 06:29:42 +00006429 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006430 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006431 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006432 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006433
Douglas Gregorb98b1992009-08-11 05:31:07 +00006434 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006435 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006436 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006437 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006438
John McCall9d125032010-01-15 18:39:57 +00006439 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006440 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006441 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006442 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006443}
Mike Stump1eb44332009-09-09 15:08:12 +00006444
Douglas Gregorb98b1992009-08-11 05:31:07 +00006445template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006446ExprResult
John McCall454feb92009-12-08 09:21:05 +00006447TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006448 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6449 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6450 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006451 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006452
John McCall60d7b3a2010-08-24 06:29:42 +00006453 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006454 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006455 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006456
Douglas Gregorb98b1992009-08-11 05:31:07 +00006457 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006458 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006459 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006460 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006461
John McCall1d7d8d62010-01-19 22:33:45 +00006462 // Note: the expression type doesn't necessarily match the
6463 // type-as-written, but that's okay, because it should always be
6464 // derivable from the initializer.
6465
John McCall42f56b52010-01-18 19:35:47 +00006466 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006467 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006468 Init.get());
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>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006474 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006475 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006476 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006477
Douglas Gregorb98b1992009-08-11 05:31:07 +00006478 if (!getDerived().AlwaysRebuild() &&
6479 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006480 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006481
Douglas Gregorb98b1992009-08-11 05:31:07 +00006482 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006483 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006484 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006485 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006486 E->getAccessorLoc(),
6487 E->getAccessor());
6488}
Mike Stump1eb44332009-09-09 15:08:12 +00006489
Douglas Gregorb98b1992009-08-11 05:31:07 +00006490template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006491ExprResult
John McCall454feb92009-12-08 09:21:05 +00006492TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006493 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006494
John McCallca0408f2010-08-23 06:44:23 +00006495 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006496 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6497 Inits, &InitChanged))
6498 return ExprError();
6499
Douglas Gregorb98b1992009-08-11 05:31:07 +00006500 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006501 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006502
Douglas Gregorb98b1992009-08-11 05:31:07 +00006503 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006504 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006505}
Mike Stump1eb44332009-09-09 15:08:12 +00006506
Douglas Gregorb98b1992009-08-11 05:31:07 +00006507template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006508ExprResult
John McCall454feb92009-12-08 09:21:05 +00006509TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006510 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006511
Douglas Gregor43959a92009-08-20 07:17:43 +00006512 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006513 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006514 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006515 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006516
Douglas Gregor43959a92009-08-20 07:17:43 +00006517 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006518 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006519 bool ExprChanged = false;
6520 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6521 DEnd = E->designators_end();
6522 D != DEnd; ++D) {
6523 if (D->isFieldDesignator()) {
6524 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6525 D->getDotLoc(),
6526 D->getFieldLoc()));
6527 continue;
6528 }
Mike Stump1eb44332009-09-09 15:08:12 +00006529
Douglas Gregorb98b1992009-08-11 05:31:07 +00006530 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006531 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006532 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006533 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006534
6535 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006536 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006537
Douglas Gregorb98b1992009-08-11 05:31:07 +00006538 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6539 ArrayExprs.push_back(Index.release());
6540 continue;
6541 }
Mike Stump1eb44332009-09-09 15:08:12 +00006542
Douglas Gregorb98b1992009-08-11 05:31:07 +00006543 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006544 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006545 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6546 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006547 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006548
John McCall60d7b3a2010-08-24 06:29:42 +00006549 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006550 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006551 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006552
6553 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006554 End.get(),
6555 D->getLBracketLoc(),
6556 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006557
Douglas Gregorb98b1992009-08-11 05:31:07 +00006558 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6559 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006560
Douglas Gregorb98b1992009-08-11 05:31:07 +00006561 ArrayExprs.push_back(Start.release());
6562 ArrayExprs.push_back(End.release());
6563 }
Mike Stump1eb44332009-09-09 15:08:12 +00006564
Douglas Gregorb98b1992009-08-11 05:31:07 +00006565 if (!getDerived().AlwaysRebuild() &&
6566 Init.get() == E->getInit() &&
6567 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006568 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006569
Douglas Gregorb98b1992009-08-11 05:31:07 +00006570 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6571 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006572 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006573}
Mike Stump1eb44332009-09-09 15:08:12 +00006574
Douglas Gregorb98b1992009-08-11 05:31:07 +00006575template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006576ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006577TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006578 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006579 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006580
Douglas Gregor5557b252009-10-28 00:29:27 +00006581 // FIXME: Will we ever have proper type location here? Will we actually
6582 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006583 QualType T = getDerived().TransformType(E->getType());
6584 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006585 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006586
Douglas Gregorb98b1992009-08-11 05:31:07 +00006587 if (!getDerived().AlwaysRebuild() &&
6588 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006589 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006590
Douglas Gregorb98b1992009-08-11 05:31:07 +00006591 return getDerived().RebuildImplicitValueInitExpr(T);
6592}
Mike Stump1eb44332009-09-09 15:08:12 +00006593
Douglas Gregorb98b1992009-08-11 05:31:07 +00006594template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006595ExprResult
John McCall454feb92009-12-08 09:21:05 +00006596TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006597 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6598 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006599 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006600
John McCall60d7b3a2010-08-24 06:29:42 +00006601 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006602 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006603 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006604
Douglas Gregorb98b1992009-08-11 05:31:07 +00006605 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006606 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006607 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006608 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006609
John McCall9ae2f072010-08-23 23:25:46 +00006610 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006611 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006612}
6613
6614template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006615ExprResult
John McCall454feb92009-12-08 09:21:05 +00006616TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006617 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006618 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006619 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6620 &ArgumentChanged))
6621 return ExprError();
6622
Douglas Gregorb98b1992009-08-11 05:31:07 +00006623 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6624 move_arg(Inits),
6625 E->getRParenLoc());
6626}
Mike Stump1eb44332009-09-09 15:08:12 +00006627
Douglas Gregorb98b1992009-08-11 05:31:07 +00006628/// \brief Transform an address-of-label expression.
6629///
6630/// By default, the transformation of an address-of-label expression always
6631/// rebuilds the expression, so that the label identifier can be resolved to
6632/// the corresponding label statement by semantic analysis.
6633template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006634ExprResult
John McCall454feb92009-12-08 09:21:05 +00006635TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006636 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6637 E->getLabel());
6638 if (!LD)
6639 return ExprError();
6640
Douglas Gregorb98b1992009-08-11 05:31:07 +00006641 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006642 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006643}
Mike Stump1eb44332009-09-09 15:08:12 +00006644
6645template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006646ExprResult
John McCall454feb92009-12-08 09:21:05 +00006647TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006648 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006649 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6650 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006651 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006652
Douglas Gregorb98b1992009-08-11 05:31:07 +00006653 if (!getDerived().AlwaysRebuild() &&
6654 SubStmt.get() == E->getSubStmt())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006655 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006656
6657 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006658 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006659 E->getRParenLoc());
6660}
Mike Stump1eb44332009-09-09 15:08:12 +00006661
Douglas Gregorb98b1992009-08-11 05:31:07 +00006662template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006663ExprResult
John McCall454feb92009-12-08 09:21:05 +00006664TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006665 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006666 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006667 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006668
John McCall60d7b3a2010-08-24 06:29:42 +00006669 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006670 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006671 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006672
John McCall60d7b3a2010-08-24 06:29:42 +00006673 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006674 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006675 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006676
Douglas Gregorb98b1992009-08-11 05:31:07 +00006677 if (!getDerived().AlwaysRebuild() &&
6678 Cond.get() == E->getCond() &&
6679 LHS.get() == E->getLHS() &&
6680 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006681 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006682
Douglas Gregorb98b1992009-08-11 05:31:07 +00006683 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006684 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006685 E->getRParenLoc());
6686}
Mike Stump1eb44332009-09-09 15:08:12 +00006687
Douglas Gregorb98b1992009-08-11 05:31:07 +00006688template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006689ExprResult
John McCall454feb92009-12-08 09:21:05 +00006690TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006691 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006692}
6693
6694template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006695ExprResult
John McCall454feb92009-12-08 09:21:05 +00006696TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006697 switch (E->getOperator()) {
6698 case OO_New:
6699 case OO_Delete:
6700 case OO_Array_New:
6701 case OO_Array_Delete:
6702 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00006703 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006704
Douglas Gregor668d6d92009-12-13 20:44:55 +00006705 case OO_Call: {
6706 // This is a call to an object's operator().
6707 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6708
6709 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006710 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006711 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006712 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006713
6714 // FIXME: Poor location information
6715 SourceLocation FakeLParenLoc
6716 = SemaRef.PP.getLocForEndOfToken(
6717 static_cast<Expr *>(Object.get())->getLocEnd());
6718
6719 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006720 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006721 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6722 Args))
6723 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006724
John McCall9ae2f072010-08-23 23:25:46 +00006725 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006726 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006727 E->getLocEnd());
6728 }
6729
6730#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6731 case OO_##Name:
6732#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6733#include "clang/Basic/OperatorKinds.def"
6734 case OO_Subscript:
6735 // Handled below.
6736 break;
6737
6738 case OO_Conditional:
6739 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00006740 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006741
6742 case OO_None:
6743 case NUM_OVERLOADED_OPERATORS:
6744 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00006745 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006746 }
6747
John McCall60d7b3a2010-08-24 06:29:42 +00006748 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006749 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006750 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006751
John McCall60d7b3a2010-08-24 06:29:42 +00006752 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006753 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006754 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006755
John McCall60d7b3a2010-08-24 06:29:42 +00006756 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006757 if (E->getNumArgs() == 2) {
6758 Second = getDerived().TransformExpr(E->getArg(1));
6759 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006760 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006761 }
Mike Stump1eb44332009-09-09 15:08:12 +00006762
Douglas Gregorb98b1992009-08-11 05:31:07 +00006763 if (!getDerived().AlwaysRebuild() &&
6764 Callee.get() == E->getCallee() &&
6765 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006766 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006767 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006768
Douglas Gregorb98b1992009-08-11 05:31:07 +00006769 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6770 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006771 Callee.get(),
6772 First.get(),
6773 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006774}
Mike Stump1eb44332009-09-09 15:08:12 +00006775
Douglas Gregorb98b1992009-08-11 05:31:07 +00006776template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006777ExprResult
John McCall454feb92009-12-08 09:21:05 +00006778TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6779 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006780}
Mike Stump1eb44332009-09-09 15:08:12 +00006781
Douglas Gregorb98b1992009-08-11 05:31:07 +00006782template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006783ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006784TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6785 // Transform the callee.
6786 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6787 if (Callee.isInvalid())
6788 return ExprError();
6789
6790 // Transform exec config.
6791 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6792 if (EC.isInvalid())
6793 return ExprError();
6794
6795 // Transform arguments.
6796 bool ArgChanged = false;
6797 ASTOwningVector<Expr*> Args(SemaRef);
6798 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6799 &ArgChanged))
6800 return ExprError();
6801
6802 if (!getDerived().AlwaysRebuild() &&
6803 Callee.get() == E->getCallee() &&
6804 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006805 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006806
6807 // FIXME: Wrong source location information for the '('.
6808 SourceLocation FakeLParenLoc
6809 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6810 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6811 move_arg(Args),
6812 E->getRParenLoc(), EC.get());
6813}
6814
6815template<typename Derived>
6816ExprResult
John McCall454feb92009-12-08 09:21:05 +00006817TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006818 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6819 if (!Type)
6820 return ExprError();
6821
John McCall60d7b3a2010-08-24 06:29:42 +00006822 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006823 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006824 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006825 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006826
Douglas Gregorb98b1992009-08-11 05:31:07 +00006827 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006828 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006829 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006830 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006831
Douglas Gregorb98b1992009-08-11 05:31:07 +00006832 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006833 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006834 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6835 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6836 SourceLocation FakeRParenLoc
6837 = SemaRef.PP.getLocForEndOfToken(
6838 E->getSubExpr()->getSourceRange().getEnd());
6839 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006840 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006841 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006842 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006843 FakeRAngleLoc,
6844 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006845 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006846 FakeRParenLoc);
6847}
Mike Stump1eb44332009-09-09 15:08:12 +00006848
Douglas Gregorb98b1992009-08-11 05:31:07 +00006849template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006850ExprResult
John McCall454feb92009-12-08 09:21:05 +00006851TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6852 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006853}
Mike Stump1eb44332009-09-09 15:08:12 +00006854
6855template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006856ExprResult
John McCall454feb92009-12-08 09:21:05 +00006857TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6858 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006859}
6860
Douglas Gregorb98b1992009-08-11 05:31:07 +00006861template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006862ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006863TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006864 CXXReinterpretCastExpr *E) {
6865 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006866}
Mike Stump1eb44332009-09-09 15:08:12 +00006867
Douglas Gregorb98b1992009-08-11 05:31:07 +00006868template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006869ExprResult
John McCall454feb92009-12-08 09:21:05 +00006870TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6871 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006872}
Mike Stump1eb44332009-09-09 15:08:12 +00006873
Douglas Gregorb98b1992009-08-11 05:31:07 +00006874template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006875ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006876TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006877 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006878 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6879 if (!Type)
6880 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006881
John McCall60d7b3a2010-08-24 06:29:42 +00006882 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006883 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006884 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006885 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006886
Douglas Gregorb98b1992009-08-11 05:31:07 +00006887 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006888 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006889 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006890 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006891
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006892 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006893 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006894 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006895 E->getRParenLoc());
6896}
Mike Stump1eb44332009-09-09 15:08:12 +00006897
Douglas Gregorb98b1992009-08-11 05:31:07 +00006898template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006899ExprResult
John McCall454feb92009-12-08 09:21:05 +00006900TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006901 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006902 TypeSourceInfo *TInfo
6903 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6904 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006905 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006906
Douglas Gregorb98b1992009-08-11 05:31:07 +00006907 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006908 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006909 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006910
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006911 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6912 E->getLocStart(),
6913 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006914 E->getLocEnd());
6915 }
Mike Stump1eb44332009-09-09 15:08:12 +00006916
Eli Friedmanef331b72012-01-20 01:26:23 +00006917 // We don't know whether the subexpression is potentially evaluated until
6918 // after we perform semantic analysis. We speculatively assume it is
6919 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00006920 // potentially evaluated.
Eli Friedmanef331b72012-01-20 01:26:23 +00006921 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006922
John McCall60d7b3a2010-08-24 06:29:42 +00006923 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006924 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006925 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006926
Douglas Gregorb98b1992009-08-11 05:31:07 +00006927 if (!getDerived().AlwaysRebuild() &&
6928 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006929 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006930
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006931 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6932 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006933 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006934 E->getLocEnd());
6935}
6936
6937template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006938ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00006939TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6940 if (E->isTypeOperand()) {
6941 TypeSourceInfo *TInfo
6942 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6943 if (!TInfo)
6944 return ExprError();
6945
6946 if (!getDerived().AlwaysRebuild() &&
6947 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006948 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006949
Douglas Gregor3c52a212011-03-06 17:40:41 +00006950 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00006951 E->getLocStart(),
6952 TInfo,
6953 E->getLocEnd());
6954 }
6955
Francois Pichet01b7c302010-09-08 12:20:18 +00006956 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6957
6958 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6959 if (SubExpr.isInvalid())
6960 return ExprError();
6961
6962 if (!getDerived().AlwaysRebuild() &&
6963 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006964 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006965
6966 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6967 E->getLocStart(),
6968 SubExpr.get(),
6969 E->getLocEnd());
6970}
6971
6972template<typename Derived>
6973ExprResult
John McCall454feb92009-12-08 09:21:05 +00006974TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006975 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006976}
Mike Stump1eb44332009-09-09 15:08:12 +00006977
Douglas Gregorb98b1992009-08-11 05:31:07 +00006978template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006979ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006980TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00006981 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006982 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006983}
Mike Stump1eb44332009-09-09 15:08:12 +00006984
Douglas Gregorb98b1992009-08-11 05:31:07 +00006985template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006986ExprResult
John McCall454feb92009-12-08 09:21:05 +00006987TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006988 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00006989 QualType T;
6990 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
6991 T = MD->getThisType(getSema().Context);
6992 else
6993 T = getSema().Context.getPointerType(
6994 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00006995
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006996 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006997 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006998
Douglas Gregor828a1972010-01-07 23:12:05 +00006999 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007000}
Mike Stump1eb44332009-09-09 15:08:12 +00007001
Douglas Gregorb98b1992009-08-11 05:31:07 +00007002template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007003ExprResult
John McCall454feb92009-12-08 09:21:05 +00007004TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007005 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007006 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007007 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007008
Douglas Gregorb98b1992009-08-11 05:31:07 +00007009 if (!getDerived().AlwaysRebuild() &&
7010 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007011 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007012
Douglas Gregorbca01b42011-07-06 22:04:06 +00007013 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7014 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007015}
Mike Stump1eb44332009-09-09 15:08:12 +00007016
Douglas Gregorb98b1992009-08-11 05:31:07 +00007017template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007018ExprResult
John McCall454feb92009-12-08 09:21:05 +00007019TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007020 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007021 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7022 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007023 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007024 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007025
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007026 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007027 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007028 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007029
Douglas Gregor036aed12009-12-23 23:03:06 +00007030 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007031}
Mike Stump1eb44332009-09-09 15:08:12 +00007032
Douglas Gregorb98b1992009-08-11 05:31:07 +00007033template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007034ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007035TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7036 CXXScalarValueInitExpr *E) {
7037 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7038 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007039 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00007040
Douglas Gregorb98b1992009-08-11 05:31:07 +00007041 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007042 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007043 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007044
Douglas Gregorab6677e2010-09-08 00:15:04 +00007045 return getDerived().RebuildCXXScalarValueInitExpr(T,
7046 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007047 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007048}
Mike Stump1eb44332009-09-09 15:08:12 +00007049
Douglas Gregorb98b1992009-08-11 05:31:07 +00007050template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007051ExprResult
John McCall454feb92009-12-08 09:21:05 +00007052TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007053 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007054 TypeSourceInfo *AllocTypeInfo
7055 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7056 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007057 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007058
Douglas Gregorb98b1992009-08-11 05:31:07 +00007059 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007060 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007061 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007062 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007063
Douglas Gregorb98b1992009-08-11 05:31:07 +00007064 // Transform the placement arguments (if any).
7065 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007066 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007067 if (getDerived().TransformExprs(E->getPlacementArgs(),
7068 E->getNumPlacementArgs(), true,
7069 PlacementArgs, &ArgumentChanged))
7070 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007071
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007072 // Transform the constructor arguments (if any).
7073 // As an annoying corner case, we may have introduced an implicit value-
7074 // initialization expression when allocating a new array, which we implicitly
7075 // drop. It will be re-created during type checking.
John McCallca0408f2010-08-23 06:44:23 +00007076 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007077 if (!(E->isArray() && E->getNumConstructorArgs() == 1 &&
7078 isa<ImplicitValueInitExpr>(E->getConstructorArgs()[0])) &&
7079 TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007080 ConstructorArgs, &ArgumentChanged))
7081 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007082
Douglas Gregor1af74512010-02-26 00:38:10 +00007083 // Transform constructor, new operator, and delete operator.
7084 CXXConstructorDecl *Constructor = 0;
7085 if (E->getConstructor()) {
7086 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007087 getDerived().TransformDecl(E->getLocStart(),
7088 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007089 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007090 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007091 }
7092
7093 FunctionDecl *OperatorNew = 0;
7094 if (E->getOperatorNew()) {
7095 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007096 getDerived().TransformDecl(E->getLocStart(),
7097 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007098 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007099 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007100 }
7101
7102 FunctionDecl *OperatorDelete = 0;
7103 if (E->getOperatorDelete()) {
7104 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007105 getDerived().TransformDecl(E->getLocStart(),
7106 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007107 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007108 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007109 }
Sean Huntc3021132010-05-05 15:23:54 +00007110
Douglas Gregorb98b1992009-08-11 05:31:07 +00007111 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007112 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007113 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007114 Constructor == E->getConstructor() &&
7115 OperatorNew == E->getOperatorNew() &&
7116 OperatorDelete == E->getOperatorDelete() &&
7117 !ArgumentChanged) {
7118 // Mark any declarations we need as referenced.
7119 // FIXME: instantiation-specific.
7120 if (Constructor)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007121 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Douglas Gregor1af74512010-02-26 00:38:10 +00007122 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007123 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007124 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007125 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007126
7127 if (E->isArray() && Constructor &&
7128 !E->getAllocatedType()->isDependentType()) {
7129 QualType ElementType
7130 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7131 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7132 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7133 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007134 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007135 }
7136 }
7137 }
7138
John McCall3fa5cae2010-10-26 07:05:15 +00007139 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007140 }
Mike Stump1eb44332009-09-09 15:08:12 +00007141
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007142 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007143 if (!ArraySize.get()) {
7144 // If no array size was specified, but the new expression was
7145 // instantiated with an array type (e.g., "new T" where T is
7146 // instantiated with "int[4]"), extract the outer bound from the
7147 // array type as our array size. We do this with constant and
7148 // dependently-sized array types.
7149 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7150 if (!ArrayT) {
7151 // Do nothing
7152 } else if (const ConstantArrayType *ConsArrayT
7153 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00007154 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007155 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7156 ConsArrayT->getSize(),
7157 SemaRef.Context.getSizeType(),
7158 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007159 AllocType = ConsArrayT->getElementType();
7160 } else if (const DependentSizedArrayType *DepArrayT
7161 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7162 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007163 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007164 AllocType = DepArrayT->getElementType();
7165 }
7166 }
7167 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007168
Douglas Gregorb98b1992009-08-11 05:31:07 +00007169 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7170 E->isGlobalNew(),
7171 /*FIXME:*/E->getLocStart(),
7172 move_arg(PlacementArgs),
7173 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007174 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007175 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007176 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007177 ArraySize.get(),
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007178 E->getConstructorLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007179 move_arg(ConstructorArgs),
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007180 E->getConstructorRParen());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007181}
Mike Stump1eb44332009-09-09 15:08:12 +00007182
Douglas Gregorb98b1992009-08-11 05:31:07 +00007183template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007184ExprResult
John McCall454feb92009-12-08 09:21:05 +00007185TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007186 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007187 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007188 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007189
Douglas Gregor1af74512010-02-26 00:38:10 +00007190 // Transform the delete operator, if known.
7191 FunctionDecl *OperatorDelete = 0;
7192 if (E->getOperatorDelete()) {
7193 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007194 getDerived().TransformDecl(E->getLocStart(),
7195 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007196 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007197 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007198 }
Sean Huntc3021132010-05-05 15:23:54 +00007199
Douglas Gregorb98b1992009-08-11 05:31:07 +00007200 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007201 Operand.get() == E->getArgument() &&
7202 OperatorDelete == E->getOperatorDelete()) {
7203 // Mark any declarations we need as referenced.
7204 // FIXME: instantiation-specific.
7205 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007206 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007207
7208 if (!E->getArgument()->isTypeDependent()) {
7209 QualType Destroyed = SemaRef.Context.getBaseElementType(
7210 E->getDestroyedType());
7211 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7212 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Eli Friedman5f2987c2012-02-02 03:46:19 +00007213 SemaRef.MarkFunctionReferenced(E->getLocStart(),
7214 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007215 }
7216 }
7217
John McCall3fa5cae2010-10-26 07:05:15 +00007218 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007219 }
Mike Stump1eb44332009-09-09 15:08:12 +00007220
Douglas Gregorb98b1992009-08-11 05:31:07 +00007221 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7222 E->isGlobalDelete(),
7223 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007224 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007225}
Mike Stump1eb44332009-09-09 15:08:12 +00007226
Douglas Gregorb98b1992009-08-11 05:31:07 +00007227template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007228ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007229TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007230 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007231 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007232 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007233 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007234
John McCallb3d87482010-08-24 05:47:05 +00007235 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007236 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007237 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007238 E->getOperatorLoc(),
7239 E->isArrow()? tok::arrow : tok::period,
7240 ObjectTypePtr,
7241 MayBePseudoDestructor);
7242 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007243 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007244
John McCallb3d87482010-08-24 05:47:05 +00007245 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007246 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7247 if (QualifierLoc) {
7248 QualifierLoc
7249 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7250 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007251 return ExprError();
7252 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007253 CXXScopeSpec SS;
7254 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007255
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007256 PseudoDestructorTypeStorage Destroyed;
7257 if (E->getDestroyedTypeInfo()) {
7258 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007259 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007260 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007261 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007262 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007263 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007264 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007265 // We aren't likely to be able to resolve the identifier down to a type
7266 // now anyway, so just retain the identifier.
7267 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7268 E->getDestroyedTypeLoc());
7269 } else {
7270 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007271 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007272 *E->getDestroyedTypeIdentifier(),
7273 E->getDestroyedTypeLoc(),
7274 /*Scope=*/0,
7275 SS, ObjectTypePtr,
7276 false);
7277 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007278 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007279
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007280 Destroyed
7281 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7282 E->getDestroyedTypeLoc());
7283 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007284
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007285 TypeSourceInfo *ScopeTypeInfo = 0;
7286 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007287 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007288 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007289 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007290 }
Sean Huntc3021132010-05-05 15:23:54 +00007291
John McCall9ae2f072010-08-23 23:25:46 +00007292 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007293 E->getOperatorLoc(),
7294 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007295 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007296 ScopeTypeInfo,
7297 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007298 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007299 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007300}
Mike Stump1eb44332009-09-09 15:08:12 +00007301
Douglas Gregora71d8192009-09-04 17:36:40 +00007302template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007303ExprResult
John McCallba135432009-11-21 08:51:07 +00007304TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007305 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007306 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7307 Sema::LookupOrdinaryName);
7308
7309 // Transform all the decls.
7310 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7311 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007312 NamedDecl *InstD = static_cast<NamedDecl*>(
7313 getDerived().TransformDecl(Old->getNameLoc(),
7314 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007315 if (!InstD) {
7316 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7317 // This can happen because of dependent hiding.
7318 if (isa<UsingShadowDecl>(*I))
7319 continue;
7320 else
John McCallf312b1e2010-08-26 23:41:50 +00007321 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007322 }
John McCallf7a1a742009-11-24 19:00:30 +00007323
7324 // Expand using declarations.
7325 if (isa<UsingDecl>(InstD)) {
7326 UsingDecl *UD = cast<UsingDecl>(InstD);
7327 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7328 E = UD->shadow_end(); I != E; ++I)
7329 R.addDecl(*I);
7330 continue;
7331 }
7332
7333 R.addDecl(InstD);
7334 }
7335
7336 // Resolve a kind, but don't do any further analysis. If it's
7337 // ambiguous, the callee needs to deal with it.
7338 R.resolveKind();
7339
7340 // Rebuild the nested-name qualifier, if present.
7341 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007342 if (Old->getQualifierLoc()) {
7343 NestedNameSpecifierLoc QualifierLoc
7344 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7345 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007346 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007347
Douglas Gregor4c9be892011-02-28 20:01:57 +00007348 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007349 }
7350
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007351 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007352 CXXRecordDecl *NamingClass
7353 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7354 Old->getNameLoc(),
7355 Old->getNamingClass()));
7356 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007357 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007358
Douglas Gregor66c45152010-04-27 16:10:10 +00007359 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007360 }
7361
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007362 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7363
John McCallf7a1a742009-11-24 19:00:30 +00007364 // If we have no template arguments, it's a normal declaration name.
7365 if (!Old->hasExplicitTemplateArgs())
7366 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7367
7368 // If we have template arguments, rebuild them, then rebuild the
7369 // templateid expression.
7370 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007371 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7372 Old->getNumTemplateArgs(),
7373 TransArgs))
7374 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007375
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007376 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
7377 Old->requiresADL(), TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007378}
Mike Stump1eb44332009-09-09 15:08:12 +00007379
Douglas Gregorb98b1992009-08-11 05:31:07 +00007380template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007381ExprResult
John McCall454feb92009-12-08 09:21:05 +00007382TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007383 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7384 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007385 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007386
Douglas Gregorb98b1992009-08-11 05:31:07 +00007387 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007388 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007389 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007390
Mike Stump1eb44332009-09-09 15:08:12 +00007391 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007392 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007393 T,
7394 E->getLocEnd());
7395}
Mike Stump1eb44332009-09-09 15:08:12 +00007396
Douglas Gregorb98b1992009-08-11 05:31:07 +00007397template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007398ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007399TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7400 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7401 if (!LhsT)
7402 return ExprError();
7403
7404 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7405 if (!RhsT)
7406 return ExprError();
7407
7408 if (!getDerived().AlwaysRebuild() &&
7409 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7410 return SemaRef.Owned(E);
7411
7412 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7413 E->getLocStart(),
7414 LhsT, RhsT,
7415 E->getLocEnd());
7416}
7417
7418template<typename Derived>
7419ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007420TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7421 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7422 if (!T)
7423 return ExprError();
7424
7425 if (!getDerived().AlwaysRebuild() &&
7426 T == E->getQueriedTypeSourceInfo())
7427 return SemaRef.Owned(E);
7428
7429 ExprResult SubExpr;
7430 {
7431 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7432 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7433 if (SubExpr.isInvalid())
7434 return ExprError();
7435
7436 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7437 return SemaRef.Owned(E);
7438 }
7439
7440 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7441 E->getLocStart(),
7442 T,
7443 SubExpr.get(),
7444 E->getLocEnd());
7445}
7446
7447template<typename Derived>
7448ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007449TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7450 ExprResult SubExpr;
7451 {
7452 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7453 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7454 if (SubExpr.isInvalid())
7455 return ExprError();
7456
7457 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7458 return SemaRef.Owned(E);
7459 }
7460
7461 return getDerived().RebuildExpressionTrait(
7462 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7463}
7464
7465template<typename Derived>
7466ExprResult
John McCall865d4472009-11-19 22:55:06 +00007467TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007468 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007469 NestedNameSpecifierLoc QualifierLoc
7470 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7471 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007472 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007473 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007474
John McCall43fed0d2010-11-12 08:19:04 +00007475 // TODO: If this is a conversion-function-id, verify that the
7476 // destination type name (if present) resolves the same way after
7477 // instantiation as it did in the local scope.
7478
Abramo Bagnara25777432010-08-11 22:01:17 +00007479 DeclarationNameInfo NameInfo
7480 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7481 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007482 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007483
John McCallf7a1a742009-11-24 19:00:30 +00007484 if (!E->hasExplicitTemplateArgs()) {
7485 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007486 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007487 // Note: it is sufficient to compare the Name component of NameInfo:
7488 // if name has not changed, DNLoc has not changed either.
7489 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007490 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007491
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007492 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007493 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007494 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007495 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007496 }
John McCalld5532b62009-11-23 01:53:49 +00007497
7498 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007499 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7500 E->getNumTemplateArgs(),
7501 TransArgs))
7502 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007503
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007504 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007505 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007506 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007507 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007508}
7509
7510template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007511ExprResult
John McCall454feb92009-12-08 09:21:05 +00007512TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007513 // CXXConstructExprs are always implicit, so when we have a
7514 // 1-argument construction we just transform that argument.
7515 if (E->getNumArgs() == 1 ||
7516 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7517 return getDerived().TransformExpr(E->getArg(0));
7518
Douglas Gregorb98b1992009-08-11 05:31:07 +00007519 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7520
7521 QualType T = getDerived().TransformType(E->getType());
7522 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007523 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007524
7525 CXXConstructorDecl *Constructor
7526 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007527 getDerived().TransformDecl(E->getLocStart(),
7528 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007529 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007530 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007531
Douglas Gregorb98b1992009-08-11 05:31:07 +00007532 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007533 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007534 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7535 &ArgumentChanged))
7536 return ExprError();
7537
Douglas Gregorb98b1992009-08-11 05:31:07 +00007538 if (!getDerived().AlwaysRebuild() &&
7539 T == E->getType() &&
7540 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007541 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007542 // Mark the constructor as referenced.
7543 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007544 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007545 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007546 }
Mike Stump1eb44332009-09-09 15:08:12 +00007547
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007548 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7549 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007550 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007551 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007552 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007553 E->getConstructionKind(),
7554 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007555}
Mike Stump1eb44332009-09-09 15:08:12 +00007556
Douglas Gregorb98b1992009-08-11 05:31:07 +00007557/// \brief Transform a C++ temporary-binding expression.
7558///
Douglas Gregor51326552009-12-24 18:51:59 +00007559/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7560/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007561template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007562ExprResult
John McCall454feb92009-12-08 09:21:05 +00007563TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007564 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007565}
Mike Stump1eb44332009-09-09 15:08:12 +00007566
John McCall4765fa02010-12-06 08:20:24 +00007567/// \brief Transform a C++ expression that contains cleanups that should
7568/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007569///
John McCall4765fa02010-12-06 08:20:24 +00007570/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007571/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007572template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007573ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007574TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007575 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007576}
Mike Stump1eb44332009-09-09 15:08:12 +00007577
Douglas Gregorb98b1992009-08-11 05:31:07 +00007578template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007579ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007580TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007581 CXXTemporaryObjectExpr *E) {
7582 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7583 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007584 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007585
Douglas Gregorb98b1992009-08-11 05:31:07 +00007586 CXXConstructorDecl *Constructor
7587 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007588 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007589 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007590 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007591 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007592
Douglas Gregorb98b1992009-08-11 05:31:07 +00007593 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007594 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007595 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007596 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7597 &ArgumentChanged))
7598 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007599
Douglas Gregorb98b1992009-08-11 05:31:07 +00007600 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007601 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007602 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007603 !ArgumentChanged) {
7604 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007605 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007606 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007607 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007608
7609 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7610 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007611 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007612 E->getLocEnd());
7613}
Mike Stump1eb44332009-09-09 15:08:12 +00007614
Douglas Gregorb98b1992009-08-11 05:31:07 +00007615template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007616ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007617TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007618 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007619 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7620 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007621 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007622
Douglas Gregorb98b1992009-08-11 05:31:07 +00007623 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007624 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007625 Args.reserve(E->arg_size());
7626 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7627 &ArgumentChanged))
7628 return ExprError();
7629
Douglas Gregorb98b1992009-08-11 05:31:07 +00007630 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007631 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007632 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007633 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007634
Douglas Gregorb98b1992009-08-11 05:31:07 +00007635 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00007636 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007637 E->getLParenLoc(),
7638 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007639 E->getRParenLoc());
7640}
Mike Stump1eb44332009-09-09 15:08:12 +00007641
Douglas Gregorb98b1992009-08-11 05:31:07 +00007642template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007643ExprResult
John McCall865d4472009-11-19 22:55:06 +00007644TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007645 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007646 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007647 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007648 Expr *OldBase;
7649 QualType BaseType;
7650 QualType ObjectType;
7651 if (!E->isImplicitAccess()) {
7652 OldBase = E->getBase();
7653 Base = getDerived().TransformExpr(OldBase);
7654 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007655 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007656
John McCallaa81e162009-12-01 22:10:20 +00007657 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00007658 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00007659 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007660 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007661 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00007662 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00007663 ObjectTy,
7664 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00007665 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007666 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007667
John McCallb3d87482010-08-24 05:47:05 +00007668 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00007669 BaseType = ((Expr*) Base.get())->getType();
7670 } else {
7671 OldBase = 0;
7672 BaseType = getDerived().TransformType(E->getBaseType());
7673 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7674 }
Mike Stump1eb44332009-09-09 15:08:12 +00007675
Douglas Gregor6cd21982009-10-20 05:58:46 +00007676 // Transform the first part of the nested-name-specifier that qualifies
7677 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00007678 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00007679 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007680 E->getFirstQualifierFoundInScope(),
7681 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00007682
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007683 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00007684 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007685 QualifierLoc
7686 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7687 ObjectType,
7688 FirstQualifierInScope);
7689 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007690 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00007691 }
Mike Stump1eb44332009-09-09 15:08:12 +00007692
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007693 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
7694
John McCall43fed0d2010-11-12 08:19:04 +00007695 // TODO: If this is a conversion-function-id, verify that the
7696 // destination type name (if present) resolves the same way after
7697 // instantiation as it did in the local scope.
7698
Abramo Bagnara25777432010-08-11 22:01:17 +00007699 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00007700 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00007701 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007702 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007703
John McCallaa81e162009-12-01 22:10:20 +00007704 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007705 // This is a reference to a member without an explicitly-specified
7706 // template argument list. Optimize for this common case.
7707 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00007708 Base.get() == OldBase &&
7709 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007710 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007711 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007712 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00007713 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007714
John McCall9ae2f072010-08-23 23:25:46 +00007715 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007716 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007717 E->isArrow(),
7718 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007719 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007720 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00007721 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007722 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007723 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007724 }
7725
John McCalld5532b62009-11-23 01:53:49 +00007726 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007727 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7728 E->getNumTemplateArgs(),
7729 TransArgs))
7730 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007731
John McCall9ae2f072010-08-23 23:25:46 +00007732 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007733 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007734 E->isArrow(),
7735 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007736 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007737 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007738 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007739 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007740 &TransArgs);
7741}
7742
7743template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007744ExprResult
John McCall454feb92009-12-08 09:21:05 +00007745TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00007746 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007747 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007748 QualType BaseType;
7749 if (!Old->isImplicitAccess()) {
7750 Base = getDerived().TransformExpr(Old->getBase());
7751 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007752 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00007753 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
7754 Old->isArrow());
7755 if (Base.isInvalid())
7756 return ExprError();
7757 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00007758 } else {
7759 BaseType = getDerived().TransformType(Old->getBaseType());
7760 }
John McCall129e2df2009-11-30 22:42:35 +00007761
Douglas Gregor4c9be892011-02-28 20:01:57 +00007762 NestedNameSpecifierLoc QualifierLoc;
7763 if (Old->getQualifierLoc()) {
7764 QualifierLoc
7765 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7766 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007767 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007768 }
7769
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007770 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7771
Abramo Bagnara25777432010-08-11 22:01:17 +00007772 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00007773 Sema::LookupOrdinaryName);
7774
7775 // Transform all the decls.
7776 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7777 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007778 NamedDecl *InstD = static_cast<NamedDecl*>(
7779 getDerived().TransformDecl(Old->getMemberLoc(),
7780 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007781 if (!InstD) {
7782 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7783 // This can happen because of dependent hiding.
7784 if (isa<UsingShadowDecl>(*I))
7785 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007786 else {
7787 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007788 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007789 }
John McCall9f54ad42009-12-10 09:41:52 +00007790 }
John McCall129e2df2009-11-30 22:42:35 +00007791
7792 // Expand using declarations.
7793 if (isa<UsingDecl>(InstD)) {
7794 UsingDecl *UD = cast<UsingDecl>(InstD);
7795 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7796 E = UD->shadow_end(); I != E; ++I)
7797 R.addDecl(*I);
7798 continue;
7799 }
7800
7801 R.addDecl(InstD);
7802 }
7803
7804 R.resolveKind();
7805
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007806 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00007807 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00007808 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007809 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00007810 Old->getMemberLoc(),
7811 Old->getNamingClass()));
7812 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007813 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007814
Douglas Gregor66c45152010-04-27 16:10:10 +00007815 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007816 }
Sean Huntc3021132010-05-05 15:23:54 +00007817
John McCall129e2df2009-11-30 22:42:35 +00007818 TemplateArgumentListInfo TransArgs;
7819 if (Old->hasExplicitTemplateArgs()) {
7820 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7821 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007822 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7823 Old->getNumTemplateArgs(),
7824 TransArgs))
7825 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007826 }
John McCallc2233c52010-01-15 08:34:02 +00007827
7828 // FIXME: to do this check properly, we will need to preserve the
7829 // first-qualifier-in-scope here, just in case we had a dependent
7830 // base (and therefore couldn't do the check) and a
7831 // nested-name-qualifier (and therefore could do the lookup).
7832 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00007833
John McCall9ae2f072010-08-23 23:25:46 +00007834 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007835 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00007836 Old->getOperatorLoc(),
7837 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00007838 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007839 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00007840 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00007841 R,
7842 (Old->hasExplicitTemplateArgs()
7843 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007844}
7845
7846template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007847ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00007848TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00007849 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00007850 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7851 if (SubExpr.isInvalid())
7852 return ExprError();
7853
7854 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007855 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00007856
7857 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7858}
7859
7860template<typename Derived>
7861ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00007862TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00007863 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7864 if (Pattern.isInvalid())
7865 return ExprError();
7866
7867 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7868 return SemaRef.Owned(E);
7869
Douglas Gregor67fd1252011-01-14 21:20:45 +00007870 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7871 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00007872}
Douglas Gregoree8aff02011-01-04 17:33:58 +00007873
7874template<typename Derived>
7875ExprResult
7876TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7877 // If E is not value-dependent, then nothing will change when we transform it.
7878 // Note: This is an instantiation-centric view.
7879 if (!E->isValueDependent())
7880 return SemaRef.Owned(E);
7881
7882 // Note: None of the implementations of TryExpandParameterPacks can ever
7883 // produce a diagnostic when given only a single unexpanded parameter pack,
7884 // so
7885 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7886 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00007887 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00007888 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00007889 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00007890 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00007891 ShouldExpand, RetainExpansion,
7892 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00007893 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00007894
Douglas Gregor089e8932011-10-10 18:59:29 +00007895 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00007896 return SemaRef.Owned(E);
Douglas Gregor089e8932011-10-10 18:59:29 +00007897
7898 NamedDecl *Pack = E->getPack();
7899 if (!ShouldExpand) {
7900 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
7901 Pack));
7902 if (!Pack)
7903 return ExprError();
7904 }
7905
Douglas Gregoree8aff02011-01-04 17:33:58 +00007906
7907 // We now know the length of the parameter pack, so build a new expression
7908 // that stores that length.
Douglas Gregor089e8932011-10-10 18:59:29 +00007909 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregoree8aff02011-01-04 17:33:58 +00007910 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00007911 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00007912}
7913
Douglas Gregorbe230c32011-01-03 17:17:50 +00007914template<typename Derived>
7915ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00007916TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7917 SubstNonTypeTemplateParmPackExpr *E) {
7918 // Default behavior is to do nothing with this transformation.
7919 return SemaRef.Owned(E);
7920}
7921
7922template<typename Derived>
7923ExprResult
John McCall91a57552011-07-15 05:09:51 +00007924TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
7925 SubstNonTypeTemplateParmExpr *E) {
7926 // Default behavior is to do nothing with this transformation.
7927 return SemaRef.Owned(E);
7928}
7929
7930template<typename Derived>
7931ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00007932TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
7933 MaterializeTemporaryExpr *E) {
7934 return getDerived().TransformExpr(E->GetTemporaryExpr());
7935}
7936
7937template<typename Derived>
7938ExprResult
John McCall454feb92009-12-08 09:21:05 +00007939TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007940 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007941}
7942
Mike Stump1eb44332009-09-09 15:08:12 +00007943template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007944ExprResult
John McCall454feb92009-12-08 09:21:05 +00007945TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00007946 TypeSourceInfo *EncodedTypeInfo
7947 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7948 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007949 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007950
Douglas Gregorb98b1992009-08-11 05:31:07 +00007951 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00007952 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007953 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007954
7955 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00007956 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007957 E->getRParenLoc());
7958}
Mike Stump1eb44332009-09-09 15:08:12 +00007959
Douglas Gregorb98b1992009-08-11 05:31:07 +00007960template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00007961ExprResult TreeTransform<Derived>::
7962TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7963 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7964 if (result.isInvalid()) return ExprError();
7965 Expr *subExpr = result.take();
7966
7967 if (!getDerived().AlwaysRebuild() &&
7968 subExpr == E->getSubExpr())
7969 return SemaRef.Owned(E);
7970
7971 return SemaRef.Owned(new(SemaRef.Context)
7972 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7973}
7974
7975template<typename Derived>
7976ExprResult TreeTransform<Derived>::
7977TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7978 TypeSourceInfo *TSInfo
7979 = getDerived().TransformType(E->getTypeInfoAsWritten());
7980 if (!TSInfo)
7981 return ExprError();
7982
7983 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7984 if (Result.isInvalid())
7985 return ExprError();
7986
7987 if (!getDerived().AlwaysRebuild() &&
7988 TSInfo == E->getTypeInfoAsWritten() &&
7989 Result.get() == E->getSubExpr())
7990 return SemaRef.Owned(E);
7991
7992 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
7993 E->getBridgeKeywordLoc(), TSInfo,
7994 Result.get());
7995}
7996
7997template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007998ExprResult
John McCall454feb92009-12-08 09:21:05 +00007999TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008000 // Transform arguments.
8001 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008002 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008003 Args.reserve(E->getNumArgs());
8004 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
8005 &ArgChanged))
8006 return ExprError();
8007
Douglas Gregor92e986e2010-04-22 16:44:27 +00008008 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8009 // Class message: transform the receiver type.
8010 TypeSourceInfo *ReceiverTypeInfo
8011 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8012 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008013 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008014
Douglas Gregor92e986e2010-04-22 16:44:27 +00008015 // If nothing changed, just retain the existing message send.
8016 if (!getDerived().AlwaysRebuild() &&
8017 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008018 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008019
8020 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008021 SmallVector<SourceLocation, 16> SelLocs;
8022 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008023 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8024 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008025 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008026 E->getMethodDecl(),
8027 E->getLeftLoc(),
8028 move_arg(Args),
8029 E->getRightLoc());
8030 }
8031
8032 // Instance message: transform the receiver
8033 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8034 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008035 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008036 = getDerived().TransformExpr(E->getInstanceReceiver());
8037 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008038 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008039
8040 // If nothing changed, just retain the existing message send.
8041 if (!getDerived().AlwaysRebuild() &&
8042 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008043 return SemaRef.MaybeBindToTemporary(E);
Sean Huntc3021132010-05-05 15:23:54 +00008044
Douglas Gregor92e986e2010-04-22 16:44:27 +00008045 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008046 SmallVector<SourceLocation, 16> SelLocs;
8047 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008048 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008049 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008050 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008051 E->getMethodDecl(),
8052 E->getLeftLoc(),
8053 move_arg(Args),
8054 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008055}
8056
Mike Stump1eb44332009-09-09 15:08:12 +00008057template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008058ExprResult
John McCall454feb92009-12-08 09:21:05 +00008059TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008060 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008061}
8062
Mike Stump1eb44332009-09-09 15:08:12 +00008063template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008064ExprResult
John McCall454feb92009-12-08 09:21:05 +00008065TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008066 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008067}
8068
Mike Stump1eb44332009-09-09 15:08:12 +00008069template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008070ExprResult
John McCall454feb92009-12-08 09:21:05 +00008071TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008072 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008073 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008074 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008075 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008076
8077 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008078
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008079 // If nothing changed, just retain the existing expression.
8080 if (!getDerived().AlwaysRebuild() &&
8081 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008082 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008083
John McCall9ae2f072010-08-23 23:25:46 +00008084 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008085 E->getLocation(),
8086 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008087}
8088
Mike Stump1eb44332009-09-09 15:08:12 +00008089template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008090ExprResult
John McCall454feb92009-12-08 09:21:05 +00008091TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008092 // 'super' and types never change. Property never changes. Just
8093 // retain the existing expression.
8094 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008095 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00008096
Douglas Gregore3303542010-04-26 20:47:02 +00008097 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008098 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008099 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008100 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008101
Douglas Gregore3303542010-04-26 20:47:02 +00008102 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008103
Douglas Gregore3303542010-04-26 20:47:02 +00008104 // If nothing changed, just retain the existing expression.
8105 if (!getDerived().AlwaysRebuild() &&
8106 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008107 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008108
John McCall12f78a62010-12-02 01:19:52 +00008109 if (E->isExplicitProperty())
8110 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8111 E->getExplicitProperty(),
8112 E->getLocation());
8113
8114 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008115 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008116 E->getImplicitPropertyGetter(),
8117 E->getImplicitPropertySetter(),
8118 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008119}
8120
Mike Stump1eb44332009-09-09 15:08:12 +00008121template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008122ExprResult
John McCall454feb92009-12-08 09:21:05 +00008123TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008124 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008125 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008126 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008127 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008128
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008129 // If nothing changed, just retain the existing expression.
8130 if (!getDerived().AlwaysRebuild() &&
8131 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008132 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008133
John McCall9ae2f072010-08-23 23:25:46 +00008134 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008135 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008136}
8137
Mike Stump1eb44332009-09-09 15:08:12 +00008138template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008139ExprResult
John McCall454feb92009-12-08 09:21:05 +00008140TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008141 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008142 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008143 SubExprs.reserve(E->getNumSubExprs());
8144 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8145 SubExprs, &ArgumentChanged))
8146 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008147
Douglas Gregorb98b1992009-08-11 05:31:07 +00008148 if (!getDerived().AlwaysRebuild() &&
8149 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008150 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008151
Douglas Gregorb98b1992009-08-11 05:31:07 +00008152 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8153 move_arg(SubExprs),
8154 E->getRParenLoc());
8155}
8156
Mike Stump1eb44332009-09-09 15:08:12 +00008157template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008158ExprResult
John McCall454feb92009-12-08 09:21:05 +00008159TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008160 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008161
John McCallc6ac9c32011-02-04 18:33:18 +00008162 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8163 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8164
8165 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008166 blockScope->TheDecl->setBlockMissingReturnType(
8167 oldBlock->blockMissingReturnType());
Fariborz Jahanianff365592011-05-05 17:18:12 +00008168
Chris Lattner686775d2011-07-20 06:58:45 +00008169 SmallVector<ParmVarDecl*, 4> params;
8170 SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008171
8172 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008173 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8174 oldBlock->param_begin(),
8175 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008176 0, paramTypes, &params)) {
8177 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008178 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008179 }
John McCallc6ac9c32011-02-04 18:33:18 +00008180
8181 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008182 QualType exprResultType =
8183 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008184
8185 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008186 if (exprResultType->isObjCObjectType()) {
John McCallc6ac9c32011-02-04 18:33:18 +00008187 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00008188 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008189 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008190 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008191 return ExprError();
8192 }
John McCall711c52b2011-01-05 12:14:39 +00008193
John McCallc6ac9c32011-02-04 18:33:18 +00008194 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008195 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008196 paramTypes.data(),
8197 paramTypes.size(),
8198 oldBlock->isVariadic(),
Douglas Gregorc938c162011-01-26 05:01:58 +00008199 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008200 exprFunctionType->getExtInfo());
8201 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008202
8203 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008204 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008205 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008206
8207 if (!oldBlock->blockMissingReturnType()) {
8208 blockScope->HasImplicitReturnType = false;
8209 blockScope->ReturnType = exprResultType;
8210 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00008211
John McCall711c52b2011-01-05 12:14:39 +00008212 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008213 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008214 if (body.isInvalid()) {
8215 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008216 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008217 }
John McCall711c52b2011-01-05 12:14:39 +00008218
John McCallc6ac9c32011-02-04 18:33:18 +00008219#ifndef NDEBUG
8220 // In builds with assertions, make sure that we captured everything we
8221 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008222 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8223 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8224 e = oldBlock->capture_end(); i != e; ++i) {
8225 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008226
Douglas Gregorfc921372011-05-20 15:32:55 +00008227 // Ignore parameter packs.
8228 if (isa<ParmVarDecl>(oldCapture) &&
8229 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8230 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008231
Douglas Gregorfc921372011-05-20 15:32:55 +00008232 VarDecl *newCapture =
8233 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8234 oldCapture));
8235 assert(blockScope->CaptureMap.count(newCapture));
8236 }
John McCallc6ac9c32011-02-04 18:33:18 +00008237 }
8238#endif
8239
8240 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8241 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008242}
8243
Mike Stump1eb44332009-09-09 15:08:12 +00008244template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008245ExprResult
John McCall454feb92009-12-08 09:21:05 +00008246TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008247 ValueDecl *ND
8248 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8249 E->getDecl()));
8250 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00008251 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00008252
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008253 if (!getDerived().AlwaysRebuild() &&
8254 ND == E->getDecl()) {
8255 // Mark it referenced in the new context regardless.
8256 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00008257 SemaRef.MarkBlockDeclRefReferenced(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008258
John McCall3fa5cae2010-10-26 07:05:15 +00008259 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008260 }
8261
Abramo Bagnara25777432010-08-11 22:01:17 +00008262 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregor40d96a62011-02-28 21:54:11 +00008263 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnara25777432010-08-11 22:01:17 +00008264 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008265}
Mike Stump1eb44332009-09-09 15:08:12 +00008266
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008267template<typename Derived>
8268ExprResult
8269TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008270 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008271}
Eli Friedman276b0612011-10-11 02:20:01 +00008272
8273template<typename Derived>
8274ExprResult
8275TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008276 QualType RetTy = getDerived().TransformType(E->getType());
8277 bool ArgumentChanged = false;
8278 ASTOwningVector<Expr*> SubExprs(SemaRef);
8279 SubExprs.reserve(E->getNumSubExprs());
8280 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8281 SubExprs, &ArgumentChanged))
8282 return ExprError();
8283
8284 if (!getDerived().AlwaysRebuild() &&
8285 !ArgumentChanged)
8286 return SemaRef.Owned(E);
8287
8288 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8289 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008290}
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008291
Douglas Gregorb98b1992009-08-11 05:31:07 +00008292//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008293// Type reconstruction
8294//===----------------------------------------------------------------------===//
8295
Mike Stump1eb44332009-09-09 15:08:12 +00008296template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008297QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8298 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008299 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008300 getDerived().getBaseEntity());
8301}
8302
Mike Stump1eb44332009-09-09 15:08:12 +00008303template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008304QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8305 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008306 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008307 getDerived().getBaseEntity());
8308}
8309
Mike Stump1eb44332009-09-09 15:08:12 +00008310template<typename Derived>
8311QualType
John McCall85737a72009-10-30 00:06:24 +00008312TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8313 bool WrittenAsLValue,
8314 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008315 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008316 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008317}
8318
8319template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008320QualType
John McCall85737a72009-10-30 00:06:24 +00008321TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8322 QualType ClassType,
8323 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008324 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008325 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008326}
8327
8328template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008329QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008330TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8331 ArrayType::ArraySizeModifier SizeMod,
8332 const llvm::APInt *Size,
8333 Expr *SizeExpr,
8334 unsigned IndexTypeQuals,
8335 SourceRange BracketsRange) {
8336 if (SizeExpr || !Size)
8337 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8338 IndexTypeQuals, BracketsRange,
8339 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008340
8341 QualType Types[] = {
8342 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8343 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8344 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008345 };
8346 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8347 QualType SizeType;
8348 for (unsigned I = 0; I != NumTypes; ++I)
8349 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8350 SizeType = Types[I];
8351 break;
8352 }
Mike Stump1eb44332009-09-09 15:08:12 +00008353
Eli Friedman01f276d2012-01-25 23:20:27 +00008354 // Note that we can return a VariableArrayType here in the case where
8355 // the element type was a dependent VariableArrayType.
8356 IntegerLiteral *ArraySize
8357 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8358 /*FIXME*/BracketsRange.getBegin());
8359 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008360 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008361 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008362}
Mike Stump1eb44332009-09-09 15:08:12 +00008363
Douglas Gregor577f75a2009-08-04 16:50:30 +00008364template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008365QualType
8366TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008367 ArrayType::ArraySizeModifier SizeMod,
8368 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008369 unsigned IndexTypeQuals,
8370 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008371 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008372 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008373}
8374
8375template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008376QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008377TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008378 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008379 unsigned IndexTypeQuals,
8380 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008381 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008382 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008383}
Mike Stump1eb44332009-09-09 15:08:12 +00008384
Douglas Gregor577f75a2009-08-04 16:50:30 +00008385template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008386QualType
8387TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008388 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008389 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008390 unsigned IndexTypeQuals,
8391 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008392 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008393 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008394 IndexTypeQuals, BracketsRange);
8395}
8396
8397template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008398QualType
8399TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008400 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008401 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008402 unsigned IndexTypeQuals,
8403 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008404 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008405 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008406 IndexTypeQuals, BracketsRange);
8407}
8408
8409template<typename Derived>
8410QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008411 unsigned NumElements,
8412 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008413 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008414 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008415}
Mike Stump1eb44332009-09-09 15:08:12 +00008416
Douglas Gregor577f75a2009-08-04 16:50:30 +00008417template<typename Derived>
8418QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8419 unsigned NumElements,
8420 SourceLocation AttributeLoc) {
8421 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8422 NumElements, true);
8423 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008424 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8425 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008426 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008427}
Mike Stump1eb44332009-09-09 15:08:12 +00008428
Douglas Gregor577f75a2009-08-04 16:50:30 +00008429template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008430QualType
8431TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008432 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008433 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008434 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008435}
Mike Stump1eb44332009-09-09 15:08:12 +00008436
Douglas Gregor577f75a2009-08-04 16:50:30 +00008437template<typename Derived>
8438QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00008439 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008440 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00008441 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00008442 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00008443 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00008444 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00008445 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregorc938c162011-01-26 05:01:58 +00008446 Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008447 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00008448 getDerived().getBaseEntity(),
8449 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008450}
Mike Stump1eb44332009-09-09 15:08:12 +00008451
Douglas Gregor577f75a2009-08-04 16:50:30 +00008452template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00008453QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8454 return SemaRef.Context.getFunctionNoProtoType(T);
8455}
8456
8457template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00008458QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8459 assert(D && "no decl found");
8460 if (D->isInvalidDecl()) return QualType();
8461
Douglas Gregor92e986e2010-04-22 16:44:27 +00008462 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00008463 TypeDecl *Ty;
8464 if (isa<UsingDecl>(D)) {
8465 UsingDecl *Using = cast<UsingDecl>(D);
8466 assert(Using->isTypeName() &&
8467 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8468
8469 // A valid resolved using typename decl points to exactly one type decl.
8470 assert(++Using->shadow_begin() == Using->shadow_end());
8471 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00008472
John McCalled976492009-12-04 22:46:56 +00008473 } else {
8474 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8475 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8476 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8477 }
8478
8479 return SemaRef.Context.getTypeDeclType(Ty);
8480}
8481
8482template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008483QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8484 SourceLocation Loc) {
8485 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008486}
8487
8488template<typename Derived>
8489QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8490 return SemaRef.Context.getTypeOfType(Underlying);
8491}
8492
8493template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008494QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8495 SourceLocation Loc) {
8496 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008497}
8498
8499template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00008500QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8501 UnaryTransformType::UTTKind UKind,
8502 SourceLocation Loc) {
8503 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8504}
8505
8506template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00008507QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00008508 TemplateName Template,
8509 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00008510 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00008511 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008512}
Mike Stump1eb44332009-09-09 15:08:12 +00008513
Douglas Gregordcee1a12009-08-06 05:28:30 +00008514template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00008515QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
8516 SourceLocation KWLoc) {
8517 return SemaRef.BuildAtomicType(ValueType, KWLoc);
8518}
8519
8520template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008521TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008522TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00008523 bool TemplateKW,
8524 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008525 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00008526 Template);
8527}
8528
8529template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008530TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008531TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8532 const IdentifierInfo &Name,
8533 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00008534 QualType ObjectType,
8535 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008536 UnqualifiedId TemplateName;
8537 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008538 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008539 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00008540 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008541 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00008542 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008543 /*EnteringContext=*/false,
8544 Template);
John McCall43fed0d2010-11-12 08:19:04 +00008545 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00008546}
Mike Stump1eb44332009-09-09 15:08:12 +00008547
Douglas Gregorb98b1992009-08-11 05:31:07 +00008548template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008549TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008550TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008551 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008552 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008553 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008554 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008555 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008556 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008557 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008558 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00008559 Sema::TemplateTy Template;
8560 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008561 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00008562 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008563 /*EnteringContext=*/false,
8564 Template);
8565 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008566}
Sean Huntc3021132010-05-05 15:23:54 +00008567
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008568template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008569ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008570TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8571 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00008572 Expr *OrigCallee,
8573 Expr *First,
8574 Expr *Second) {
8575 Expr *Callee = OrigCallee->IgnoreParenCasts();
8576 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00008577
Douglas Gregorb98b1992009-08-11 05:31:07 +00008578 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00008579 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00008580 if (!First->getType()->isOverloadableType() &&
8581 !Second->getType()->isOverloadableType())
8582 return getSema().CreateBuiltinArraySubscriptExpr(First,
8583 Callee->getLocStart(),
8584 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00008585 } else if (Op == OO_Arrow) {
8586 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00008587 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8588 } else if (Second == 0 || isPostIncDec) {
8589 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008590 // The argument is not of overloadable type, so try to create a
8591 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00008592 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008593 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00008594
John McCall9ae2f072010-08-23 23:25:46 +00008595 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008596 }
8597 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008598 if (!First->getType()->isOverloadableType() &&
8599 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008600 // Neither of the arguments is an overloadable type, so try to
8601 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00008602 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008603 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00008604 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008605 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008606 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008607
Douglas Gregorb98b1992009-08-11 05:31:07 +00008608 return move(Result);
8609 }
8610 }
Mike Stump1eb44332009-09-09 15:08:12 +00008611
8612 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00008613 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00008614 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00008615
John McCall9ae2f072010-08-23 23:25:46 +00008616 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00008617 assert(ULE->requiresADL());
8618
8619 // FIXME: Do we have to check
8620 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00008621 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00008622 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008623 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00008624 }
Mike Stump1eb44332009-09-09 15:08:12 +00008625
Douglas Gregorb98b1992009-08-11 05:31:07 +00008626 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00008627 Expr *Args[2] = { First, Second };
8628 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00008629
Douglas Gregorb98b1992009-08-11 05:31:07 +00008630 // Create the overloaded operator invocation for unary operators.
8631 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00008632 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008633 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00008634 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008635 }
Mike Stump1eb44332009-09-09 15:08:12 +00008636
Douglas Gregor5b8968c2011-07-15 16:25:15 +00008637 if (Op == OO_Subscript) {
8638 SourceLocation LBrace;
8639 SourceLocation RBrace;
8640
8641 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
8642 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
8643 LBrace = SourceLocation::getFromRawEncoding(
8644 NameLoc.CXXOperatorName.BeginOpNameLoc);
8645 RBrace = SourceLocation::getFromRawEncoding(
8646 NameLoc.CXXOperatorName.EndOpNameLoc);
8647 } else {
8648 LBrace = Callee->getLocStart();
8649 RBrace = OpLoc;
8650 }
8651
8652 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
8653 First, Second);
8654 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00008655
Douglas Gregorb98b1992009-08-11 05:31:07 +00008656 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00008657 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008658 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00008659 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8660 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008661 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008662
Mike Stump1eb44332009-09-09 15:08:12 +00008663 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008664}
Mike Stump1eb44332009-09-09 15:08:12 +00008665
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008666template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008667ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00008668TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008669 SourceLocation OperatorLoc,
8670 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00008671 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008672 TypeSourceInfo *ScopeType,
8673 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008674 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008675 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00008676 QualType BaseType = Base->getType();
8677 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008678 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00008679 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00008680 !BaseType->getAs<PointerType>()->getPointeeType()
8681 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008682 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00008683 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008684 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008685 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008686 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008687 /*FIXME?*/true);
8688 }
Abramo Bagnara25777432010-08-11 22:01:17 +00008689
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008690 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00008691 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8692 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8693 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8694 NameInfo.setNamedTypeInfo(DestroyedType);
8695
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008696 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00008697
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008698 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00008699 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008700 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008701 SS, TemplateKWLoc,
8702 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00008703 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008704 /*TemplateArgs*/ 0);
8705}
8706
Douglas Gregor577f75a2009-08-04 16:50:30 +00008707} // end namespace clang
8708
8709#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H