blob: a30a0d036af6fd7354aac439bf79ae5e1361ef54 [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregord6ff3322009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
John McCall83024632010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor840bd6c2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCallaab3e412010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000024#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000025#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000026#include "clang/AST/ExprCXX.h"
27#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000028#include "clang/AST/Stmt.h"
29#include "clang/AST/StmtCXX.h"
30#include "clang/AST/StmtObjC.h"
John McCall8b0666c2010-08-20 18:27:03 +000031#include "clang/Sema/Ownership.h"
32#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000033#include "clang/Lex/Preprocessor.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000034#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000035#include "llvm/Support/ErrorHandling.h"
Douglas Gregor451d1b12010-12-02 00:05:49 +000036#include "TypeLocBuilder.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000040using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000041
Douglas Gregord6ff3322009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump11289f42009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump11289f42009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
101
102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
106
107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
111
Douglas Gregord6ff3322009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000114
Mike Stump11289f42009-09-09 15:08:12 +0000115public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000116 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000117 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000118
Douglas Gregord6ff3322009-08-04 16:50:30 +0000119 /// \brief Retrieves a reference to the derived class.
120 Derived &getDerived() { return static_cast<Derived&>(*this); }
121
122 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000123 const Derived &getDerived() const {
124 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000125 }
126
John McCalldadc5752010-08-24 06:29:42 +0000127 static inline ExprResult Owned(Expr *E) { return E; }
128 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000129
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 /// \brief Retrieves a reference to the semantic analysis object used for
131 /// this tree transform.
132 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000133
Douglas Gregord6ff3322009-08-04 16:50:30 +0000134 /// \brief Whether the transformation should always rebuild AST nodes, even
135 /// if none of the children have changed.
136 ///
137 /// Subclasses may override this function to specify when the transformation
138 /// should rebuild all AST nodes.
139 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000140
Douglas Gregord6ff3322009-08-04 16:50:30 +0000141 /// \brief Returns the location of the entity being transformed, if that
142 /// information was not available elsewhere in the AST.
143 ///
Mike Stump11289f42009-09-09 15:08:12 +0000144 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000145 /// provide an alternative implementation that provides better location
146 /// information.
147 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000148
Douglas Gregord6ff3322009-08-04 16:50:30 +0000149 /// \brief Returns the name of the entity being transformed, if that
150 /// information was not available elsewhere in the AST.
151 ///
152 /// By default, returns an empty name. Subclasses can provide an alternative
153 /// implementation with a more precise name.
154 DeclarationName getBaseEntity() { return DeclarationName(); }
155
Douglas Gregora16548e2009-08-11 05:31:07 +0000156 /// \brief Sets the "base" location and entity when that
157 /// information is known based on another transformation.
158 ///
159 /// By default, the source location and entity are ignored. Subclasses can
160 /// override this function to provide a customized implementation.
161 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000162
Douglas Gregora16548e2009-08-11 05:31:07 +0000163 /// \brief RAII object that temporarily sets the base location and entity
164 /// used for reporting diagnostics in types.
165 class TemporaryBase {
166 TreeTransform &Self;
167 SourceLocation OldLocation;
168 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000169
Douglas Gregora16548e2009-08-11 05:31:07 +0000170 public:
171 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000172 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000173 OldLocation = Self.getDerived().getBaseLocation();
174 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregora518d5b2011-01-25 17:51:48 +0000175
176 if (Location.isValid())
177 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000178 }
Mike Stump11289f42009-09-09 15:08:12 +0000179
Douglas Gregora16548e2009-08-11 05:31:07 +0000180 ~TemporaryBase() {
181 Self.getDerived().setBase(OldLocation, OldEntity);
182 }
183 };
Mike Stump11289f42009-09-09 15:08:12 +0000184
185 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000186 /// transformed.
187 ///
188 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000189 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000190 /// not change. For example, template instantiation need not traverse
191 /// non-dependent types.
192 bool AlreadyTransformed(QualType T) {
193 return T.isNull();
194 }
195
Douglas Gregord196a582009-12-14 19:27:10 +0000196 /// \brief Determine whether the given call argument should be dropped, e.g.,
197 /// because it is a default argument.
198 ///
199 /// Subclasses can provide an alternative implementation of this routine to
200 /// determine which kinds of call arguments get dropped. By default,
201 /// CXXDefaultArgument nodes are dropped (prior to transformation).
202 bool DropCallArgument(Expr *E) {
203 return E->isDefaultArgument();
204 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000205
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000206 /// \brief Determine whether we should expand a pack expansion with the
207 /// given set of parameter packs into separate arguments by repeatedly
208 /// transforming the pattern.
209 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000210 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000211 /// Subclasses can override this routine to provide different behavior.
212 ///
213 /// \param EllipsisLoc The location of the ellipsis that identifies the
214 /// pack expansion.
215 ///
216 /// \param PatternRange The source range that covers the entire pattern of
217 /// the pack expansion.
218 ///
219 /// \param Unexpanded The set of unexpanded parameter packs within the
220 /// pattern.
221 ///
222 /// \param NumUnexpanded The number of unexpanded parameter packs in
223 /// \p Unexpanded.
224 ///
225 /// \param ShouldExpand Will be set to \c true if the transformer should
226 /// expand the corresponding pack expansions into separate arguments. When
227 /// set, \c NumExpansions must also be set.
228 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000229 /// \param RetainExpansion Whether the caller should add an unexpanded
230 /// pack expansion after all of the expanded arguments. This is used
231 /// when extending explicitly-specified template argument packs per
232 /// C++0x [temp.arg.explicit]p9.
233 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000234 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000235 /// the expanded form of the corresponding pack expansion. This is both an
236 /// input and an output parameter, which can be set by the caller if the
237 /// number of expansions is known a priori (e.g., due to a prior substitution)
238 /// and will be set by the callee when the number of expansions is known.
239 /// The callee must set this value when \c ShouldExpand is \c true; it may
240 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000241 ///
242 /// \returns true if an error occurred (e.g., because the parameter packs
243 /// are to be instantiated with arguments of different lengths), false
244 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
245 /// must be set.
246 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
247 SourceRange PatternRange,
David Blaikieb9c168a2011-09-22 02:34:54 +0000248 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000249 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000250 bool &RetainExpansion,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000251 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000252 ShouldExpand = false;
253 return false;
254 }
255
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000256 /// \brief "Forget" about the partially-substituted pack template argument,
257 /// when performing an instantiation that must preserve the parameter pack
258 /// use.
259 ///
260 /// This routine is meant to be overridden by the template instantiator.
261 TemplateArgument ForgetPartiallySubstitutedPack() {
262 return TemplateArgument();
263 }
264
265 /// \brief "Remember" the partially-substituted pack template argument
266 /// after performing an instantiation that must preserve the parameter pack
267 /// use.
268 ///
269 /// This routine is meant to be overridden by the template instantiator.
270 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
271
Douglas Gregorf3010112011-01-07 16:43:16 +0000272 /// \brief Note to the derived class when a function parameter pack is
273 /// being expanded.
274 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
275
Douglas Gregord6ff3322009-08-04 16:50:30 +0000276 /// \brief Transforms the given type into another type.
277 ///
John McCall550e0c22009-10-21 00:40:46 +0000278 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000279 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000280 /// function. This is expensive, but we don't mind, because
281 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000282 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 ///
284 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000285 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000286
John McCall550e0c22009-10-21 00:40:46 +0000287 /// \brief Transforms the given type-with-location into a new
288 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
John McCall550e0c22009-10-21 00:40:46 +0000290 /// By default, this routine transforms a type by delegating to the
291 /// appropriate TransformXXXType to build a new type. Subclasses
292 /// may override this function (to take over all type
293 /// transformations) or some set of the TransformXXXType functions
294 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000295 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000296
297 /// \brief Transform the given type-with-location into a new
298 /// type, collecting location information in the given builder
299 /// as necessary.
300 ///
John McCall31f82722010-11-12 08:19:04 +0000301 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000302
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000303 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000304 ///
Mike Stump11289f42009-09-09 15:08:12 +0000305 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000306 /// appropriate TransformXXXStmt function to transform a specific kind of
307 /// statement or the TransformExpr() function to transform an expression.
308 /// Subclasses may override this function to transform statements using some
309 /// other mechanism.
310 ///
311 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000312 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000313
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000314 /// \brief Transform the given expression.
315 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000316 /// By default, this routine transforms an expression by delegating to the
317 /// appropriate TransformXXXExpr function to build a new expression.
318 /// Subclasses may override this function to transform expressions using some
319 /// other mechanism.
320 ///
321 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000322 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000323
Douglas Gregora3efea12011-01-03 19:04:46 +0000324 /// \brief Transform the given list of expressions.
325 ///
326 /// This routine transforms a list of expressions by invoking
327 /// \c TransformExpr() for each subexpression. However, it also provides
328 /// support for variadic templates by expanding any pack expansions (if the
329 /// derived class permits such expansion) along the way. When pack expansions
330 /// are present, the number of outputs may not equal the number of inputs.
331 ///
332 /// \param Inputs The set of expressions to be transformed.
333 ///
334 /// \param NumInputs The number of expressions in \c Inputs.
335 ///
336 /// \param IsCall If \c true, then this transform is being performed on
337 /// function-call arguments, and any arguments that should be dropped, will
338 /// be.
339 ///
340 /// \param Outputs The transformed input expressions will be added to this
341 /// vector.
342 ///
343 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
344 /// due to transformation.
345 ///
346 /// \returns true if an error occurred, false otherwise.
347 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000348 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +0000349 bool *ArgChanged = 0);
350
Douglas Gregord6ff3322009-08-04 16:50:30 +0000351 /// \brief Transform the given declaration, which is referenced from a type
352 /// or expression.
353 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000354 /// By default, acts as the identity function on declarations. Subclasses
355 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000356 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000357
358 /// \brief Transform the definition of the given declaration.
359 ///
Mike Stump11289f42009-09-09 15:08:12 +0000360 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000361 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000362 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
363 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000364 }
Mike Stump11289f42009-09-09 15:08:12 +0000365
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000366 /// \brief Transform the given declaration, which was the first part of a
367 /// nested-name-specifier in a member access expression.
368 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000369 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000370 /// identifier in a nested-name-specifier of a member access expression, e.g.,
371 /// the \c T in \c x->T::member
372 ///
373 /// By default, invokes TransformDecl() to transform the declaration.
374 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000375 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
376 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000377 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000378
Douglas Gregor14454802011-02-25 02:25:35 +0000379 /// \brief Transform the given nested-name-specifier with source-location
380 /// information.
381 ///
382 /// By default, transforms all of the types and declarations within the
383 /// nested-name-specifier. Subclasses may override this function to provide
384 /// alternate behavior.
385 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
386 NestedNameSpecifierLoc NNS,
387 QualType ObjectType = QualType(),
388 NamedDecl *FirstQualifierInScope = 0);
389
Douglas Gregorf816bd72009-09-03 22:13:48 +0000390 /// \brief Transform the given declaration name.
391 ///
392 /// By default, transforms the types of conversion function, constructor,
393 /// and destructor names and then (if needed) rebuilds the declaration name.
394 /// Identifiers and selectors are returned unmodified. Sublcasses may
395 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000396 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000397 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000398
Douglas Gregord6ff3322009-08-04 16:50:30 +0000399 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000400 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000401 /// \param SS The nested-name-specifier that qualifies the template
402 /// name. This nested-name-specifier must already have been transformed.
403 ///
404 /// \param Name The template name to transform.
405 ///
406 /// \param NameLoc The source location of the template name.
407 ///
408 /// \param ObjectType If we're translating a template name within a member
409 /// access expression, this is the type of the object whose member template
410 /// is being referenced.
411 ///
412 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
413 /// also refers to a name within the current (lexical) scope, this is the
414 /// declaration it refers to.
415 ///
416 /// By default, transforms the template name by transforming the declarations
417 /// and nested-name-specifiers that occur within the template name.
418 /// Subclasses may override this function to provide alternate behavior.
419 TemplateName TransformTemplateName(CXXScopeSpec &SS,
420 TemplateName Name,
421 SourceLocation NameLoc,
422 QualType ObjectType = QualType(),
423 NamedDecl *FirstQualifierInScope = 0);
424
Douglas Gregord6ff3322009-08-04 16:50:30 +0000425 /// \brief Transform the given template argument.
426 ///
Mike Stump11289f42009-09-09 15:08:12 +0000427 /// By default, this operation transforms the type, expression, or
428 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000429 /// new template argument from the transformed result. Subclasses may
430 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000431 ///
432 /// Returns true if there was an error.
433 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
434 TemplateArgumentLoc &Output);
435
Douglas Gregor62e06f22010-12-20 17:31:10 +0000436 /// \brief Transform the given set of template arguments.
437 ///
438 /// By default, this operation transforms all of the template arguments
439 /// in the input set using \c TransformTemplateArgument(), and appends
440 /// the transformed arguments to the output list.
441 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000442 /// Note that this overload of \c TransformTemplateArguments() is merely
443 /// a convenience function. Subclasses that wish to override this behavior
444 /// should override the iterator-based member template version.
445 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000446 /// \param Inputs The set of template arguments to be transformed.
447 ///
448 /// \param NumInputs The number of template arguments in \p Inputs.
449 ///
450 /// \param Outputs The set of transformed template arguments output by this
451 /// routine.
452 ///
453 /// Returns true if an error occurred.
454 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
455 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000456 TemplateArgumentListInfo &Outputs) {
457 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
458 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000459
460 /// \brief Transform the given set of template arguments.
461 ///
462 /// By default, this operation transforms all of the template arguments
463 /// in the input set using \c TransformTemplateArgument(), and appends
464 /// the transformed arguments to the output list.
465 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000466 /// \param First An iterator to the first template argument.
467 ///
468 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000469 ///
470 /// \param Outputs The set of transformed template arguments output by this
471 /// routine.
472 ///
473 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000474 template<typename InputIterator>
475 bool TransformTemplateArguments(InputIterator First,
476 InputIterator Last,
477 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000478
John McCall0ad16662009-10-29 08:12:44 +0000479 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
480 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
481 TemplateArgumentLoc &ArgLoc);
482
John McCallbcd03502009-12-07 02:54:59 +0000483 /// \brief Fakes up a TypeSourceInfo for a type.
484 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
485 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000486 getDerived().getBaseLocation());
487 }
Mike Stump11289f42009-09-09 15:08:12 +0000488
John McCall550e0c22009-10-21 00:40:46 +0000489#define ABSTRACT_TYPELOC(CLASS, PARENT)
490#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000491 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000492#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000493
John Wiegley1c0675e2011-04-28 01:08:34 +0000494 StmtResult
495 TransformSEHHandler(Stmt *Handler);
496
John McCall31f82722010-11-12 08:19:04 +0000497 QualType
498 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
499 TemplateSpecializationTypeLoc TL,
500 TemplateName Template);
501
502 QualType
503 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
504 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000505 TemplateName Template,
506 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000507
508 QualType
509 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000510 DependentTemplateSpecializationTypeLoc TL,
511 NestedNameSpecifierLoc QualifierLoc);
512
John McCall58f10c32010-03-11 09:03:00 +0000513 /// \brief Transforms the parameters of a function type into the
514 /// given vectors.
515 ///
516 /// The result vectors should be kept in sync; null entries in the
517 /// variables vector are acceptable.
518 ///
519 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000520 bool TransformFunctionTypeParams(SourceLocation Loc,
521 ParmVarDecl **Params, unsigned NumParams,
522 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000523 SmallVectorImpl<QualType> &PTypes,
524 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000525
526 /// \brief Transforms a single function-type parameter. Return null
527 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000528 ///
529 /// \param indexAdjustment - A number to add to the parameter's
530 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000531 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000532 int indexAdjustment,
Douglas Gregor715e4612011-01-14 22:40:04 +0000533 llvm::Optional<unsigned> NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +0000534
John McCall31f82722010-11-12 08:19:04 +0000535 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000536
John McCalldadc5752010-08-24 06:29:42 +0000537 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
538 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000539
Douglas Gregorebe10102009-08-20 07:17:43 +0000540#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000541 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000542#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000543 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000544#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000545#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000546
Douglas Gregord6ff3322009-08-04 16:50:30 +0000547 /// \brief Build a new pointer type given its pointee type.
548 ///
549 /// By default, performs semantic analysis when building the pointer type.
550 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000551 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000552
553 /// \brief Build a new block pointer type given its pointee type.
554 ///
Mike Stump11289f42009-09-09 15:08:12 +0000555 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000556 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000557 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000558
John McCall70dd5f62009-10-30 00:06:24 +0000559 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000560 ///
John McCall70dd5f62009-10-30 00:06:24 +0000561 /// By default, performs semantic analysis when building the
562 /// reference type. Subclasses may override this routine to provide
563 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000564 ///
John McCall70dd5f62009-10-30 00:06:24 +0000565 /// \param LValue whether the type was written with an lvalue sigil
566 /// or an rvalue sigil.
567 QualType RebuildReferenceType(QualType ReferentType,
568 bool LValue,
569 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000570
Douglas Gregord6ff3322009-08-04 16:50:30 +0000571 /// \brief Build a new member pointer type given the pointee type and the
572 /// class type it refers into.
573 ///
574 /// By default, performs semantic analysis when building the member pointer
575 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000576 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
577 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000578
Douglas Gregord6ff3322009-08-04 16:50:30 +0000579 /// \brief Build a new array type given the element type, size
580 /// modifier, size of the array (if known), size expression, and index type
581 /// qualifiers.
582 ///
583 /// By default, performs semantic analysis when building the array type.
584 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000585 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000586 QualType RebuildArrayType(QualType ElementType,
587 ArrayType::ArraySizeModifier SizeMod,
588 const llvm::APInt *Size,
589 Expr *SizeExpr,
590 unsigned IndexTypeQuals,
591 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000592
Douglas Gregord6ff3322009-08-04 16:50:30 +0000593 /// \brief Build a new constant array type given the element type, size
594 /// modifier, (known) size of the array, and index type qualifiers.
595 ///
596 /// By default, performs semantic analysis when building the array type.
597 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000598 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000599 ArrayType::ArraySizeModifier SizeMod,
600 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000601 unsigned IndexTypeQuals,
602 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000603
Douglas Gregord6ff3322009-08-04 16:50:30 +0000604 /// \brief Build a new incomplete array type given the element type, size
605 /// modifier, and index type qualifiers.
606 ///
607 /// By default, performs semantic analysis when building the array type.
608 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000609 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000610 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000611 unsigned IndexTypeQuals,
612 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000613
Mike Stump11289f42009-09-09 15:08:12 +0000614 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000615 /// size modifier, size expression, and index type qualifiers.
616 ///
617 /// By default, performs semantic analysis when building the array type.
618 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000619 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000620 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000621 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000622 unsigned IndexTypeQuals,
623 SourceRange BracketsRange);
624
Mike Stump11289f42009-09-09 15:08:12 +0000625 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000626 /// size modifier, size expression, and index type qualifiers.
627 ///
628 /// By default, performs semantic analysis when building the array type.
629 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000630 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000631 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000632 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000633 unsigned IndexTypeQuals,
634 SourceRange BracketsRange);
635
636 /// \brief Build a new vector type given the element type and
637 /// number of elements.
638 ///
639 /// By default, performs semantic analysis when building the vector type.
640 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000641 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000642 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000643
Douglas Gregord6ff3322009-08-04 16:50:30 +0000644 /// \brief Build a new extended vector type given the element type and
645 /// number of elements.
646 ///
647 /// By default, performs semantic analysis when building the vector type.
648 /// Subclasses may override this routine to provide different behavior.
649 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
650 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000651
652 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000653 /// given the element type and number of elements.
654 ///
655 /// By default, performs semantic analysis when building the vector type.
656 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000657 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000658 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000659 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000660
Douglas Gregord6ff3322009-08-04 16:50:30 +0000661 /// \brief Build a new function type.
662 ///
663 /// By default, performs semantic analysis when building the function type.
664 /// Subclasses may override this routine to provide different behavior.
665 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000666 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000667 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000668 bool Variadic, unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +0000669 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +0000670 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000671
John McCall550e0c22009-10-21 00:40:46 +0000672 /// \brief Build a new unprototyped function type.
673 QualType RebuildFunctionNoProtoType(QualType ResultType);
674
John McCallb96ec562009-12-04 22:46:56 +0000675 /// \brief Rebuild an unresolved typename type, given the decl that
676 /// the UnresolvedUsingTypenameDecl was transformed to.
677 QualType RebuildUnresolvedUsingType(Decl *D);
678
Douglas Gregord6ff3322009-08-04 16:50:30 +0000679 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000680 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000681 return SemaRef.Context.getTypeDeclType(Typedef);
682 }
683
684 /// \brief Build a new class/struct/union type.
685 QualType RebuildRecordType(RecordDecl *Record) {
686 return SemaRef.Context.getTypeDeclType(Record);
687 }
688
689 /// \brief Build a new Enum type.
690 QualType RebuildEnumType(EnumDecl *Enum) {
691 return SemaRef.Context.getTypeDeclType(Enum);
692 }
John McCallfcc33b02009-09-05 00:15:47 +0000693
Mike Stump11289f42009-09-09 15:08:12 +0000694 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000695 ///
696 /// By default, performs semantic analysis when building the typeof type.
697 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000698 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000699
Mike Stump11289f42009-09-09 15:08:12 +0000700 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000701 ///
702 /// By default, builds a new TypeOfType with the given underlying type.
703 QualType RebuildTypeOfType(QualType Underlying);
704
Alexis Hunte852b102011-05-24 22:41:36 +0000705 /// \brief Build a new unary transform type.
706 QualType RebuildUnaryTransformType(QualType BaseType,
707 UnaryTransformType::UTTKind UKind,
708 SourceLocation Loc);
709
Mike Stump11289f42009-09-09 15:08:12 +0000710 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000711 ///
712 /// By default, performs semantic analysis when building the decltype type.
713 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000714 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000715
Richard Smith30482bc2011-02-20 03:19:35 +0000716 /// \brief Build a new C++0x auto type.
717 ///
718 /// By default, builds a new AutoType with the given deduced type.
719 QualType RebuildAutoType(QualType Deduced) {
720 return SemaRef.Context.getAutoType(Deduced);
721 }
722
Douglas Gregord6ff3322009-08-04 16:50:30 +0000723 /// \brief Build a new template specialization type.
724 ///
725 /// By default, performs semantic analysis when building the template
726 /// specialization type. Subclasses may override this routine to provide
727 /// different behavior.
728 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000729 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000730 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000731
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000732 /// \brief Build a new parenthesized type.
733 ///
734 /// By default, builds a new ParenType type from the inner type.
735 /// Subclasses may override this routine to provide different behavior.
736 QualType RebuildParenType(QualType InnerType) {
737 return SemaRef.Context.getParenType(InnerType);
738 }
739
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740 /// \brief Build a new qualified name type.
741 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000742 /// By default, builds a new ElaboratedType type from the keyword,
743 /// the nested-name-specifier and the named type.
744 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000745 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
746 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000747 NestedNameSpecifierLoc QualifierLoc,
748 QualType Named) {
749 return SemaRef.Context.getElaboratedType(Keyword,
750 QualifierLoc.getNestedNameSpecifier(),
751 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000752 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000753
754 /// \brief Build a new typename type that refers to a template-id.
755 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000756 /// By default, builds a new DependentNameType type from the
757 /// nested-name-specifier and the given type. Subclasses may override
758 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000759 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000760 ElaboratedTypeKeyword Keyword,
761 NestedNameSpecifierLoc QualifierLoc,
762 const IdentifierInfo *Name,
763 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000764 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000765 // Rebuild the template name.
766 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000767 CXXScopeSpec SS;
768 SS.Adopt(QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000769 TemplateName InstName
Douglas Gregor9db53502011-03-02 18:07:45 +0000770 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000771
772 if (InstName.isNull())
773 return QualType();
774
775 // If it's still dependent, make a dependent specialization.
776 if (InstName.getAsDependentTemplateName())
777 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
778 QualifierLoc.getNestedNameSpecifier(),
779 Name,
780 Args);
781
782 // Otherwise, make an elaborated type wrapping a non-dependent
783 // specialization.
784 QualType T =
785 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
786 if (T.isNull()) return QualType();
787
788 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
789 return T;
790
791 return SemaRef.Context.getElaboratedType(Keyword,
792 QualifierLoc.getNestedNameSpecifier(),
793 T);
794 }
795
Douglas Gregord6ff3322009-08-04 16:50:30 +0000796 /// \brief Build a new typename type that refers to an identifier.
797 ///
798 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000799 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000800 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000801 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000802 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000803 NestedNameSpecifierLoc QualifierLoc,
804 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000805 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000806 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000807 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000808
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000809 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000810 // If the name is still dependent, just build a new dependent name type.
811 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000812 return SemaRef.Context.getDependentNameType(Keyword,
813 QualifierLoc.getNestedNameSpecifier(),
814 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000815 }
816
Abramo Bagnara6150c882010-05-11 21:36:43 +0000817 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000818 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000819 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000820
821 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
822
Abramo Bagnarad7548482010-05-19 21:37:53 +0000823 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000824 // into a non-dependent elaborated-type-specifier. Find the tag we're
825 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000826 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000827 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
828 if (!DC)
829 return QualType();
830
John McCallbf8c5192010-05-27 06:40:31 +0000831 if (SemaRef.RequireCompleteDeclContext(SS, DC))
832 return QualType();
833
Douglas Gregore677daf2010-03-31 22:19:08 +0000834 TagDecl *Tag = 0;
835 SemaRef.LookupQualifiedName(Result, DC);
836 switch (Result.getResultKind()) {
837 case LookupResult::NotFound:
838 case LookupResult::NotFoundInCurrentInstantiation:
839 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000840
Douglas Gregore677daf2010-03-31 22:19:08 +0000841 case LookupResult::Found:
842 Tag = Result.getAsSingle<TagDecl>();
843 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000844
Douglas Gregore677daf2010-03-31 22:19:08 +0000845 case LookupResult::FoundOverloaded:
846 case LookupResult::FoundUnresolvedValue:
847 llvm_unreachable("Tag lookup cannot find non-tags");
848 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000849
Douglas Gregore677daf2010-03-31 22:19:08 +0000850 case LookupResult::Ambiguous:
851 // Let the LookupResult structure handle ambiguities.
852 return QualType();
853 }
854
855 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000856 // Check where the name exists but isn't a tag type and use that to emit
857 // better diagnostics.
858 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
859 SemaRef.LookupQualifiedName(Result, DC);
860 switch (Result.getResultKind()) {
861 case LookupResult::Found:
862 case LookupResult::FoundOverloaded:
863 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000864 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000865 unsigned Kind = 0;
866 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000867 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
868 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000869 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
870 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
871 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000872 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000873 default:
874 // FIXME: Would be nice to highlight just the source range.
875 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
876 << Kind << Id << DC;
877 break;
878 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000879 return QualType();
880 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000881
Richard Trieucaa33d32011-06-10 03:11:26 +0000882 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
883 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000884 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000885 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
886 return QualType();
887 }
888
889 // Build the elaborated-type-specifier type.
890 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000891 return SemaRef.Context.getElaboratedType(Keyword,
892 QualifierLoc.getNestedNameSpecifier(),
893 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000894 }
Mike Stump11289f42009-09-09 15:08:12 +0000895
Douglas Gregor822d0302011-01-12 17:07:58 +0000896 /// \brief Build a new pack expansion type.
897 ///
898 /// By default, builds a new PackExpansionType type from the given pattern.
899 /// Subclasses may override this routine to provide different behavior.
900 QualType RebuildPackExpansionType(QualType Pattern,
901 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000902 SourceLocation EllipsisLoc,
903 llvm::Optional<unsigned> NumExpansions) {
904 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
905 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000906 }
907
Eli Friedman0dfb8892011-10-06 23:00:33 +0000908 /// \brief Build a new atomic type given its value type.
909 ///
910 /// By default, performs semantic analysis when building the atomic type.
911 /// Subclasses may override this routine to provide different behavior.
912 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
913
Douglas Gregor71dc5092009-08-06 06:41:21 +0000914 /// \brief Build a new template name given a nested name specifier, a flag
915 /// indicating whether the "template" keyword was provided, and the template
916 /// that the template name refers to.
917 ///
918 /// By default, builds the new template name directly. Subclasses may override
919 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000920 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +0000921 bool TemplateKW,
922 TemplateDecl *Template);
923
Douglas Gregor71dc5092009-08-06 06:41:21 +0000924 /// \brief Build a new template name given a nested name specifier and the
925 /// name that is referred to as a template.
926 ///
927 /// By default, performs semantic analysis to determine whether the name can
928 /// be resolved to a specific template, then builds the appropriate kind of
929 /// template name. Subclasses may override this routine to provide different
930 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000931 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
932 const IdentifierInfo &Name,
933 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +0000934 QualType ObjectType,
935 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000936
Douglas Gregor71395fa2009-11-04 00:56:37 +0000937 /// \brief Build a new template name given a nested name specifier and the
938 /// overloaded operator name that is referred to as a template.
939 ///
940 /// By default, performs semantic analysis to determine whether the name can
941 /// be resolved to a specific template, then builds the appropriate kind of
942 /// template name. Subclasses may override this routine to provide different
943 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000944 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000945 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +0000946 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000947 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000948
949 /// \brief Build a new template name given a template template parameter pack
950 /// and the
951 ///
952 /// By default, performs semantic analysis to determine whether the name can
953 /// be resolved to a specific template, then builds the appropriate kind of
954 /// template name. Subclasses may override this routine to provide different
955 /// behavior.
956 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
957 const TemplateArgument &ArgPack) {
958 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
959 }
960
Douglas Gregorebe10102009-08-20 07:17:43 +0000961 /// \brief Build a new compound statement.
962 ///
963 /// By default, performs semantic analysis to build the new statement.
964 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000965 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000966 MultiStmtArg Statements,
967 SourceLocation RBraceLoc,
968 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000969 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000970 IsStmtExpr);
971 }
972
973 /// \brief Build a new case statement.
974 ///
975 /// By default, performs semantic analysis to build the new statement.
976 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000977 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000978 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000979 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000980 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000981 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000982 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000983 ColonLoc);
984 }
Mike Stump11289f42009-09-09 15:08:12 +0000985
Douglas Gregorebe10102009-08-20 07:17:43 +0000986 /// \brief Attach the body to a new case statement.
987 ///
988 /// By default, performs semantic analysis to build the new statement.
989 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000990 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000991 getSema().ActOnCaseStmtBody(S, Body);
992 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000993 }
Mike Stump11289f42009-09-09 15:08:12 +0000994
Douglas Gregorebe10102009-08-20 07:17:43 +0000995 /// \brief Build a new default statement.
996 ///
997 /// By default, performs semantic analysis to build the new statement.
998 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000999 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001000 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001001 Stmt *SubStmt) {
1002 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +00001003 /*CurScope=*/0);
1004 }
Mike Stump11289f42009-09-09 15:08:12 +00001005
Douglas Gregorebe10102009-08-20 07:17:43 +00001006 /// \brief Build a new label statement.
1007 ///
1008 /// By default, performs semantic analysis to build the new statement.
1009 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001010 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1011 SourceLocation ColonLoc, Stmt *SubStmt) {
1012 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001013 }
Mike Stump11289f42009-09-09 15:08:12 +00001014
Douglas Gregorebe10102009-08-20 07:17:43 +00001015 /// \brief Build a new "if" statement.
1016 ///
1017 /// By default, performs semantic analysis to build the new statement.
1018 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001019 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattnercab02a62011-02-17 20:34:02 +00001020 VarDecl *CondVar, Stmt *Then,
1021 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001022 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001023 }
Mike Stump11289f42009-09-09 15:08:12 +00001024
Douglas Gregorebe10102009-08-20 07:17:43 +00001025 /// \brief Start building a new switch statement.
1026 ///
1027 /// By default, performs semantic analysis to build the new statement.
1028 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001029 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001030 Expr *Cond, VarDecl *CondVar) {
John McCallb268a282010-08-23 23:25:46 +00001031 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001032 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001033 }
Mike Stump11289f42009-09-09 15:08:12 +00001034
Douglas Gregorebe10102009-08-20 07:17:43 +00001035 /// \brief Attach the body to the switch statement.
1036 ///
1037 /// By default, performs semantic analysis to build the new statement.
1038 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001039 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001040 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001041 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001042 }
1043
1044 /// \brief Build a new while statement.
1045 ///
1046 /// By default, performs semantic analysis to build the new statement.
1047 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001048 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1049 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001050 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001051 }
Mike Stump11289f42009-09-09 15:08:12 +00001052
Douglas Gregorebe10102009-08-20 07:17:43 +00001053 /// \brief Build a new do-while statement.
1054 ///
1055 /// By default, performs semantic analysis to build the new statement.
1056 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001057 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001058 SourceLocation WhileLoc, SourceLocation LParenLoc,
1059 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001060 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1061 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001062 }
1063
1064 /// \brief Build a new for statement.
1065 ///
1066 /// By default, performs semantic analysis to build the new statement.
1067 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001068 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1069 Stmt *Init, Sema::FullExprArg Cond,
1070 VarDecl *CondVar, Sema::FullExprArg Inc,
1071 SourceLocation RParenLoc, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001072 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001073 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001074 }
Mike Stump11289f42009-09-09 15:08:12 +00001075
Douglas Gregorebe10102009-08-20 07:17:43 +00001076 /// \brief Build a new goto statement.
1077 ///
1078 /// By default, performs semantic analysis to build the new statement.
1079 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001080 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1081 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001082 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001083 }
1084
1085 /// \brief Build a new indirect goto statement.
1086 ///
1087 /// By default, performs semantic analysis to build the new statement.
1088 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001089 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001090 SourceLocation StarLoc,
1091 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001092 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001093 }
Mike Stump11289f42009-09-09 15:08:12 +00001094
Douglas Gregorebe10102009-08-20 07:17:43 +00001095 /// \brief Build a new return statement.
1096 ///
1097 /// By default, performs semantic analysis to build the new statement.
1098 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001099 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001100 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001101 }
Mike Stump11289f42009-09-09 15:08:12 +00001102
Douglas Gregorebe10102009-08-20 07:17:43 +00001103 /// \brief Build a new declaration statement.
1104 ///
1105 /// By default, performs semantic analysis to build the new statement.
1106 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001107 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001108 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001109 SourceLocation EndLoc) {
Richard Smith2abf6762011-02-23 00:37:57 +00001110 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1111 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001112 }
Mike Stump11289f42009-09-09 15:08:12 +00001113
Anders Carlssonaaeef072010-01-24 05:50:09 +00001114 /// \brief Build a new inline asm statement.
1115 ///
1116 /// By default, performs semantic analysis to build the new statement.
1117 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001118 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001119 bool IsSimple,
1120 bool IsVolatile,
1121 unsigned NumOutputs,
1122 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001123 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001124 MultiExprArg Constraints,
1125 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001126 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001127 MultiExprArg Clobbers,
1128 SourceLocation RParenLoc,
1129 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001130 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001131 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001132 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001133 RParenLoc, MSAsm);
1134 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001135
1136 /// \brief Build a new Objective-C @try statement.
1137 ///
1138 /// By default, performs semantic analysis to build the new statement.
1139 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001140 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001141 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001142 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001143 Stmt *Finally) {
1144 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1145 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001146 }
1147
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001148 /// \brief Rebuild an Objective-C exception declaration.
1149 ///
1150 /// By default, performs semantic analysis to build the new declaration.
1151 /// Subclasses may override this routine to provide different behavior.
1152 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1153 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001154 return getSema().BuildObjCExceptionDecl(TInfo, T,
1155 ExceptionDecl->getInnerLocStart(),
1156 ExceptionDecl->getLocation(),
1157 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001158 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001159
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001160 /// \brief Build a new Objective-C @catch statement.
1161 ///
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001164 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001165 SourceLocation RParenLoc,
1166 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001167 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001168 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001169 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001170 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001171
Douglas Gregor306de2f2010-04-22 23:59:56 +00001172 /// \brief Build a new Objective-C @finally statement.
1173 ///
1174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001176 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001177 Stmt *Body) {
1178 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001179 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001180
Douglas Gregor6148de72010-04-22 22:01:21 +00001181 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001182 ///
1183 /// By default, performs semantic analysis to build the new statement.
1184 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001185 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001186 Expr *Operand) {
1187 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001188 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001189
John McCalld9bb7432011-07-27 21:50:02 +00001190 /// \brief Rebuild the operand to an Objective-C @synchronized statement.
1191 ///
1192 /// By default, performs semantic analysis to build the new statement.
1193 /// Subclasses may override this routine to provide different behavior.
1194 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1195 Expr *object) {
1196 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1197 }
1198
Douglas Gregor6148de72010-04-22 22:01:21 +00001199 /// \brief Build a new Objective-C @synchronized statement.
1200 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001201 /// By default, performs semantic analysis to build the new statement.
1202 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001203 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001204 Expr *Object, Stmt *Body) {
1205 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001206 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001207
John McCall31168b02011-06-15 23:02:42 +00001208 /// \brief Build a new Objective-C @autoreleasepool statement.
1209 ///
1210 /// By default, performs semantic analysis to build the new statement.
1211 /// Subclasses may override this routine to provide different behavior.
1212 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1213 Stmt *Body) {
1214 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1215 }
John McCall53848232011-07-27 01:07:15 +00001216
1217 /// \brief Build the collection operand to a new Objective-C fast
1218 /// enumeration statement.
1219 ///
1220 /// By default, performs semantic analysis to build the new statement.
1221 /// Subclasses may override this routine to provide different behavior.
1222 ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc,
1223 Expr *collection) {
1224 return getSema().ActOnObjCForCollectionOperand(forLoc, collection);
1225 }
John McCall31168b02011-06-15 23:02:42 +00001226
Douglas Gregorf68a5082010-04-22 23:10:45 +00001227 /// \brief Build a new Objective-C fast enumeration statement.
1228 ///
1229 /// By default, performs semantic analysis to build the new statement.
1230 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001231 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001232 SourceLocation LParenLoc,
1233 Stmt *Element,
1234 Expr *Collection,
1235 SourceLocation RParenLoc,
1236 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001237 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001238 Element,
1239 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001240 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001241 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001242 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001243
Douglas Gregorebe10102009-08-20 07:17:43 +00001244 /// \brief Build a new C++ exception declaration.
1245 ///
1246 /// By default, performs semantic analysis to build the new decaration.
1247 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001248 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001249 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001250 SourceLocation StartLoc,
1251 SourceLocation IdLoc,
1252 IdentifierInfo *Id) {
Douglas Gregor40965fa2011-04-14 22:32:28 +00001253 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1254 StartLoc, IdLoc, Id);
1255 if (Var)
1256 getSema().CurContext->addDecl(Var);
1257 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001258 }
1259
1260 /// \brief Build a new C++ catch statement.
1261 ///
1262 /// By default, performs semantic analysis to build the new statement.
1263 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001264 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001265 VarDecl *ExceptionDecl,
1266 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001267 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1268 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001269 }
Mike Stump11289f42009-09-09 15:08:12 +00001270
Douglas Gregorebe10102009-08-20 07:17:43 +00001271 /// \brief Build a new C++ try statement.
1272 ///
1273 /// By default, performs semantic analysis to build the new statement.
1274 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001275 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001276 Stmt *TryBlock,
1277 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001278 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001279 }
Mike Stump11289f42009-09-09 15:08:12 +00001280
Richard Smith02e85f32011-04-14 22:09:26 +00001281 /// \brief Build a new C++0x range-based for statement.
1282 ///
1283 /// By default, performs semantic analysis to build the new statement.
1284 /// Subclasses may override this routine to provide different behavior.
1285 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1286 SourceLocation ColonLoc,
1287 Stmt *Range, Stmt *BeginEnd,
1288 Expr *Cond, Expr *Inc,
1289 Stmt *LoopVar,
1290 SourceLocation RParenLoc) {
1291 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1292 Cond, Inc, LoopVar, RParenLoc);
1293 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001294
1295 /// \brief Build a new C++0x range-based for statement.
1296 ///
1297 /// By default, performs semantic analysis to build the new statement.
1298 /// Subclasses may override this routine to provide different behavior.
1299 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
1300 bool IsIfExists,
1301 NestedNameSpecifierLoc QualifierLoc,
1302 DeclarationNameInfo NameInfo,
1303 Stmt *Nested) {
1304 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1305 QualifierLoc, NameInfo, Nested);
1306 }
1307
Richard Smith02e85f32011-04-14 22:09:26 +00001308 /// \brief Attach body to a C++0x range-based for statement.
1309 ///
1310 /// By default, performs semantic analysis to finish the new statement.
1311 /// Subclasses may override this routine to provide different behavior.
1312 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1313 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1314 }
1315
John Wiegley1c0675e2011-04-28 01:08:34 +00001316 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1317 SourceLocation TryLoc,
1318 Stmt *TryBlock,
1319 Stmt *Handler) {
1320 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1321 }
1322
1323 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1324 Expr *FilterExpr,
1325 Stmt *Block) {
1326 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1327 }
1328
1329 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1330 Stmt *Block) {
1331 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1332 }
1333
Douglas Gregora16548e2009-08-11 05:31:07 +00001334 /// \brief Build a new expression that references a declaration.
1335 ///
1336 /// By default, performs semantic analysis to build the new expression.
1337 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001338 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001339 LookupResult &R,
1340 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001341 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1342 }
1343
1344
1345 /// \brief Build a new expression that references a declaration.
1346 ///
1347 /// By default, performs semantic analysis to build the new expression.
1348 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001349 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001350 ValueDecl *VD,
1351 const DeclarationNameInfo &NameInfo,
1352 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001353 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001354 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001355
1356 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001357
1358 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001359 }
Mike Stump11289f42009-09-09 15:08:12 +00001360
Douglas Gregora16548e2009-08-11 05:31:07 +00001361 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001362 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001363 /// By default, performs semantic analysis to build the new expression.
1364 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001365 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001366 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001367 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001368 }
1369
Douglas Gregorad8a3362009-09-04 17:36:40 +00001370 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001371 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001372 /// By default, performs semantic analysis to build the new expression.
1373 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001374 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001375 SourceLocation OperatorLoc,
1376 bool isArrow,
1377 CXXScopeSpec &SS,
1378 TypeSourceInfo *ScopeType,
1379 SourceLocation CCLoc,
1380 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001381 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001382
Douglas Gregora16548e2009-08-11 05:31:07 +00001383 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001384 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001385 /// By default, performs semantic analysis to build the new expression.
1386 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001387 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001388 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001389 Expr *SubExpr) {
1390 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001391 }
Mike Stump11289f42009-09-09 15:08:12 +00001392
Douglas Gregor882211c2010-04-28 22:16:22 +00001393 /// \brief Build a new builtin offsetof expression.
1394 ///
1395 /// By default, performs semantic analysis to build the new expression.
1396 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001397 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001398 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001399 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001400 unsigned NumComponents,
1401 SourceLocation RParenLoc) {
1402 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1403 NumComponents, RParenLoc);
1404 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001405
Peter Collingbournee190dee2011-03-11 19:24:49 +00001406 /// \brief Build a new sizeof, alignof or vec_step expression with a
1407 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001408 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 /// By default, performs semantic analysis to build the new expression.
1410 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001411 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1412 SourceLocation OpLoc,
1413 UnaryExprOrTypeTrait ExprKind,
1414 SourceRange R) {
1415 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001416 }
1417
Peter Collingbournee190dee2011-03-11 19:24:49 +00001418 /// \brief Build a new sizeof, alignof or vec step expression with an
1419 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001420 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001421 /// By default, performs semantic analysis to build the new expression.
1422 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001423 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1424 UnaryExprOrTypeTrait ExprKind,
1425 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001426 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001427 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001428 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001429 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001430
Douglas Gregora16548e2009-08-11 05:31:07 +00001431 return move(Result);
1432 }
Mike Stump11289f42009-09-09 15:08:12 +00001433
Douglas Gregora16548e2009-08-11 05:31:07 +00001434 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001435 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001436 /// By default, performs semantic analysis to build the new expression.
1437 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001438 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001439 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001440 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001441 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001442 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1443 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001444 RBracketLoc);
1445 }
1446
1447 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001448 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001449 /// By default, performs semantic analysis to build the new expression.
1450 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001451 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001452 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001453 SourceLocation RParenLoc,
1454 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001455 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001456 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001457 }
1458
1459 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001460 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001461 /// By default, performs semantic analysis to build the new expression.
1462 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001463 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001464 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001465 NestedNameSpecifierLoc QualifierLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001466 const DeclarationNameInfo &MemberNameInfo,
1467 ValueDecl *Member,
1468 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001469 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001470 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001471 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1472 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001473 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001474 // We have a reference to an unnamed field. This is always the
1475 // base of an anonymous struct/union member access, i.e. the
1476 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001477 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001478 assert(Member->getType()->isRecordType() &&
1479 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001480
Richard Smithcab9a7d2011-10-26 19:06:56 +00001481 BaseResult =
1482 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley01296292011-04-08 18:41:53 +00001483 QualifierLoc.getNestedNameSpecifier(),
1484 FoundDecl, Member);
1485 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001486 return ExprError();
John Wiegley01296292011-04-08 18:41:53 +00001487 Base = BaseResult.take();
John McCall7decc9e2010-11-18 06:31:45 +00001488 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001489 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001490 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001491 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001492 cast<FieldDecl>(Member)->getType(),
1493 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001494 return getSema().Owned(ME);
1495 }
Mike Stump11289f42009-09-09 15:08:12 +00001496
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001497 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001498 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001499
John Wiegley01296292011-04-08 18:41:53 +00001500 Base = BaseResult.take();
John McCallb268a282010-08-23 23:25:46 +00001501 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001502
John McCall16df1e52010-03-30 21:47:33 +00001503 // FIXME: this involves duplicating earlier analysis in a lot of
1504 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001505 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001506 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001507 R.resolveKind();
1508
John McCallb268a282010-08-23 23:25:46 +00001509 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001510 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001511 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001512 }
Mike Stump11289f42009-09-09 15:08:12 +00001513
Douglas Gregora16548e2009-08-11 05:31:07 +00001514 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001515 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001516 /// By default, performs semantic analysis to build the new expression.
1517 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001518 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001519 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001520 Expr *LHS, Expr *RHS) {
1521 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 }
1523
1524 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001525 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001526 /// By default, performs semantic analysis to build the new expression.
1527 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001528 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001529 SourceLocation QuestionLoc,
1530 Expr *LHS,
1531 SourceLocation ColonLoc,
1532 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001533 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1534 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001535 }
1536
Douglas Gregora16548e2009-08-11 05:31:07 +00001537 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001538 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001539 /// By default, performs semantic analysis to build the new expression.
1540 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001541 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001542 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001544 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001545 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001546 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001547 }
Mike Stump11289f42009-09-09 15:08:12 +00001548
Douglas Gregora16548e2009-08-11 05:31:07 +00001549 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001550 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001551 /// By default, performs semantic analysis to build the new expression.
1552 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001553 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001554 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001555 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001556 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001557 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001558 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001559 }
Mike Stump11289f42009-09-09 15:08:12 +00001560
Douglas Gregora16548e2009-08-11 05:31:07 +00001561 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001562 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001563 /// By default, performs semantic analysis to build the new expression.
1564 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001565 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001566 SourceLocation OpLoc,
1567 SourceLocation AccessorLoc,
1568 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001569
John McCall10eae182009-11-30 22:42:35 +00001570 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001571 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001572 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001573 OpLoc, /*IsArrow*/ false,
1574 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001575 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001576 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001577 }
Mike Stump11289f42009-09-09 15:08:12 +00001578
Douglas Gregora16548e2009-08-11 05:31:07 +00001579 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001580 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001581 /// By default, performs semantic analysis to build the new expression.
1582 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001583 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001584 MultiExprArg Inits,
1585 SourceLocation RBraceLoc,
1586 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001587 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001588 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1589 if (Result.isInvalid() || ResultTy->isDependentType())
1590 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001591
Douglas Gregord3d93062009-11-09 17:16:50 +00001592 // Patch in the result type we were given, which may have been computed
1593 // when the initial InitListExpr was built.
1594 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1595 ILE->setType(ResultTy);
1596 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001597 }
Mike Stump11289f42009-09-09 15:08:12 +00001598
Douglas Gregora16548e2009-08-11 05:31:07 +00001599 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001600 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001601 /// By default, performs semantic analysis to build the new expression.
1602 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001603 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001604 MultiExprArg ArrayExprs,
1605 SourceLocation EqualOrColonLoc,
1606 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001607 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001608 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001609 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001610 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001611 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001612 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001613
Douglas Gregora16548e2009-08-11 05:31:07 +00001614 ArrayExprs.release();
1615 return move(Result);
1616 }
Mike Stump11289f42009-09-09 15:08:12 +00001617
Douglas Gregora16548e2009-08-11 05:31:07 +00001618 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001619 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001620 /// By default, builds the implicit value initialization without performing
1621 /// any semantic analysis. Subclasses may override this routine to provide
1622 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001623 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001624 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1625 }
Mike Stump11289f42009-09-09 15:08:12 +00001626
Douglas Gregora16548e2009-08-11 05:31:07 +00001627 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001628 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001629 /// By default, performs semantic analysis to build the new expression.
1630 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001631 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001632 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001633 SourceLocation RParenLoc) {
1634 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001635 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001636 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001637 }
1638
1639 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001640 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001641 /// By default, performs semantic analysis to build the new expression.
1642 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001643 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001644 MultiExprArg SubExprs,
1645 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001646 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001647 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001648 }
Mike Stump11289f42009-09-09 15:08:12 +00001649
Douglas Gregora16548e2009-08-11 05:31:07 +00001650 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001651 ///
1652 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001653 /// rather than attempting to map the label statement itself.
1654 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001655 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001656 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001657 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 }
Mike Stump11289f42009-09-09 15:08:12 +00001659
Douglas Gregora16548e2009-08-11 05:31:07 +00001660 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001661 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001662 /// By default, performs semantic analysis to build the new expression.
1663 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001664 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001665 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001666 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001667 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001668 }
Mike Stump11289f42009-09-09 15:08:12 +00001669
Douglas Gregora16548e2009-08-11 05:31:07 +00001670 /// \brief Build a new __builtin_choose_expr expression.
1671 ///
1672 /// By default, performs semantic analysis to build the new expression.
1673 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001674 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001675 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001676 SourceLocation RParenLoc) {
1677 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001678 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001679 RParenLoc);
1680 }
Mike Stump11289f42009-09-09 15:08:12 +00001681
Peter Collingbourne91147592011-04-15 00:35:48 +00001682 /// \brief Build a new generic selection expression.
1683 ///
1684 /// By default, performs semantic analysis to build the new expression.
1685 /// Subclasses may override this routine to provide different behavior.
1686 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1687 SourceLocation DefaultLoc,
1688 SourceLocation RParenLoc,
1689 Expr *ControllingExpr,
1690 TypeSourceInfo **Types,
1691 Expr **Exprs,
1692 unsigned NumAssocs) {
1693 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1694 ControllingExpr, Types, Exprs,
1695 NumAssocs);
1696 }
1697
Douglas Gregora16548e2009-08-11 05:31:07 +00001698 /// \brief Build a new overloaded operator call expression.
1699 ///
1700 /// By default, performs semantic analysis to build the new expression.
1701 /// The semantic analysis provides the behavior of template instantiation,
1702 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001703 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001704 /// argument-dependent lookup, etc. Subclasses may override this routine to
1705 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001706 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001707 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001708 Expr *Callee,
1709 Expr *First,
1710 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001711
1712 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001713 /// reinterpret_cast.
1714 ///
1715 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001716 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001717 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001718 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001719 Stmt::StmtClass Class,
1720 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001721 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001722 SourceLocation RAngleLoc,
1723 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001724 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001725 SourceLocation RParenLoc) {
1726 switch (Class) {
1727 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001728 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001729 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001730 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001731
1732 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001733 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001734 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001735 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001736
Douglas Gregora16548e2009-08-11 05:31:07 +00001737 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001738 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001739 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001740 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001741 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001742
Douglas Gregora16548e2009-08-11 05:31:07 +00001743 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001744 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001745 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001746 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001747
Douglas Gregora16548e2009-08-11 05:31:07 +00001748 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001749 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00001750 }
Mike Stump11289f42009-09-09 15:08:12 +00001751
John McCallfaf5fb42010-08-26 23:41:50 +00001752 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001753 }
Mike Stump11289f42009-09-09 15:08:12 +00001754
Douglas Gregora16548e2009-08-11 05:31:07 +00001755 /// \brief Build a new C++ static_cast expression.
1756 ///
1757 /// By default, performs semantic analysis to build the new expression.
1758 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001759 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001760 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001761 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001762 SourceLocation RAngleLoc,
1763 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001764 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001765 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001766 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001767 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001768 SourceRange(LAngleLoc, RAngleLoc),
1769 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001770 }
1771
1772 /// \brief Build a new C++ dynamic_cast expression.
1773 ///
1774 /// By default, performs semantic analysis to build the new expression.
1775 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001776 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001777 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001778 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001779 SourceLocation RAngleLoc,
1780 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001781 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001782 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001783 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001784 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001785 SourceRange(LAngleLoc, RAngleLoc),
1786 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001787 }
1788
1789 /// \brief Build a new C++ reinterpret_cast expression.
1790 ///
1791 /// By default, performs semantic analysis to build the new expression.
1792 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001793 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001794 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001795 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001796 SourceLocation RAngleLoc,
1797 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001798 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001799 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001800 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001801 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001802 SourceRange(LAngleLoc, RAngleLoc),
1803 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001804 }
1805
1806 /// \brief Build a new C++ const_cast expression.
1807 ///
1808 /// By default, performs semantic analysis to build the new expression.
1809 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001810 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001811 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001812 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001813 SourceLocation RAngleLoc,
1814 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001815 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001816 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001817 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001818 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001819 SourceRange(LAngleLoc, RAngleLoc),
1820 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001821 }
Mike Stump11289f42009-09-09 15:08:12 +00001822
Douglas Gregora16548e2009-08-11 05:31:07 +00001823 /// \brief Build a new C++ functional-style cast expression.
1824 ///
1825 /// By default, performs semantic analysis to build the new expression.
1826 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001827 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1828 SourceLocation LParenLoc,
1829 Expr *Sub,
1830 SourceLocation RParenLoc) {
1831 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001832 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001833 RParenLoc);
1834 }
Mike Stump11289f42009-09-09 15:08:12 +00001835
Douglas Gregora16548e2009-08-11 05:31:07 +00001836 /// \brief Build a new C++ typeid(type) expression.
1837 ///
1838 /// By default, performs semantic analysis to build the new expression.
1839 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001840 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001841 SourceLocation TypeidLoc,
1842 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001843 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001844 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001845 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001846 }
Mike Stump11289f42009-09-09 15:08:12 +00001847
Francois Pichet9f4f2072010-09-08 12:20:18 +00001848
Douglas Gregora16548e2009-08-11 05:31:07 +00001849 /// \brief Build a new C++ typeid(expr) expression.
1850 ///
1851 /// By default, performs semantic analysis to build the new expression.
1852 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001853 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001854 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001855 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001856 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001857 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001858 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001859 }
1860
Francois Pichet9f4f2072010-09-08 12:20:18 +00001861 /// \brief Build a new C++ __uuidof(type) expression.
1862 ///
1863 /// By default, performs semantic analysis to build the new expression.
1864 /// Subclasses may override this routine to provide different behavior.
1865 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1866 SourceLocation TypeidLoc,
1867 TypeSourceInfo *Operand,
1868 SourceLocation RParenLoc) {
1869 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1870 RParenLoc);
1871 }
1872
1873 /// \brief Build a new C++ __uuidof(expr) expression.
1874 ///
1875 /// By default, performs semantic analysis to build the new expression.
1876 /// Subclasses may override this routine to provide different behavior.
1877 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1878 SourceLocation TypeidLoc,
1879 Expr *Operand,
1880 SourceLocation RParenLoc) {
1881 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1882 RParenLoc);
1883 }
1884
Douglas Gregora16548e2009-08-11 05:31:07 +00001885 /// \brief Build a new C++ "this" expression.
1886 ///
1887 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001888 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001889 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001890 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001891 QualType ThisType,
1892 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001893 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001894 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1895 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001896 }
1897
1898 /// \brief Build a new C++ throw expression.
1899 ///
1900 /// By default, performs semantic analysis to build the new expression.
1901 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00001902 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1903 bool IsThrownVariableInScope) {
1904 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00001905 }
1906
1907 /// \brief Build a new C++ default-argument expression.
1908 ///
1909 /// By default, builds a new default-argument expression, which does not
1910 /// require any semantic analysis. Subclasses may override this routine to
1911 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001912 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001913 ParmVarDecl *Param) {
1914 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1915 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001916 }
1917
1918 /// \brief Build a new C++ zero-initialization expression.
1919 ///
1920 /// By default, performs semantic analysis to build the new expression.
1921 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001922 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1923 SourceLocation LParenLoc,
1924 SourceLocation RParenLoc) {
1925 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001926 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001927 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001928 }
Mike Stump11289f42009-09-09 15:08:12 +00001929
Douglas Gregora16548e2009-08-11 05:31:07 +00001930 /// \brief Build a new C++ "new" expression.
1931 ///
1932 /// By default, performs semantic analysis to build the new expression.
1933 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001934 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001935 bool UseGlobal,
1936 SourceLocation PlacementLParen,
1937 MultiExprArg PlacementArgs,
1938 SourceLocation PlacementRParen,
1939 SourceRange TypeIdParens,
1940 QualType AllocatedType,
1941 TypeSourceInfo *AllocatedTypeInfo,
1942 Expr *ArraySize,
1943 SourceLocation ConstructorLParen,
1944 MultiExprArg ConstructorArgs,
1945 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001946 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001947 PlacementLParen,
1948 move(PlacementArgs),
1949 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001950 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001951 AllocatedType,
1952 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001953 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001954 ConstructorLParen,
1955 move(ConstructorArgs),
1956 ConstructorRParen);
1957 }
Mike Stump11289f42009-09-09 15:08:12 +00001958
Douglas Gregora16548e2009-08-11 05:31:07 +00001959 /// \brief Build a new C++ "delete" expression.
1960 ///
1961 /// By default, performs semantic analysis to build the new expression.
1962 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001963 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001964 bool IsGlobalDelete,
1965 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001966 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001967 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001968 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001969 }
Mike Stump11289f42009-09-09 15:08:12 +00001970
Douglas Gregora16548e2009-08-11 05:31:07 +00001971 /// \brief Build a new unary type trait expression.
1972 ///
1973 /// By default, performs semantic analysis to build the new expression.
1974 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001975 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001976 SourceLocation StartLoc,
1977 TypeSourceInfo *T,
1978 SourceLocation RParenLoc) {
1979 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001980 }
1981
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001982 /// \brief Build a new binary type trait expression.
1983 ///
1984 /// By default, performs semantic analysis to build the new expression.
1985 /// Subclasses may override this routine to provide different behavior.
1986 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1987 SourceLocation StartLoc,
1988 TypeSourceInfo *LhsT,
1989 TypeSourceInfo *RhsT,
1990 SourceLocation RParenLoc) {
1991 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1992 }
1993
John Wiegley6242b6a2011-04-28 00:16:57 +00001994 /// \brief Build a new array type trait expression.
1995 ///
1996 /// By default, performs semantic analysis to build the new expression.
1997 /// Subclasses may override this routine to provide different behavior.
1998 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
1999 SourceLocation StartLoc,
2000 TypeSourceInfo *TSInfo,
2001 Expr *DimExpr,
2002 SourceLocation RParenLoc) {
2003 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2004 }
2005
John Wiegleyf9f65842011-04-25 06:54:41 +00002006 /// \brief Build a new expression trait expression.
2007 ///
2008 /// By default, performs semantic analysis to build the new expression.
2009 /// Subclasses may override this routine to provide different behavior.
2010 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2011 SourceLocation StartLoc,
2012 Expr *Queried,
2013 SourceLocation RParenLoc) {
2014 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2015 }
2016
Mike Stump11289f42009-09-09 15:08:12 +00002017 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002018 /// expression.
2019 ///
2020 /// By default, performs semantic analysis to build the new expression.
2021 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002022 ExprResult RebuildDependentScopeDeclRefExpr(
2023 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002024 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00002025 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002026 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002027 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002028
2029 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002030 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00002031 *TemplateArgs);
2032
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002033 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00002034 }
2035
2036 /// \brief Build a new template-id expression.
2037 ///
2038 /// By default, performs semantic analysis to build the new expression.
2039 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002040 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00002041 LookupResult &R,
2042 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00002043 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00002044 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002045 }
2046
2047 /// \brief Build a new object-construction expression.
2048 ///
2049 /// By default, performs semantic analysis to build the new expression.
2050 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002051 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002052 SourceLocation Loc,
2053 CXXConstructorDecl *Constructor,
2054 bool IsElidable,
2055 MultiExprArg Args,
2056 bool HadMultipleCandidates,
2057 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002058 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002059 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00002060 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002061 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002062 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002063 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002064
Douglas Gregordb121ba2009-12-14 16:27:04 +00002065 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00002066 move_arg(ConvertedArgs),
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002067 HadMultipleCandidates,
Chandler Carruth01718152010-10-25 08:47:36 +00002068 RequiresZeroInit, ConstructKind,
2069 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002070 }
2071
2072 /// \brief Build a new object-construction expression.
2073 ///
2074 /// By default, performs semantic analysis to build the new expression.
2075 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002076 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2077 SourceLocation LParenLoc,
2078 MultiExprArg Args,
2079 SourceLocation RParenLoc) {
2080 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002081 LParenLoc,
2082 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002083 RParenLoc);
2084 }
2085
2086 /// \brief Build a new object-construction expression.
2087 ///
2088 /// By default, performs semantic analysis to build the new expression.
2089 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002090 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2091 SourceLocation LParenLoc,
2092 MultiExprArg Args,
2093 SourceLocation RParenLoc) {
2094 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002095 LParenLoc,
2096 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002097 RParenLoc);
2098 }
Mike Stump11289f42009-09-09 15:08:12 +00002099
Douglas Gregora16548e2009-08-11 05:31:07 +00002100 /// \brief Build a new member reference expression.
2101 ///
2102 /// By default, performs semantic analysis to build the new expression.
2103 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002104 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002105 QualType BaseType,
2106 bool IsArrow,
2107 SourceLocation OperatorLoc,
2108 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00002109 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002110 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002111 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002112 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002113 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002114
John McCallb268a282010-08-23 23:25:46 +00002115 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002116 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00002117 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002118 MemberNameInfo,
2119 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002120 }
2121
John McCall10eae182009-11-30 22:42:35 +00002122 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002123 ///
2124 /// By default, performs semantic analysis to build the new expression.
2125 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002126 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2127 SourceLocation OperatorLoc,
2128 bool IsArrow,
2129 NestedNameSpecifierLoc QualifierLoc,
2130 NamedDecl *FirstQualifierInScope,
2131 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002132 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002133 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002134 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002135
John McCallb268a282010-08-23 23:25:46 +00002136 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002137 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00002138 SS, FirstQualifierInScope,
2139 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002140 }
Mike Stump11289f42009-09-09 15:08:12 +00002141
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002142 /// \brief Build a new noexcept expression.
2143 ///
2144 /// By default, performs semantic analysis to build the new expression.
2145 /// Subclasses may override this routine to provide different behavior.
2146 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2147 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2148 }
2149
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002150 /// \brief Build a new expression to compute the length of a parameter pack.
2151 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2152 SourceLocation PackLoc,
2153 SourceLocation RParenLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002154 llvm::Optional<unsigned> Length) {
2155 if (Length)
2156 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2157 OperatorLoc, Pack, PackLoc,
2158 RParenLoc, *Length);
2159
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002160 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2161 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002162 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002163 }
2164
Douglas Gregora16548e2009-08-11 05:31:07 +00002165 /// \brief Build a new Objective-C @encode expression.
2166 ///
2167 /// By default, performs semantic analysis to build the new expression.
2168 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002169 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002170 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002171 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002172 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002173 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002174 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002175
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002176 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002177 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002178 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002179 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002180 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002181 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002182 MultiExprArg Args,
2183 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002184 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2185 ReceiverTypeInfo->getType(),
2186 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002187 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002188 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002189 }
2190
2191 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002192 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002193 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002194 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002195 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002196 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002197 MultiExprArg Args,
2198 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002199 return SemaRef.BuildInstanceMessage(Receiver,
2200 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002201 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002202 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002203 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002204 }
2205
Douglas Gregord51d90d2010-04-26 20:11:03 +00002206 /// \brief Build a new Objective-C ivar reference expression.
2207 ///
2208 /// By default, performs semantic analysis to build the new expression.
2209 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002210 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002211 SourceLocation IvarLoc,
2212 bool IsArrow, bool IsFreeIvar) {
2213 // FIXME: We lose track of the IsFreeIvar bit.
2214 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002215 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002216 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2217 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002218 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002219 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002220 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002221 false);
John Wiegley01296292011-04-08 18:41:53 +00002222 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002223 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002224
Douglas Gregord51d90d2010-04-26 20:11:03 +00002225 if (Result.get())
2226 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002227
John Wiegley01296292011-04-08 18:41:53 +00002228 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002229 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002230 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002231 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002232 /*TemplateArgs=*/0);
2233 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002234
2235 /// \brief Build a new Objective-C property reference expression.
2236 ///
2237 /// By default, performs semantic analysis to build the new expression.
2238 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002239 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002240 ObjCPropertyDecl *Property,
2241 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002242 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002243 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002244 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2245 Sema::LookupMemberName);
2246 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002247 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002248 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002249 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002250 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002251 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002252
Douglas Gregor9faee212010-04-26 20:47:02 +00002253 if (Result.get())
2254 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002255
John Wiegley01296292011-04-08 18:41:53 +00002256 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002257 /*FIXME:*/PropertyLoc, IsArrow,
2258 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002259 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002260 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002261 /*TemplateArgs=*/0);
2262 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002263
John McCallb7bd14f2010-12-02 01:19:52 +00002264 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002265 ///
2266 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002267 /// Subclasses may override this routine to provide different behavior.
2268 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2269 ObjCMethodDecl *Getter,
2270 ObjCMethodDecl *Setter,
2271 SourceLocation PropertyLoc) {
2272 // Since these expressions can only be value-dependent, we do not
2273 // need to perform semantic analysis again.
2274 return Owned(
2275 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2276 VK_LValue, OK_ObjCProperty,
2277 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002278 }
2279
Douglas Gregord51d90d2010-04-26 20:11:03 +00002280 /// \brief Build a new Objective-C "isa" expression.
2281 ///
2282 /// By default, performs semantic analysis to build the new expression.
2283 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002284 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002285 bool IsArrow) {
2286 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002287 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002288 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2289 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002290 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002291 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002292 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002293 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002294 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002295
Douglas Gregord51d90d2010-04-26 20:11:03 +00002296 if (Result.get())
2297 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002298
John Wiegley01296292011-04-08 18:41:53 +00002299 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002300 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002301 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002302 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002303 /*TemplateArgs=*/0);
2304 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002305
Douglas Gregora16548e2009-08-11 05:31:07 +00002306 /// \brief Build a new shuffle vector expression.
2307 ///
2308 /// By default, performs semantic analysis to build the new expression.
2309 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002310 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002311 MultiExprArg SubExprs,
2312 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002313 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002314 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002315 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2316 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2317 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2318 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002319
Douglas Gregora16548e2009-08-11 05:31:07 +00002320 // Build a reference to the __builtin_shufflevector builtin
2321 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley01296292011-04-08 18:41:53 +00002322 ExprResult Callee
2323 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2324 VK_LValue, BuiltinLoc));
2325 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2326 if (Callee.isInvalid())
2327 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002328
2329 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002330 unsigned NumSubExprs = SubExprs.size();
2331 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley01296292011-04-08 18:41:53 +00002332 ExprResult TheCall = SemaRef.Owned(
2333 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregora16548e2009-08-11 05:31:07 +00002334 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002335 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002336 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley01296292011-04-08 18:41:53 +00002337 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002338
Douglas Gregora16548e2009-08-11 05:31:07 +00002339 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002340 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002341 }
John McCall31f82722010-11-12 08:19:04 +00002342
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002343 /// \brief Build a new template argument pack expansion.
2344 ///
2345 /// By default, performs semantic analysis to build a new pack expansion
2346 /// for a template argument. Subclasses may override this routine to provide
2347 /// different behavior.
2348 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002349 SourceLocation EllipsisLoc,
2350 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002351 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002352 case TemplateArgument::Expression: {
2353 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002354 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2355 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002356 if (Result.isInvalid())
2357 return TemplateArgumentLoc();
2358
2359 return TemplateArgumentLoc(Result.get(), Result.get());
2360 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002361
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002362 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002363 return TemplateArgumentLoc(TemplateArgument(
2364 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002365 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002366 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002367 Pattern.getTemplateNameLoc(),
2368 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002369
2370 case TemplateArgument::Null:
2371 case TemplateArgument::Integral:
2372 case TemplateArgument::Declaration:
2373 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002374 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002375 llvm_unreachable("Pack expansion pattern has no parameter packs");
2376
2377 case TemplateArgument::Type:
2378 if (TypeSourceInfo *Expansion
2379 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002380 EllipsisLoc,
2381 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002382 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2383 Expansion);
2384 break;
2385 }
2386
2387 return TemplateArgumentLoc();
2388 }
2389
Douglas Gregor968f23a2011-01-03 19:31:53 +00002390 /// \brief Build a new expression pack expansion.
2391 ///
2392 /// By default, performs semantic analysis to build a new pack expansion
2393 /// for an expression. Subclasses may override this routine to provide
2394 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002395 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2396 llvm::Optional<unsigned> NumExpansions) {
2397 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002398 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002399
2400 /// \brief Build a new atomic operation expression.
2401 ///
2402 /// By default, performs semantic analysis to build the new expression.
2403 /// Subclasses may override this routine to provide different behavior.
2404 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2405 MultiExprArg SubExprs,
2406 QualType RetTy,
2407 AtomicExpr::AtomicOp Op,
2408 SourceLocation RParenLoc) {
2409 // Just create the expression; there is not any interesting semantic
2410 // analysis here because we can't actually build an AtomicExpr until
2411 // we are sure it is semantically sound.
2412 unsigned NumSubExprs = SubExprs.size();
2413 Expr **Subs = (Expr **)SubExprs.release();
2414 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2415 NumSubExprs, RetTy, Op,
2416 RParenLoc);
2417 }
2418
John McCall31f82722010-11-12 08:19:04 +00002419private:
Douglas Gregor14454802011-02-25 02:25:35 +00002420 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2421 QualType ObjectType,
2422 NamedDecl *FirstQualifierInScope,
2423 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002424
2425 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2426 QualType ObjectType,
2427 NamedDecl *FirstQualifierInScope,
2428 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002429};
Douglas Gregora16548e2009-08-11 05:31:07 +00002430
Douglas Gregorebe10102009-08-20 07:17:43 +00002431template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002432StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002433 if (!S)
2434 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002435
Douglas Gregorebe10102009-08-20 07:17:43 +00002436 switch (S->getStmtClass()) {
2437 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002438
Douglas Gregorebe10102009-08-20 07:17:43 +00002439 // Transform individual statement nodes
2440#define STMT(Node, Parent) \
2441 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002442#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002443#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002444#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002445
Douglas Gregorebe10102009-08-20 07:17:43 +00002446 // Transform expressions by calling TransformExpr.
2447#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002448#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002449#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002450#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002451 {
John McCalldadc5752010-08-24 06:29:42 +00002452 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002453 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002454 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002455
John McCallb268a282010-08-23 23:25:46 +00002456 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002457 }
Mike Stump11289f42009-09-09 15:08:12 +00002458 }
2459
John McCallc3007a22010-10-26 07:05:15 +00002460 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002461}
Mike Stump11289f42009-09-09 15:08:12 +00002462
2463
Douglas Gregore922c772009-08-04 22:27:00 +00002464template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002465ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002466 if (!E)
2467 return SemaRef.Owned(E);
2468
2469 switch (E->getStmtClass()) {
2470 case Stmt::NoStmtClass: break;
2471#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002472#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002473#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002474 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002475#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002476 }
2477
John McCallc3007a22010-10-26 07:05:15 +00002478 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002479}
2480
2481template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002482bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2483 unsigned NumInputs,
2484 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002485 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002486 bool *ArgChanged) {
2487 for (unsigned I = 0; I != NumInputs; ++I) {
2488 // If requested, drop call arguments that need to be dropped.
2489 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2490 if (ArgChanged)
2491 *ArgChanged = true;
2492
2493 break;
2494 }
2495
Douglas Gregor968f23a2011-01-03 19:31:53 +00002496 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2497 Expr *Pattern = Expansion->getPattern();
2498
Chris Lattner01cf8db2011-07-20 06:58:45 +00002499 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002500 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2501 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2502
2503 // Determine whether the set of unexpanded parameter packs can and should
2504 // be expanded.
2505 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002506 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002507 llvm::Optional<unsigned> OrigNumExpansions
2508 = Expansion->getNumExpansions();
2509 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002510 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2511 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002512 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002513 Expand, RetainExpansion,
2514 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002515 return true;
2516
2517 if (!Expand) {
2518 // The transform has determined that we should perform a simple
2519 // transformation on the pack expansion, producing another pack
2520 // expansion.
2521 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2522 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2523 if (OutPattern.isInvalid())
2524 return true;
2525
2526 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002527 Expansion->getEllipsisLoc(),
2528 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002529 if (Out.isInvalid())
2530 return true;
2531
2532 if (ArgChanged)
2533 *ArgChanged = true;
2534 Outputs.push_back(Out.get());
2535 continue;
2536 }
John McCall542e7c62011-07-06 07:30:07 +00002537
2538 // Record right away that the argument was changed. This needs
2539 // to happen even if the array expands to nothing.
2540 if (ArgChanged) *ArgChanged = true;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002541
2542 // The transform has determined that we should perform an elementwise
2543 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002544 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002545 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2546 ExprResult Out = getDerived().TransformExpr(Pattern);
2547 if (Out.isInvalid())
2548 return true;
2549
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002550 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002551 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2552 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002553 if (Out.isInvalid())
2554 return true;
2555 }
2556
Douglas Gregor968f23a2011-01-03 19:31:53 +00002557 Outputs.push_back(Out.get());
2558 }
2559
2560 continue;
2561 }
2562
Douglas Gregora3efea12011-01-03 19:04:46 +00002563 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2564 if (Result.isInvalid())
2565 return true;
2566
2567 if (Result.get() != Inputs[I] && ArgChanged)
2568 *ArgChanged = true;
2569
2570 Outputs.push_back(Result.get());
2571 }
2572
2573 return false;
2574}
2575
2576template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002577NestedNameSpecifierLoc
2578TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2579 NestedNameSpecifierLoc NNS,
2580 QualType ObjectType,
2581 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002582 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregor14454802011-02-25 02:25:35 +00002583 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2584 Qualifier = Qualifier.getPrefix())
2585 Qualifiers.push_back(Qualifier);
2586
2587 CXXScopeSpec SS;
2588 while (!Qualifiers.empty()) {
2589 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2590 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2591
2592 switch (QNNS->getKind()) {
2593 case NestedNameSpecifier::Identifier:
2594 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2595 *QNNS->getAsIdentifier(),
2596 Q.getLocalBeginLoc(),
2597 Q.getLocalEndLoc(),
2598 ObjectType, false, SS,
2599 FirstQualifierInScope, false))
2600 return NestedNameSpecifierLoc();
2601
2602 break;
2603
2604 case NestedNameSpecifier::Namespace: {
2605 NamespaceDecl *NS
2606 = cast_or_null<NamespaceDecl>(
2607 getDerived().TransformDecl(
2608 Q.getLocalBeginLoc(),
2609 QNNS->getAsNamespace()));
2610 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2611 break;
2612 }
2613
2614 case NestedNameSpecifier::NamespaceAlias: {
2615 NamespaceAliasDecl *Alias
2616 = cast_or_null<NamespaceAliasDecl>(
2617 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2618 QNNS->getAsNamespaceAlias()));
2619 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2620 Q.getLocalEndLoc());
2621 break;
2622 }
2623
2624 case NestedNameSpecifier::Global:
2625 // There is no meaningful transformation that one could perform on the
2626 // global scope.
2627 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2628 break;
2629
2630 case NestedNameSpecifier::TypeSpecWithTemplate:
2631 case NestedNameSpecifier::TypeSpec: {
2632 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2633 FirstQualifierInScope, SS);
2634
2635 if (!TL)
2636 return NestedNameSpecifierLoc();
2637
2638 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2639 (SemaRef.getLangOptions().CPlusPlus0x &&
2640 TL.getType()->isEnumeralType())) {
2641 assert(!TL.getType().hasLocalQualifiers() &&
2642 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00002643 if (TL.getType()->isEnumeralType())
2644 SemaRef.Diag(TL.getBeginLoc(),
2645 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00002646 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2647 Q.getLocalEndLoc());
2648 break;
2649 }
Richard Trieude756fb2011-05-07 01:36:37 +00002650 // If the nested-name-specifier is an invalid type def, don't emit an
2651 // error because a previous error should have already been emitted.
2652 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2653 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2654 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2655 << TL.getType() << SS.getRange();
2656 }
Douglas Gregor14454802011-02-25 02:25:35 +00002657 return NestedNameSpecifierLoc();
2658 }
Douglas Gregore16af532011-02-28 18:50:33 +00002659 }
Douglas Gregor14454802011-02-25 02:25:35 +00002660
Douglas Gregore16af532011-02-28 18:50:33 +00002661 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002662 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002663 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002664 }
2665
2666 // Don't rebuild the nested-name-specifier if we don't have to.
2667 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2668 !getDerived().AlwaysRebuild())
2669 return NNS;
2670
2671 // If we can re-use the source-location data from the original
2672 // nested-name-specifier, do so.
2673 if (SS.location_size() == NNS.getDataLength() &&
2674 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2675 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2676
2677 // Allocate new nested-name-specifier location information.
2678 return SS.getWithLocInContext(SemaRef.Context);
2679}
2680
2681template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002682DeclarationNameInfo
2683TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002684::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002685 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002686 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002687 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002688
2689 switch (Name.getNameKind()) {
2690 case DeclarationName::Identifier:
2691 case DeclarationName::ObjCZeroArgSelector:
2692 case DeclarationName::ObjCOneArgSelector:
2693 case DeclarationName::ObjCMultiArgSelector:
2694 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002695 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002696 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002697 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002698
Douglas Gregorf816bd72009-09-03 22:13:48 +00002699 case DeclarationName::CXXConstructorName:
2700 case DeclarationName::CXXDestructorName:
2701 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002702 TypeSourceInfo *NewTInfo;
2703 CanQualType NewCanTy;
2704 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002705 NewTInfo = getDerived().TransformType(OldTInfo);
2706 if (!NewTInfo)
2707 return DeclarationNameInfo();
2708 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002709 }
2710 else {
2711 NewTInfo = 0;
2712 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002713 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002714 if (NewT.isNull())
2715 return DeclarationNameInfo();
2716 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2717 }
Mike Stump11289f42009-09-09 15:08:12 +00002718
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002719 DeclarationName NewName
2720 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2721 NewCanTy);
2722 DeclarationNameInfo NewNameInfo(NameInfo);
2723 NewNameInfo.setName(NewName);
2724 NewNameInfo.setNamedTypeInfo(NewTInfo);
2725 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002726 }
Mike Stump11289f42009-09-09 15:08:12 +00002727 }
2728
David Blaikie83d382b2011-09-23 05:06:16 +00002729 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00002730}
2731
2732template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002733TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00002734TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2735 TemplateName Name,
2736 SourceLocation NameLoc,
2737 QualType ObjectType,
2738 NamedDecl *FirstQualifierInScope) {
2739 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2740 TemplateDecl *Template = QTN->getTemplateDecl();
2741 assert(Template && "qualified template name must refer to a template");
2742
2743 TemplateDecl *TransTemplate
2744 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2745 Template));
2746 if (!TransTemplate)
2747 return TemplateName();
2748
2749 if (!getDerived().AlwaysRebuild() &&
2750 SS.getScopeRep() == QTN->getQualifier() &&
2751 TransTemplate == Template)
2752 return Name;
2753
2754 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2755 TransTemplate);
2756 }
2757
2758 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2759 if (SS.getScopeRep()) {
2760 // These apply to the scope specifier, not the template.
2761 ObjectType = QualType();
2762 FirstQualifierInScope = 0;
2763 }
2764
2765 if (!getDerived().AlwaysRebuild() &&
2766 SS.getScopeRep() == DTN->getQualifier() &&
2767 ObjectType.isNull())
2768 return Name;
2769
2770 if (DTN->isIdentifier()) {
2771 return getDerived().RebuildTemplateName(SS,
2772 *DTN->getIdentifier(),
2773 NameLoc,
2774 ObjectType,
2775 FirstQualifierInScope);
2776 }
2777
2778 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2779 ObjectType);
2780 }
2781
2782 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2783 TemplateDecl *TransTemplate
2784 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2785 Template));
2786 if (!TransTemplate)
2787 return TemplateName();
2788
2789 if (!getDerived().AlwaysRebuild() &&
2790 TransTemplate == Template)
2791 return Name;
2792
2793 return TemplateName(TransTemplate);
2794 }
2795
2796 if (SubstTemplateTemplateParmPackStorage *SubstPack
2797 = Name.getAsSubstTemplateTemplateParmPack()) {
2798 TemplateTemplateParmDecl *TransParam
2799 = cast_or_null<TemplateTemplateParmDecl>(
2800 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2801 if (!TransParam)
2802 return TemplateName();
2803
2804 if (!getDerived().AlwaysRebuild() &&
2805 TransParam == SubstPack->getParameterPack())
2806 return Name;
2807
2808 return getDerived().RebuildTemplateName(TransParam,
2809 SubstPack->getArgumentPack());
2810 }
2811
2812 // These should be getting filtered out before they reach the AST.
2813 llvm_unreachable("overloaded function decl survived to here");
2814 return TemplateName();
2815}
2816
2817template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002818void TreeTransform<Derived>::InventTemplateArgumentLoc(
2819 const TemplateArgument &Arg,
2820 TemplateArgumentLoc &Output) {
2821 SourceLocation Loc = getDerived().getBaseLocation();
2822 switch (Arg.getKind()) {
2823 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002824 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002825 break;
2826
2827 case TemplateArgument::Type:
2828 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002829 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002830
John McCall0ad16662009-10-29 08:12:44 +00002831 break;
2832
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002833 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00002834 case TemplateArgument::TemplateExpansion: {
2835 NestedNameSpecifierLocBuilder Builder;
2836 TemplateName Template = Arg.getAsTemplate();
2837 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2838 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2839 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2840 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2841
2842 if (Arg.getKind() == TemplateArgument::Template)
2843 Output = TemplateArgumentLoc(Arg,
2844 Builder.getWithLocInContext(SemaRef.Context),
2845 Loc);
2846 else
2847 Output = TemplateArgumentLoc(Arg,
2848 Builder.getWithLocInContext(SemaRef.Context),
2849 Loc, Loc);
2850
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002851 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00002852 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002853
John McCall0ad16662009-10-29 08:12:44 +00002854 case TemplateArgument::Expression:
2855 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2856 break;
2857
2858 case TemplateArgument::Declaration:
2859 case TemplateArgument::Integral:
2860 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002861 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002862 break;
2863 }
2864}
2865
2866template<typename Derived>
2867bool TreeTransform<Derived>::TransformTemplateArgument(
2868 const TemplateArgumentLoc &Input,
2869 TemplateArgumentLoc &Output) {
2870 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002871 switch (Arg.getKind()) {
2872 case TemplateArgument::Null:
2873 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002874 Output = Input;
2875 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002876
Douglas Gregore922c772009-08-04 22:27:00 +00002877 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002878 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002879 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002880 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002881
2882 DI = getDerived().TransformType(DI);
2883 if (!DI) return true;
2884
2885 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2886 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002887 }
Mike Stump11289f42009-09-09 15:08:12 +00002888
Douglas Gregore922c772009-08-04 22:27:00 +00002889 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002890 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002891 DeclarationName Name;
2892 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2893 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002894 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002895 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002896 if (!D) return true;
2897
John McCall0d07eb32009-10-29 18:45:58 +00002898 Expr *SourceExpr = Input.getSourceDeclExpression();
2899 if (SourceExpr) {
2900 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002901 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002902 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002903 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002904 }
2905
2906 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002907 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002908 }
Mike Stump11289f42009-09-09 15:08:12 +00002909
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002910 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00002911 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2912 if (QualifierLoc) {
2913 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2914 if (!QualifierLoc)
2915 return true;
2916 }
2917
Douglas Gregordf846d12011-03-02 18:46:51 +00002918 CXXScopeSpec SS;
2919 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002920 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00002921 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2922 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002923 if (Template.isNull())
2924 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002925
Douglas Gregor9d802122011-03-02 17:09:35 +00002926 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002927 Input.getTemplateNameLoc());
2928 return false;
2929 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002930
2931 case TemplateArgument::TemplateExpansion:
2932 llvm_unreachable("Caller should expand pack expansions");
2933
Douglas Gregore922c772009-08-04 22:27:00 +00002934 case TemplateArgument::Expression: {
2935 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002936 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002937 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002938
John McCall0ad16662009-10-29 08:12:44 +00002939 Expr *InputExpr = Input.getSourceExpression();
2940 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2941
Chris Lattnercdb591a2011-04-25 20:37:58 +00002942 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall0ad16662009-10-29 08:12:44 +00002943 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002944 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002945 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002946 }
Mike Stump11289f42009-09-09 15:08:12 +00002947
Douglas Gregore922c772009-08-04 22:27:00 +00002948 case TemplateArgument::Pack: {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002949 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregore922c772009-08-04 22:27:00 +00002950 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002951 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002952 AEnd = Arg.pack_end();
2953 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002954
John McCall0ad16662009-10-29 08:12:44 +00002955 // FIXME: preserve source information here when we start
2956 // caring about parameter packs.
2957
John McCall0d07eb32009-10-29 18:45:58 +00002958 TemplateArgumentLoc InputArg;
2959 TemplateArgumentLoc OutputArg;
2960 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2961 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002962 return true;
2963
John McCall0d07eb32009-10-29 18:45:58 +00002964 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002965 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002966
2967 TemplateArgument *TransformedArgsPtr
2968 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2969 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2970 TransformedArgsPtr);
2971 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2972 TransformedArgs.size()),
2973 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002974 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002975 }
2976 }
Mike Stump11289f42009-09-09 15:08:12 +00002977
Douglas Gregore922c772009-08-04 22:27:00 +00002978 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002979 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002980}
2981
Douglas Gregorfe921a72010-12-20 23:36:19 +00002982/// \brief Iterator adaptor that invents template argument location information
2983/// for each of the template arguments in its underlying iterator.
2984template<typename Derived, typename InputIterator>
2985class TemplateArgumentLocInventIterator {
2986 TreeTransform<Derived> &Self;
2987 InputIterator Iter;
2988
2989public:
2990 typedef TemplateArgumentLoc value_type;
2991 typedef TemplateArgumentLoc reference;
2992 typedef typename std::iterator_traits<InputIterator>::difference_type
2993 difference_type;
2994 typedef std::input_iterator_tag iterator_category;
2995
2996 class pointer {
2997 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002998
Douglas Gregorfe921a72010-12-20 23:36:19 +00002999 public:
3000 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3001
3002 const TemplateArgumentLoc *operator->() const { return &Arg; }
3003 };
3004
3005 TemplateArgumentLocInventIterator() { }
3006
3007 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3008 InputIterator Iter)
3009 : Self(Self), Iter(Iter) { }
3010
3011 TemplateArgumentLocInventIterator &operator++() {
3012 ++Iter;
3013 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003014 }
3015
Douglas Gregorfe921a72010-12-20 23:36:19 +00003016 TemplateArgumentLocInventIterator operator++(int) {
3017 TemplateArgumentLocInventIterator Old(*this);
3018 ++(*this);
3019 return Old;
3020 }
3021
3022 reference operator*() const {
3023 TemplateArgumentLoc Result;
3024 Self.InventTemplateArgumentLoc(*Iter, Result);
3025 return Result;
3026 }
3027
3028 pointer operator->() const { return pointer(**this); }
3029
3030 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3031 const TemplateArgumentLocInventIterator &Y) {
3032 return X.Iter == Y.Iter;
3033 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003034
Douglas Gregorfe921a72010-12-20 23:36:19 +00003035 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3036 const TemplateArgumentLocInventIterator &Y) {
3037 return X.Iter != Y.Iter;
3038 }
3039};
3040
Douglas Gregor42cafa82010-12-20 17:42:22 +00003041template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003042template<typename InputIterator>
3043bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3044 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003045 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003046 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003047 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003048 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003049
3050 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3051 // Unpack argument packs, which we translate them into separate
3052 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003053 // FIXME: We could do much better if we could guarantee that the
3054 // TemplateArgumentLocInfo for the pack expansion would be usable for
3055 // all of the template arguments in the argument pack.
3056 typedef TemplateArgumentLocInventIterator<Derived,
3057 TemplateArgument::pack_iterator>
3058 PackLocIterator;
3059 if (TransformTemplateArguments(PackLocIterator(*this,
3060 In.getArgument().pack_begin()),
3061 PackLocIterator(*this,
3062 In.getArgument().pack_end()),
3063 Outputs))
3064 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003065
3066 continue;
3067 }
3068
3069 if (In.getArgument().isPackExpansion()) {
3070 // We have a pack expansion, for which we will be substituting into
3071 // the pattern.
3072 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003073 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003074 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003075 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3076 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003077
Chris Lattner01cf8db2011-07-20 06:58:45 +00003078 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003079 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3080 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3081
3082 // Determine whether the set of unexpanded parameter packs can and should
3083 // be expanded.
3084 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003085 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003086 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003087 if (getDerived().TryExpandParameterPacks(Ellipsis,
3088 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003089 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003090 Expand,
3091 RetainExpansion,
3092 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003093 return true;
3094
3095 if (!Expand) {
3096 // The transform has determined that we should perform a simple
3097 // transformation on the pack expansion, producing another pack
3098 // expansion.
3099 TemplateArgumentLoc OutPattern;
3100 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3101 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3102 return true;
3103
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003104 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3105 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003106 if (Out.getArgument().isNull())
3107 return true;
3108
3109 Outputs.addArgument(Out);
3110 continue;
3111 }
3112
3113 // The transform has determined that we should perform an elementwise
3114 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003115 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003116 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3117
3118 if (getDerived().TransformTemplateArgument(Pattern, Out))
3119 return true;
3120
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003121 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003122 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3123 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003124 if (Out.getArgument().isNull())
3125 return true;
3126 }
3127
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003128 Outputs.addArgument(Out);
3129 }
3130
Douglas Gregor48d24112011-01-10 20:53:55 +00003131 // If we're supposed to retain a pack expansion, do so by temporarily
3132 // forgetting the partially-substituted parameter pack.
3133 if (RetainExpansion) {
3134 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3135
3136 if (getDerived().TransformTemplateArgument(Pattern, Out))
3137 return true;
3138
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003139 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3140 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003141 if (Out.getArgument().isNull())
3142 return true;
3143
3144 Outputs.addArgument(Out);
3145 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003146
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003147 continue;
3148 }
3149
3150 // The simple case:
3151 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003152 return true;
3153
3154 Outputs.addArgument(Out);
3155 }
3156
3157 return false;
3158
3159}
3160
Douglas Gregord6ff3322009-08-04 16:50:30 +00003161//===----------------------------------------------------------------------===//
3162// Type transformation
3163//===----------------------------------------------------------------------===//
3164
3165template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003166QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003167 if (getDerived().AlreadyTransformed(T))
3168 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003169
John McCall550e0c22009-10-21 00:40:46 +00003170 // Temporary workaround. All of these transformations should
3171 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003172 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3173 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003174
John McCall31f82722010-11-12 08:19:04 +00003175 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003176
John McCall550e0c22009-10-21 00:40:46 +00003177 if (!NewDI)
3178 return QualType();
3179
3180 return NewDI->getType();
3181}
3182
3183template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003184TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003185 if (getDerived().AlreadyTransformed(DI->getType()))
3186 return DI;
3187
3188 TypeLocBuilder TLB;
3189
3190 TypeLoc TL = DI->getTypeLoc();
3191 TLB.reserve(TL.getFullDataSize());
3192
John McCall31f82722010-11-12 08:19:04 +00003193 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003194 if (Result.isNull())
3195 return 0;
3196
John McCallbcd03502009-12-07 02:54:59 +00003197 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003198}
3199
3200template<typename Derived>
3201QualType
John McCall31f82722010-11-12 08:19:04 +00003202TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003203 switch (T.getTypeLocClass()) {
3204#define ABSTRACT_TYPELOC(CLASS, PARENT)
3205#define TYPELOC(CLASS, PARENT) \
3206 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003207 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003208#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003209 }
Mike Stump11289f42009-09-09 15:08:12 +00003210
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003211 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003212 return QualType();
3213}
3214
3215/// FIXME: By default, this routine adds type qualifiers only to types
3216/// that can have qualifiers, and silently suppresses those qualifiers
3217/// that are not permitted (e.g., qualifiers on reference or function
3218/// types). This is the right thing for template instantiation, but
3219/// probably not for other clients.
3220template<typename Derived>
3221QualType
3222TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003223 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003224 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003225
John McCall31f82722010-11-12 08:19:04 +00003226 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003227 if (Result.isNull())
3228 return QualType();
3229
3230 // Silently suppress qualifiers if the result type can't be qualified.
3231 // FIXME: this is the right thing for template instantiation, but
3232 // probably not for other clients.
3233 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003234 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003235
John McCall31168b02011-06-15 23:02:42 +00003236 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003237 // resulting type.
3238 if (Quals.hasObjCLifetime()) {
3239 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3240 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003241 else if (Result.getObjCLifetime()) {
Douglas Gregore46db902011-06-17 22:11:49 +00003242 // Objective-C ARC:
3243 // A lifetime qualifier applied to a substituted template parameter
3244 // overrides the lifetime qualifier from the template argument.
3245 if (const SubstTemplateTypeParmType *SubstTypeParam
3246 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3247 QualType Replacement = SubstTypeParam->getReplacementType();
3248 Qualifiers Qs = Replacement.getQualifiers();
3249 Qs.removeObjCLifetime();
3250 Replacement
3251 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3252 Qs);
3253 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3254 SubstTypeParam->getReplacedParameter(),
3255 Replacement);
3256 TLB.TypeWasModifiedSafely(Result);
3257 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003258 // Otherwise, complain about the addition of a qualifier to an
3259 // already-qualified type.
3260 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003261 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003262 << Result << R;
3263
Douglas Gregore46db902011-06-17 22:11:49 +00003264 Quals.removeObjCLifetime();
3265 }
3266 }
3267 }
John McCallcb0f89a2010-06-05 06:41:15 +00003268 if (!Quals.empty()) {
3269 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3270 TLB.push<QualifiedTypeLoc>(Result);
3271 // No location information to preserve.
3272 }
John McCall550e0c22009-10-21 00:40:46 +00003273
3274 return Result;
3275}
3276
Douglas Gregor14454802011-02-25 02:25:35 +00003277template<typename Derived>
3278TypeLoc
3279TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3280 QualType ObjectType,
3281 NamedDecl *UnqualLookup,
3282 CXXScopeSpec &SS) {
Douglas Gregor14454802011-02-25 02:25:35 +00003283 QualType T = TL.getType();
3284 if (getDerived().AlreadyTransformed(T))
3285 return TL;
3286
3287 TypeLocBuilder TLB;
3288 QualType Result;
3289
3290 if (isa<TemplateSpecializationType>(T)) {
3291 TemplateSpecializationTypeLoc SpecTL
3292 = cast<TemplateSpecializationTypeLoc>(TL);
3293
3294 TemplateName Template =
Douglas Gregor9db53502011-03-02 18:07:45 +00003295 getDerived().TransformTemplateName(SS,
3296 SpecTL.getTypePtr()->getTemplateName(),
3297 SpecTL.getTemplateNameLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003298 ObjectType, UnqualLookup);
3299 if (Template.isNull())
3300 return TypeLoc();
3301
3302 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3303 Template);
3304 } else if (isa<DependentTemplateSpecializationType>(T)) {
3305 DependentTemplateSpecializationTypeLoc SpecTL
3306 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3307
Douglas Gregor5a064722011-02-28 17:23:35 +00003308 TemplateName Template
Douglas Gregor9db53502011-03-02 18:07:45 +00003309 = getDerived().RebuildTemplateName(SS,
Douglas Gregore16af532011-02-28 18:50:33 +00003310 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003311 SpecTL.getNameLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00003312 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003313 if (Template.isNull())
3314 return TypeLoc();
3315
Douglas Gregor14454802011-02-25 02:25:35 +00003316 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003317 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003318 Template,
3319 SS);
Douglas Gregor14454802011-02-25 02:25:35 +00003320 } else {
3321 // Nothing special needs to be done for these.
3322 Result = getDerived().TransformType(TLB, TL);
3323 }
3324
3325 if (Result.isNull())
3326 return TypeLoc();
3327
3328 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3329}
3330
Douglas Gregor579c15f2011-03-02 18:32:08 +00003331template<typename Derived>
3332TypeSourceInfo *
3333TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3334 QualType ObjectType,
3335 NamedDecl *UnqualLookup,
3336 CXXScopeSpec &SS) {
3337 // FIXME: Painfully copy-paste from the above!
3338
3339 QualType T = TSInfo->getType();
3340 if (getDerived().AlreadyTransformed(T))
3341 return TSInfo;
3342
3343 TypeLocBuilder TLB;
3344 QualType Result;
3345
3346 TypeLoc TL = TSInfo->getTypeLoc();
3347 if (isa<TemplateSpecializationType>(T)) {
3348 TemplateSpecializationTypeLoc SpecTL
3349 = cast<TemplateSpecializationTypeLoc>(TL);
3350
3351 TemplateName Template
3352 = getDerived().TransformTemplateName(SS,
3353 SpecTL.getTypePtr()->getTemplateName(),
3354 SpecTL.getTemplateNameLoc(),
3355 ObjectType, UnqualLookup);
3356 if (Template.isNull())
3357 return 0;
3358
3359 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3360 Template);
3361 } else if (isa<DependentTemplateSpecializationType>(T)) {
3362 DependentTemplateSpecializationTypeLoc SpecTL
3363 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3364
3365 TemplateName Template
3366 = getDerived().RebuildTemplateName(SS,
3367 *SpecTL.getTypePtr()->getIdentifier(),
3368 SpecTL.getNameLoc(),
3369 ObjectType, UnqualLookup);
3370 if (Template.isNull())
3371 return 0;
3372
3373 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3374 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003375 Template,
3376 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003377 } else {
3378 // Nothing special needs to be done for these.
3379 Result = getDerived().TransformType(TLB, TL);
3380 }
3381
3382 if (Result.isNull())
3383 return 0;
3384
3385 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3386}
3387
John McCall550e0c22009-10-21 00:40:46 +00003388template <class TyLoc> static inline
3389QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3390 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3391 NewT.setNameLoc(T.getNameLoc());
3392 return T.getType();
3393}
3394
John McCall550e0c22009-10-21 00:40:46 +00003395template<typename Derived>
3396QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003397 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003398 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3399 NewT.setBuiltinLoc(T.getBuiltinLoc());
3400 if (T.needsExtraLocalData())
3401 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3402 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003403}
Mike Stump11289f42009-09-09 15:08:12 +00003404
Douglas Gregord6ff3322009-08-04 16:50:30 +00003405template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003406QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003407 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003408 // FIXME: recurse?
3409 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003410}
Mike Stump11289f42009-09-09 15:08:12 +00003411
Douglas Gregord6ff3322009-08-04 16:50:30 +00003412template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003413QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003414 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003415 QualType PointeeType
3416 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003417 if (PointeeType.isNull())
3418 return QualType();
3419
3420 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003421 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003422 // A dependent pointer type 'T *' has is being transformed such
3423 // that an Objective-C class type is being replaced for 'T'. The
3424 // resulting pointer type is an ObjCObjectPointerType, not a
3425 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003426 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003427
John McCall8b07ec22010-05-15 11:32:37 +00003428 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3429 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003430 return Result;
3431 }
John McCall31f82722010-11-12 08:19:04 +00003432
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003433 if (getDerived().AlwaysRebuild() ||
3434 PointeeType != TL.getPointeeLoc().getType()) {
3435 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3436 if (Result.isNull())
3437 return QualType();
3438 }
John McCall31168b02011-06-15 23:02:42 +00003439
3440 // Objective-C ARC can add lifetime qualifiers to the type that we're
3441 // pointing to.
3442 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3443
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003444 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3445 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003446 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003447}
Mike Stump11289f42009-09-09 15:08:12 +00003448
3449template<typename Derived>
3450QualType
John McCall550e0c22009-10-21 00:40:46 +00003451TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003452 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003453 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003454 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3455 if (PointeeType.isNull())
3456 return QualType();
3457
3458 QualType Result = TL.getType();
3459 if (getDerived().AlwaysRebuild() ||
3460 PointeeType != TL.getPointeeLoc().getType()) {
3461 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003462 TL.getSigilLoc());
3463 if (Result.isNull())
3464 return QualType();
3465 }
3466
Douglas Gregor049211a2010-04-22 16:50:51 +00003467 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003468 NewT.setSigilLoc(TL.getSigilLoc());
3469 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003470}
3471
John McCall70dd5f62009-10-30 00:06:24 +00003472/// Transforms a reference type. Note that somewhat paradoxically we
3473/// don't care whether the type itself is an l-value type or an r-value
3474/// type; we only care if the type was *written* as an l-value type
3475/// or an r-value type.
3476template<typename Derived>
3477QualType
3478TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003479 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003480 const ReferenceType *T = TL.getTypePtr();
3481
3482 // Note that this works with the pointee-as-written.
3483 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3484 if (PointeeType.isNull())
3485 return QualType();
3486
3487 QualType Result = TL.getType();
3488 if (getDerived().AlwaysRebuild() ||
3489 PointeeType != T->getPointeeTypeAsWritten()) {
3490 Result = getDerived().RebuildReferenceType(PointeeType,
3491 T->isSpelledAsLValue(),
3492 TL.getSigilLoc());
3493 if (Result.isNull())
3494 return QualType();
3495 }
3496
John McCall31168b02011-06-15 23:02:42 +00003497 // Objective-C ARC can add lifetime qualifiers to the type that we're
3498 // referring to.
3499 TLB.TypeWasModifiedSafely(
3500 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3501
John McCall70dd5f62009-10-30 00:06:24 +00003502 // r-value references can be rebuilt as l-value references.
3503 ReferenceTypeLoc NewTL;
3504 if (isa<LValueReferenceType>(Result))
3505 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3506 else
3507 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3508 NewTL.setSigilLoc(TL.getSigilLoc());
3509
3510 return Result;
3511}
3512
Mike Stump11289f42009-09-09 15:08:12 +00003513template<typename Derived>
3514QualType
John McCall550e0c22009-10-21 00:40:46 +00003515TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003516 LValueReferenceTypeLoc TL) {
3517 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003518}
3519
Mike Stump11289f42009-09-09 15:08:12 +00003520template<typename Derived>
3521QualType
John McCall550e0c22009-10-21 00:40:46 +00003522TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003523 RValueReferenceTypeLoc TL) {
3524 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003525}
Mike Stump11289f42009-09-09 15:08:12 +00003526
Douglas Gregord6ff3322009-08-04 16:50:30 +00003527template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003528QualType
John McCall550e0c22009-10-21 00:40:46 +00003529TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003530 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003531 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003532 if (PointeeType.isNull())
3533 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003534
Abramo Bagnara509357842011-03-05 14:42:21 +00003535 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3536 TypeSourceInfo* NewClsTInfo = 0;
3537 if (OldClsTInfo) {
3538 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3539 if (!NewClsTInfo)
3540 return QualType();
3541 }
3542
3543 const MemberPointerType *T = TL.getTypePtr();
3544 QualType OldClsType = QualType(T->getClass(), 0);
3545 QualType NewClsType;
3546 if (NewClsTInfo)
3547 NewClsType = NewClsTInfo->getType();
3548 else {
3549 NewClsType = getDerived().TransformType(OldClsType);
3550 if (NewClsType.isNull())
3551 return QualType();
3552 }
Mike Stump11289f42009-09-09 15:08:12 +00003553
John McCall550e0c22009-10-21 00:40:46 +00003554 QualType Result = TL.getType();
3555 if (getDerived().AlwaysRebuild() ||
3556 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003557 NewClsType != OldClsType) {
3558 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003559 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003560 if (Result.isNull())
3561 return QualType();
3562 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003563
John McCall550e0c22009-10-21 00:40:46 +00003564 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3565 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003566 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003567
3568 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003569}
3570
Mike Stump11289f42009-09-09 15:08:12 +00003571template<typename Derived>
3572QualType
John McCall550e0c22009-10-21 00:40:46 +00003573TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003574 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003575 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003576 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003577 if (ElementType.isNull())
3578 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003579
John McCall550e0c22009-10-21 00:40:46 +00003580 QualType Result = TL.getType();
3581 if (getDerived().AlwaysRebuild() ||
3582 ElementType != T->getElementType()) {
3583 Result = getDerived().RebuildConstantArrayType(ElementType,
3584 T->getSizeModifier(),
3585 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003586 T->getIndexTypeCVRQualifiers(),
3587 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003588 if (Result.isNull())
3589 return QualType();
3590 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003591
John McCall550e0c22009-10-21 00:40:46 +00003592 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3593 NewTL.setLBracketLoc(TL.getLBracketLoc());
3594 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003595
John McCall550e0c22009-10-21 00:40:46 +00003596 Expr *Size = TL.getSizeExpr();
3597 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003598 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003599 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3600 }
3601 NewTL.setSizeExpr(Size);
3602
3603 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003604}
Mike Stump11289f42009-09-09 15:08:12 +00003605
Douglas Gregord6ff3322009-08-04 16:50:30 +00003606template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003607QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003608 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003609 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003610 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003611 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003612 if (ElementType.isNull())
3613 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003614
John McCall550e0c22009-10-21 00:40:46 +00003615 QualType Result = TL.getType();
3616 if (getDerived().AlwaysRebuild() ||
3617 ElementType != T->getElementType()) {
3618 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003619 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003620 T->getIndexTypeCVRQualifiers(),
3621 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003622 if (Result.isNull())
3623 return QualType();
3624 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003625
John McCall550e0c22009-10-21 00:40:46 +00003626 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3627 NewTL.setLBracketLoc(TL.getLBracketLoc());
3628 NewTL.setRBracketLoc(TL.getRBracketLoc());
3629 NewTL.setSizeExpr(0);
3630
3631 return Result;
3632}
3633
3634template<typename Derived>
3635QualType
3636TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003637 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003638 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003639 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3640 if (ElementType.isNull())
3641 return QualType();
3642
3643 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003644 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003645
John McCalldadc5752010-08-24 06:29:42 +00003646 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003647 = getDerived().TransformExpr(T->getSizeExpr());
3648 if (SizeResult.isInvalid())
3649 return QualType();
3650
John McCallb268a282010-08-23 23:25:46 +00003651 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003652
3653 QualType Result = TL.getType();
3654 if (getDerived().AlwaysRebuild() ||
3655 ElementType != T->getElementType() ||
3656 Size != T->getSizeExpr()) {
3657 Result = getDerived().RebuildVariableArrayType(ElementType,
3658 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003659 Size,
John McCall550e0c22009-10-21 00:40:46 +00003660 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003661 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003662 if (Result.isNull())
3663 return QualType();
3664 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003665
John McCall550e0c22009-10-21 00:40:46 +00003666 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3667 NewTL.setLBracketLoc(TL.getLBracketLoc());
3668 NewTL.setRBracketLoc(TL.getRBracketLoc());
3669 NewTL.setSizeExpr(Size);
3670
3671 return Result;
3672}
3673
3674template<typename Derived>
3675QualType
3676TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003677 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003678 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003679 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3680 if (ElementType.isNull())
3681 return QualType();
3682
3683 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003684 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003685
John McCall33ddac02011-01-19 10:06:00 +00003686 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3687 Expr *origSize = TL.getSizeExpr();
3688 if (!origSize) origSize = T->getSizeExpr();
3689
3690 ExprResult sizeResult
3691 = getDerived().TransformExpr(origSize);
3692 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003693 return QualType();
3694
John McCall33ddac02011-01-19 10:06:00 +00003695 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003696
3697 QualType Result = TL.getType();
3698 if (getDerived().AlwaysRebuild() ||
3699 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003700 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003701 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3702 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003703 size,
John McCall550e0c22009-10-21 00:40:46 +00003704 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003705 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003706 if (Result.isNull())
3707 return QualType();
3708 }
John McCall550e0c22009-10-21 00:40:46 +00003709
3710 // We might have any sort of array type now, but fortunately they
3711 // all have the same location layout.
3712 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3713 NewTL.setLBracketLoc(TL.getLBracketLoc());
3714 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003715 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003716
3717 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003718}
Mike Stump11289f42009-09-09 15:08:12 +00003719
3720template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003721QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003722 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003723 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003724 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003725
3726 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003727 QualType ElementType = getDerived().TransformType(T->getElementType());
3728 if (ElementType.isNull())
3729 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003730
Douglas Gregore922c772009-08-04 22:27:00 +00003731 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003732 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003733
John McCalldadc5752010-08-24 06:29:42 +00003734 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003735 if (Size.isInvalid())
3736 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003737
John McCall550e0c22009-10-21 00:40:46 +00003738 QualType Result = TL.getType();
3739 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003740 ElementType != T->getElementType() ||
3741 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003742 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003743 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003744 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003745 if (Result.isNull())
3746 return QualType();
3747 }
John McCall550e0c22009-10-21 00:40:46 +00003748
3749 // Result might be dependent or not.
3750 if (isa<DependentSizedExtVectorType>(Result)) {
3751 DependentSizedExtVectorTypeLoc NewTL
3752 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3753 NewTL.setNameLoc(TL.getNameLoc());
3754 } else {
3755 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3756 NewTL.setNameLoc(TL.getNameLoc());
3757 }
3758
3759 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003760}
Mike Stump11289f42009-09-09 15:08:12 +00003761
3762template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003763QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003764 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003765 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003766 QualType ElementType = getDerived().TransformType(T->getElementType());
3767 if (ElementType.isNull())
3768 return QualType();
3769
John McCall550e0c22009-10-21 00:40:46 +00003770 QualType Result = TL.getType();
3771 if (getDerived().AlwaysRebuild() ||
3772 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003773 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003774 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003775 if (Result.isNull())
3776 return QualType();
3777 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003778
John McCall550e0c22009-10-21 00:40:46 +00003779 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3780 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003781
John McCall550e0c22009-10-21 00:40:46 +00003782 return Result;
3783}
3784
3785template<typename Derived>
3786QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003787 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003788 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003789 QualType ElementType = getDerived().TransformType(T->getElementType());
3790 if (ElementType.isNull())
3791 return QualType();
3792
3793 QualType Result = TL.getType();
3794 if (getDerived().AlwaysRebuild() ||
3795 ElementType != T->getElementType()) {
3796 Result = getDerived().RebuildExtVectorType(ElementType,
3797 T->getNumElements(),
3798 /*FIXME*/ SourceLocation());
3799 if (Result.isNull())
3800 return QualType();
3801 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003802
John McCall550e0c22009-10-21 00:40:46 +00003803 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3804 NewTL.setNameLoc(TL.getNameLoc());
3805
3806 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003807}
Mike Stump11289f42009-09-09 15:08:12 +00003808
3809template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003810ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003811TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003812 int indexAdjustment,
Douglas Gregor715e4612011-01-14 22:40:04 +00003813 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003814 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003815 TypeSourceInfo *NewDI = 0;
3816
3817 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3818 // If we're substituting into a pack expansion type and we know the
3819 TypeLoc OldTL = OldDI->getTypeLoc();
3820 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3821
3822 TypeLocBuilder TLB;
3823 TypeLoc NewTL = OldDI->getTypeLoc();
3824 TLB.reserve(NewTL.getFullDataSize());
3825
3826 QualType Result = getDerived().TransformType(TLB,
3827 OldExpansionTL.getPatternLoc());
3828 if (Result.isNull())
3829 return 0;
3830
3831 Result = RebuildPackExpansionType(Result,
3832 OldExpansionTL.getPatternLoc().getSourceRange(),
3833 OldExpansionTL.getEllipsisLoc(),
3834 NumExpansions);
3835 if (Result.isNull())
3836 return 0;
3837
3838 PackExpansionTypeLoc NewExpansionTL
3839 = TLB.push<PackExpansionTypeLoc>(Result);
3840 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3841 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3842 } else
3843 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003844 if (!NewDI)
3845 return 0;
3846
John McCall8fb0d9d2011-05-01 22:35:37 +00003847 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00003848 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00003849
3850 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3851 OldParm->getDeclContext(),
3852 OldParm->getInnerLocStart(),
3853 OldParm->getLocation(),
3854 OldParm->getIdentifier(),
3855 NewDI->getType(),
3856 NewDI,
3857 OldParm->getStorageClass(),
3858 OldParm->getStorageClassAsWritten(),
3859 /* DefArg */ NULL);
3860 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3861 OldParm->getFunctionScopeIndex() + indexAdjustment);
3862 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00003863}
3864
3865template<typename Derived>
3866bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003867 TransformFunctionTypeParams(SourceLocation Loc,
3868 ParmVarDecl **Params, unsigned NumParams,
3869 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003870 SmallVectorImpl<QualType> &OutParamTypes,
3871 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003872 int indexAdjustment = 0;
3873
Douglas Gregordd472162011-01-07 00:20:55 +00003874 for (unsigned i = 0; i != NumParams; ++i) {
3875 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003876 assert(OldParm->getFunctionScopeIndex() == i);
3877
Douglas Gregor715e4612011-01-14 22:40:04 +00003878 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003879 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00003880 if (OldParm->isParameterPack()) {
3881 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00003882 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003883
Douglas Gregor5499af42011-01-05 23:12:31 +00003884 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003885 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3886 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3887 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3888 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00003889 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3890
Douglas Gregor5499af42011-01-05 23:12:31 +00003891 // Determine whether we should expand the parameter packs.
3892 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003893 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003894 llvm::Optional<unsigned> OrigNumExpansions
3895 = ExpansionTL.getTypePtr()->getNumExpansions();
3896 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003897 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3898 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003899 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003900 ShouldExpand,
3901 RetainExpansion,
3902 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003903 return true;
3904 }
3905
3906 if (ShouldExpand) {
3907 // Expand the function parameter pack into multiple, separate
3908 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003909 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003910 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003911 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3912 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003913 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003914 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003915 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003916 if (!NewParm)
3917 return true;
3918
Douglas Gregordd472162011-01-07 00:20:55 +00003919 OutParamTypes.push_back(NewParm->getType());
3920 if (PVars)
3921 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003922 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003923
3924 // If we're supposed to retain a pack expansion, do so by temporarily
3925 // forgetting the partially-substituted parameter pack.
3926 if (RetainExpansion) {
3927 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3928 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003929 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003930 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003931 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003932 if (!NewParm)
3933 return true;
3934
3935 OutParamTypes.push_back(NewParm->getType());
3936 if (PVars)
3937 PVars->push_back(NewParm);
3938 }
3939
John McCall8fb0d9d2011-05-01 22:35:37 +00003940 // The next parameter should have the same adjustment as the
3941 // last thing we pushed, but we post-incremented indexAdjustment
3942 // on every push. Also, if we push nothing, the adjustment should
3943 // go down by one.
3944 indexAdjustment--;
3945
Douglas Gregor5499af42011-01-05 23:12:31 +00003946 // We're done with the pack expansion.
3947 continue;
3948 }
3949
3950 // We'll substitute the parameter now without expanding the pack
3951 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00003952 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3953 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003954 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003955 NumExpansions);
3956 } else {
3957 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003958 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003959 llvm::Optional<unsigned>());
Douglas Gregor5499af42011-01-05 23:12:31 +00003960 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00003961
John McCall58f10c32010-03-11 09:03:00 +00003962 if (!NewParm)
3963 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003964
Douglas Gregordd472162011-01-07 00:20:55 +00003965 OutParamTypes.push_back(NewParm->getType());
3966 if (PVars)
3967 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003968 continue;
3969 }
John McCall58f10c32010-03-11 09:03:00 +00003970
3971 // Deal with the possibility that we don't have a parameter
3972 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003973 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003974 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003975 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003976 QualType NewType;
Douglas Gregor5499af42011-01-05 23:12:31 +00003977 if (const PackExpansionType *Expansion
3978 = dyn_cast<PackExpansionType>(OldType)) {
3979 // We have a function parameter pack that may need to be expanded.
3980 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00003981 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00003982 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3983
3984 // Determine whether we should expand the parameter packs.
3985 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003986 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003987 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003988 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003989 ShouldExpand,
3990 RetainExpansion,
3991 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003992 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003993 }
3994
3995 if (ShouldExpand) {
3996 // Expand the function parameter pack into multiple, separate
3997 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003998 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003999 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4000 QualType NewType = getDerived().TransformType(Pattern);
4001 if (NewType.isNull())
4002 return true;
John McCall58f10c32010-03-11 09:03:00 +00004003
Douglas Gregordd472162011-01-07 00:20:55 +00004004 OutParamTypes.push_back(NewType);
4005 if (PVars)
4006 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00004007 }
4008
4009 // We're done with the pack expansion.
4010 continue;
4011 }
4012
Douglas Gregor48d24112011-01-10 20:53:55 +00004013 // If we're supposed to retain a pack expansion, do so by temporarily
4014 // forgetting the partially-substituted parameter pack.
4015 if (RetainExpansion) {
4016 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4017 QualType NewType = getDerived().TransformType(Pattern);
4018 if (NewType.isNull())
4019 return true;
4020
4021 OutParamTypes.push_back(NewType);
4022 if (PVars)
4023 PVars->push_back(0);
4024 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004025
Douglas Gregor5499af42011-01-05 23:12:31 +00004026 // We'll substitute the parameter now without expanding the pack
4027 // expansion.
4028 OldType = Expansion->getPattern();
4029 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004030 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4031 NewType = getDerived().TransformType(OldType);
4032 } else {
4033 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004034 }
4035
Douglas Gregor5499af42011-01-05 23:12:31 +00004036 if (NewType.isNull())
4037 return true;
4038
4039 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004040 NewType = getSema().Context.getPackExpansionType(NewType,
4041 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00004042
Douglas Gregordd472162011-01-07 00:20:55 +00004043 OutParamTypes.push_back(NewType);
4044 if (PVars)
4045 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00004046 }
4047
John McCall8fb0d9d2011-05-01 22:35:37 +00004048#ifndef NDEBUG
4049 if (PVars) {
4050 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4051 if (ParmVarDecl *parm = (*PVars)[i])
4052 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004053 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004054#endif
4055
4056 return false;
4057}
John McCall58f10c32010-03-11 09:03:00 +00004058
4059template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004060QualType
John McCall550e0c22009-10-21 00:40:46 +00004061TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004062 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004063 // Transform the parameters and return type.
4064 //
4065 // We instantiate in source order, with the return type first followed by
4066 // the parameters, because users tend to expect this (even if they shouldn't
4067 // rely on it!).
4068 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00004069 // When the function has a trailing return type, we instantiate the
4070 // parameters before the return type, since the return type can then refer
4071 // to the parameters themselves (via decltype, sizeof, etc.).
4072 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004073 SmallVector<QualType, 4> ParamTypes;
4074 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004075 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004076
Douglas Gregor7fb25412010-10-01 18:44:50 +00004077 QualType ResultType;
4078
4079 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00004080 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4081 TL.getParmArray(),
4082 TL.getNumArgs(),
4083 TL.getTypePtr()->arg_type_begin(),
4084 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004085 return QualType();
4086
4087 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4088 if (ResultType.isNull())
4089 return QualType();
4090 }
4091 else {
4092 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4093 if (ResultType.isNull())
4094 return QualType();
4095
Douglas Gregordd472162011-01-07 00:20:55 +00004096 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4097 TL.getParmArray(),
4098 TL.getNumArgs(),
4099 TL.getTypePtr()->arg_type_begin(),
4100 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004101 return QualType();
4102 }
4103
John McCall550e0c22009-10-21 00:40:46 +00004104 QualType Result = TL.getType();
4105 if (getDerived().AlwaysRebuild() ||
4106 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00004107 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00004108 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4109 Result = getDerived().RebuildFunctionProtoType(ResultType,
4110 ParamTypes.data(),
4111 ParamTypes.size(),
4112 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004113 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00004114 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004115 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00004116 if (Result.isNull())
4117 return QualType();
4118 }
Mike Stump11289f42009-09-09 15:08:12 +00004119
John McCall550e0c22009-10-21 00:40:46 +00004120 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004121 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4122 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004123 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00004124 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4125 NewTL.setArg(i, ParamDecls[i]);
4126
4127 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004128}
Mike Stump11289f42009-09-09 15:08:12 +00004129
Douglas Gregord6ff3322009-08-04 16:50:30 +00004130template<typename Derived>
4131QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004132 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004133 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004134 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004135 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4136 if (ResultType.isNull())
4137 return QualType();
4138
4139 QualType Result = TL.getType();
4140 if (getDerived().AlwaysRebuild() ||
4141 ResultType != T->getResultType())
4142 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4143
4144 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004145 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4146 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004147 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00004148
4149 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004150}
Mike Stump11289f42009-09-09 15:08:12 +00004151
John McCallb96ec562009-12-04 22:46:56 +00004152template<typename Derived> QualType
4153TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004154 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004155 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004156 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004157 if (!D)
4158 return QualType();
4159
4160 QualType Result = TL.getType();
4161 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4162 Result = getDerived().RebuildUnresolvedUsingType(D);
4163 if (Result.isNull())
4164 return QualType();
4165 }
4166
4167 // We might get an arbitrary type spec type back. We should at
4168 // least always get a type spec type, though.
4169 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4170 NewTL.setNameLoc(TL.getNameLoc());
4171
4172 return Result;
4173}
4174
Douglas Gregord6ff3322009-08-04 16:50:30 +00004175template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004176QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004177 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004178 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004179 TypedefNameDecl *Typedef
4180 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4181 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004182 if (!Typedef)
4183 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004184
John McCall550e0c22009-10-21 00:40:46 +00004185 QualType Result = TL.getType();
4186 if (getDerived().AlwaysRebuild() ||
4187 Typedef != T->getDecl()) {
4188 Result = getDerived().RebuildTypedefType(Typedef);
4189 if (Result.isNull())
4190 return QualType();
4191 }
Mike Stump11289f42009-09-09 15:08:12 +00004192
John McCall550e0c22009-10-21 00:40:46 +00004193 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4194 NewTL.setNameLoc(TL.getNameLoc());
4195
4196 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004197}
Mike Stump11289f42009-09-09 15:08:12 +00004198
Douglas Gregord6ff3322009-08-04 16:50:30 +00004199template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004200QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004201 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004202 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004203 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004204
John McCalldadc5752010-08-24 06:29:42 +00004205 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004206 if (E.isInvalid())
4207 return QualType();
4208
John McCall550e0c22009-10-21 00:40:46 +00004209 QualType Result = TL.getType();
4210 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004211 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004212 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004213 if (Result.isNull())
4214 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004215 }
John McCall550e0c22009-10-21 00:40:46 +00004216 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004217
John McCall550e0c22009-10-21 00:40:46 +00004218 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004219 NewTL.setTypeofLoc(TL.getTypeofLoc());
4220 NewTL.setLParenLoc(TL.getLParenLoc());
4221 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004222
4223 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004224}
Mike Stump11289f42009-09-09 15:08:12 +00004225
4226template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004227QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004228 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004229 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4230 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4231 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004232 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004233
John McCall550e0c22009-10-21 00:40:46 +00004234 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004235 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4236 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004237 if (Result.isNull())
4238 return QualType();
4239 }
Mike Stump11289f42009-09-09 15:08:12 +00004240
John McCall550e0c22009-10-21 00:40:46 +00004241 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004242 NewTL.setTypeofLoc(TL.getTypeofLoc());
4243 NewTL.setLParenLoc(TL.getLParenLoc());
4244 NewTL.setRParenLoc(TL.getRParenLoc());
4245 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004246
4247 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004248}
Mike Stump11289f42009-09-09 15:08:12 +00004249
4250template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004251QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004252 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004253 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004254
Douglas Gregore922c772009-08-04 22:27:00 +00004255 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004256 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004257
John McCalldadc5752010-08-24 06:29:42 +00004258 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004259 if (E.isInvalid())
4260 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004261
John McCall550e0c22009-10-21 00:40:46 +00004262 QualType Result = TL.getType();
4263 if (getDerived().AlwaysRebuild() ||
4264 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004265 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004266 if (Result.isNull())
4267 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004268 }
John McCall550e0c22009-10-21 00:40:46 +00004269 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004270
John McCall550e0c22009-10-21 00:40:46 +00004271 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4272 NewTL.setNameLoc(TL.getNameLoc());
4273
4274 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004275}
4276
4277template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004278QualType TreeTransform<Derived>::TransformUnaryTransformType(
4279 TypeLocBuilder &TLB,
4280 UnaryTransformTypeLoc TL) {
4281 QualType Result = TL.getType();
4282 if (Result->isDependentType()) {
4283 const UnaryTransformType *T = TL.getTypePtr();
4284 QualType NewBase =
4285 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4286 Result = getDerived().RebuildUnaryTransformType(NewBase,
4287 T->getUTTKind(),
4288 TL.getKWLoc());
4289 if (Result.isNull())
4290 return QualType();
4291 }
4292
4293 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4294 NewTL.setKWLoc(TL.getKWLoc());
4295 NewTL.setParensRange(TL.getParensRange());
4296 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4297 return Result;
4298}
4299
4300template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004301QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4302 AutoTypeLoc TL) {
4303 const AutoType *T = TL.getTypePtr();
4304 QualType OldDeduced = T->getDeducedType();
4305 QualType NewDeduced;
4306 if (!OldDeduced.isNull()) {
4307 NewDeduced = getDerived().TransformType(OldDeduced);
4308 if (NewDeduced.isNull())
4309 return QualType();
4310 }
4311
4312 QualType Result = TL.getType();
4313 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4314 Result = getDerived().RebuildAutoType(NewDeduced);
4315 if (Result.isNull())
4316 return QualType();
4317 }
4318
4319 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4320 NewTL.setNameLoc(TL.getNameLoc());
4321
4322 return Result;
4323}
4324
4325template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004326QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004327 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004328 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004329 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004330 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4331 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004332 if (!Record)
4333 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004334
John McCall550e0c22009-10-21 00:40:46 +00004335 QualType Result = TL.getType();
4336 if (getDerived().AlwaysRebuild() ||
4337 Record != T->getDecl()) {
4338 Result = getDerived().RebuildRecordType(Record);
4339 if (Result.isNull())
4340 return QualType();
4341 }
Mike Stump11289f42009-09-09 15:08:12 +00004342
John McCall550e0c22009-10-21 00:40:46 +00004343 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4344 NewTL.setNameLoc(TL.getNameLoc());
4345
4346 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004347}
Mike Stump11289f42009-09-09 15:08:12 +00004348
4349template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004350QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004351 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004352 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004353 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004354 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4355 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004356 if (!Enum)
4357 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004358
John McCall550e0c22009-10-21 00:40:46 +00004359 QualType Result = TL.getType();
4360 if (getDerived().AlwaysRebuild() ||
4361 Enum != T->getDecl()) {
4362 Result = getDerived().RebuildEnumType(Enum);
4363 if (Result.isNull())
4364 return QualType();
4365 }
Mike Stump11289f42009-09-09 15:08:12 +00004366
John McCall550e0c22009-10-21 00:40:46 +00004367 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4368 NewTL.setNameLoc(TL.getNameLoc());
4369
4370 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004371}
John McCallfcc33b02009-09-05 00:15:47 +00004372
John McCalle78aac42010-03-10 03:28:59 +00004373template<typename Derived>
4374QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4375 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004376 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004377 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4378 TL.getTypePtr()->getDecl());
4379 if (!D) return QualType();
4380
4381 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4382 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4383 return T;
4384}
4385
Douglas Gregord6ff3322009-08-04 16:50:30 +00004386template<typename Derived>
4387QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004388 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004389 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004390 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004391}
4392
Mike Stump11289f42009-09-09 15:08:12 +00004393template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004394QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004395 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004396 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004397 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4398
4399 // Substitute into the replacement type, which itself might involve something
4400 // that needs to be transformed. This only tends to occur with default
4401 // template arguments of template template parameters.
4402 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4403 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4404 if (Replacement.isNull())
4405 return QualType();
4406
4407 // Always canonicalize the replacement type.
4408 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4409 QualType Result
4410 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4411 Replacement);
4412
4413 // Propagate type-source information.
4414 SubstTemplateTypeParmTypeLoc NewTL
4415 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4416 NewTL.setNameLoc(TL.getNameLoc());
4417 return Result;
4418
John McCallcebee162009-10-18 09:09:24 +00004419}
4420
4421template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004422QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4423 TypeLocBuilder &TLB,
4424 SubstTemplateTypeParmPackTypeLoc TL) {
4425 return TransformTypeSpecType(TLB, TL);
4426}
4427
4428template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004429QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004430 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004431 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004432 const TemplateSpecializationType *T = TL.getTypePtr();
4433
Douglas Gregordf846d12011-03-02 18:46:51 +00004434 // The nested-name-specifier never matters in a TemplateSpecializationType,
4435 // because we can't have a dependent nested-name-specifier anyway.
4436 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004437 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004438 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4439 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004440 if (Template.isNull())
4441 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004442
John McCall31f82722010-11-12 08:19:04 +00004443 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4444}
4445
Eli Friedman0dfb8892011-10-06 23:00:33 +00004446template<typename Derived>
4447QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4448 AtomicTypeLoc TL) {
4449 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4450 if (ValueType.isNull())
4451 return QualType();
4452
4453 QualType Result = TL.getType();
4454 if (getDerived().AlwaysRebuild() ||
4455 ValueType != TL.getValueLoc().getType()) {
4456 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4457 if (Result.isNull())
4458 return QualType();
4459 }
4460
4461 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4462 NewTL.setKWLoc(TL.getKWLoc());
4463 NewTL.setLParenLoc(TL.getLParenLoc());
4464 NewTL.setRParenLoc(TL.getRParenLoc());
4465
4466 return Result;
4467}
4468
Douglas Gregorfe921a72010-12-20 23:36:19 +00004469namespace {
4470 /// \brief Simple iterator that traverses the template arguments in a
4471 /// container that provides a \c getArgLoc() member function.
4472 ///
4473 /// This iterator is intended to be used with the iterator form of
4474 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4475 template<typename ArgLocContainer>
4476 class TemplateArgumentLocContainerIterator {
4477 ArgLocContainer *Container;
4478 unsigned Index;
4479
4480 public:
4481 typedef TemplateArgumentLoc value_type;
4482 typedef TemplateArgumentLoc reference;
4483 typedef int difference_type;
4484 typedef std::input_iterator_tag iterator_category;
4485
4486 class pointer {
4487 TemplateArgumentLoc Arg;
4488
4489 public:
4490 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4491
4492 const TemplateArgumentLoc *operator->() const {
4493 return &Arg;
4494 }
4495 };
4496
4497
4498 TemplateArgumentLocContainerIterator() {}
4499
4500 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4501 unsigned Index)
4502 : Container(&Container), Index(Index) { }
4503
4504 TemplateArgumentLocContainerIterator &operator++() {
4505 ++Index;
4506 return *this;
4507 }
4508
4509 TemplateArgumentLocContainerIterator operator++(int) {
4510 TemplateArgumentLocContainerIterator Old(*this);
4511 ++(*this);
4512 return Old;
4513 }
4514
4515 TemplateArgumentLoc operator*() const {
4516 return Container->getArgLoc(Index);
4517 }
4518
4519 pointer operator->() const {
4520 return pointer(Container->getArgLoc(Index));
4521 }
4522
4523 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004524 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004525 return X.Container == Y.Container && X.Index == Y.Index;
4526 }
4527
4528 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004529 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004530 return !(X == Y);
4531 }
4532 };
4533}
4534
4535
John McCall31f82722010-11-12 08:19:04 +00004536template <typename Derived>
4537QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4538 TypeLocBuilder &TLB,
4539 TemplateSpecializationTypeLoc TL,
4540 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004541 TemplateArgumentListInfo NewTemplateArgs;
4542 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4543 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004544 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4545 ArgIterator;
4546 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4547 ArgIterator(TL, TL.getNumArgs()),
4548 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004549 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004550
John McCall0ad16662009-10-29 08:12:44 +00004551 // FIXME: maybe don't rebuild if all the template arguments are the same.
4552
4553 QualType Result =
4554 getDerived().RebuildTemplateSpecializationType(Template,
4555 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004556 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004557
4558 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004559 // Specializations of template template parameters are represented as
4560 // TemplateSpecializationTypes, and substitution of type alias templates
4561 // within a dependent context can transform them into
4562 // DependentTemplateSpecializationTypes.
4563 if (isa<DependentTemplateSpecializationType>(Result)) {
4564 DependentTemplateSpecializationTypeLoc NewTL
4565 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4566 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4567 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4568 NewTL.setNameLoc(TL.getTemplateNameLoc());
4569 NewTL.setLAngleLoc(TL.getLAngleLoc());
4570 NewTL.setRAngleLoc(TL.getRAngleLoc());
4571 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4572 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4573 return Result;
4574 }
4575
John McCall0ad16662009-10-29 08:12:44 +00004576 TemplateSpecializationTypeLoc NewTL
4577 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4578 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4579 NewTL.setLAngleLoc(TL.getLAngleLoc());
4580 NewTL.setRAngleLoc(TL.getRAngleLoc());
4581 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4582 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004583 }
Mike Stump11289f42009-09-09 15:08:12 +00004584
John McCall0ad16662009-10-29 08:12:44 +00004585 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004586}
Mike Stump11289f42009-09-09 15:08:12 +00004587
Douglas Gregor5a064722011-02-28 17:23:35 +00004588template <typename Derived>
4589QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4590 TypeLocBuilder &TLB,
4591 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004592 TemplateName Template,
4593 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004594 TemplateArgumentListInfo NewTemplateArgs;
4595 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4596 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4597 typedef TemplateArgumentLocContainerIterator<
4598 DependentTemplateSpecializationTypeLoc> ArgIterator;
4599 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4600 ArgIterator(TL, TL.getNumArgs()),
4601 NewTemplateArgs))
4602 return QualType();
4603
4604 // FIXME: maybe don't rebuild if all the template arguments are the same.
4605
4606 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4607 QualType Result
4608 = getSema().Context.getDependentTemplateSpecializationType(
4609 TL.getTypePtr()->getKeyword(),
4610 DTN->getQualifier(),
4611 DTN->getIdentifier(),
4612 NewTemplateArgs);
4613
4614 DependentTemplateSpecializationTypeLoc NewTL
4615 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4616 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004617
Douglas Gregora7a795b2011-03-01 20:11:18 +00004618 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004619 NewTL.setNameLoc(TL.getNameLoc());
4620 NewTL.setLAngleLoc(TL.getLAngleLoc());
4621 NewTL.setRAngleLoc(TL.getRAngleLoc());
4622 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4623 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4624 return Result;
4625 }
4626
4627 QualType Result
4628 = getDerived().RebuildTemplateSpecializationType(Template,
4629 TL.getNameLoc(),
4630 NewTemplateArgs);
4631
4632 if (!Result.isNull()) {
4633 /// FIXME: Wrap this in an elaborated-type-specifier?
4634 TemplateSpecializationTypeLoc NewTL
4635 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4636 NewTL.setTemplateNameLoc(TL.getNameLoc());
4637 NewTL.setLAngleLoc(TL.getLAngleLoc());
4638 NewTL.setRAngleLoc(TL.getRAngleLoc());
4639 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4640 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4641 }
4642
4643 return Result;
4644}
4645
Mike Stump11289f42009-09-09 15:08:12 +00004646template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004647QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004648TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004649 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004650 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004651
Douglas Gregor844cb502011-03-01 18:12:44 +00004652 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004653 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004654 if (TL.getQualifierLoc()) {
4655 QualifierLoc
4656 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4657 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004658 return QualType();
4659 }
Mike Stump11289f42009-09-09 15:08:12 +00004660
John McCall31f82722010-11-12 08:19:04 +00004661 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4662 if (NamedT.isNull())
4663 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004664
Richard Smith3f1b5d02011-05-05 21:57:07 +00004665 // C++0x [dcl.type.elab]p2:
4666 // If the identifier resolves to a typedef-name or the simple-template-id
4667 // resolves to an alias template specialization, the
4668 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00004669 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4670 if (const TemplateSpecializationType *TST =
4671 NamedT->getAs<TemplateSpecializationType>()) {
4672 TemplateName Template = TST->getTemplateName();
4673 if (TypeAliasTemplateDecl *TAT =
4674 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4675 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4676 diag::err_tag_reference_non_tag) << 4;
4677 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4678 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00004679 }
4680 }
4681
John McCall550e0c22009-10-21 00:40:46 +00004682 QualType Result = TL.getType();
4683 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004684 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004685 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004686 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004687 T->getKeyword(),
4688 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004689 if (Result.isNull())
4690 return QualType();
4691 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004692
Abramo Bagnara6150c882010-05-11 21:36:43 +00004693 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004694 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004695 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004696 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004697}
Mike Stump11289f42009-09-09 15:08:12 +00004698
4699template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004700QualType TreeTransform<Derived>::TransformAttributedType(
4701 TypeLocBuilder &TLB,
4702 AttributedTypeLoc TL) {
4703 const AttributedType *oldType = TL.getTypePtr();
4704 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4705 if (modifiedType.isNull())
4706 return QualType();
4707
4708 QualType result = TL.getType();
4709
4710 // FIXME: dependent operand expressions?
4711 if (getDerived().AlwaysRebuild() ||
4712 modifiedType != oldType->getModifiedType()) {
4713 // TODO: this is really lame; we should really be rebuilding the
4714 // equivalent type from first principles.
4715 QualType equivalentType
4716 = getDerived().TransformType(oldType->getEquivalentType());
4717 if (equivalentType.isNull())
4718 return QualType();
4719 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4720 modifiedType,
4721 equivalentType);
4722 }
4723
4724 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4725 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4726 if (TL.hasAttrOperand())
4727 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4728 if (TL.hasAttrExprOperand())
4729 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4730 else if (TL.hasAttrEnumOperand())
4731 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4732
4733 return result;
4734}
4735
4736template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004737QualType
4738TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4739 ParenTypeLoc TL) {
4740 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4741 if (Inner.isNull())
4742 return QualType();
4743
4744 QualType Result = TL.getType();
4745 if (getDerived().AlwaysRebuild() ||
4746 Inner != TL.getInnerLoc().getType()) {
4747 Result = getDerived().RebuildParenType(Inner);
4748 if (Result.isNull())
4749 return QualType();
4750 }
4751
4752 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4753 NewTL.setLParenLoc(TL.getLParenLoc());
4754 NewTL.setRParenLoc(TL.getRParenLoc());
4755 return Result;
4756}
4757
4758template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004759QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004760 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004761 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004762
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004763 NestedNameSpecifierLoc QualifierLoc
4764 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4765 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004766 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004767
John McCallc392f372010-06-11 00:33:02 +00004768 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004769 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004770 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004771 QualifierLoc,
4772 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004773 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004774 if (Result.isNull())
4775 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004776
Abramo Bagnarad7548482010-05-19 21:37:53 +00004777 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4778 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004779 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4780
Abramo Bagnarad7548482010-05-19 21:37:53 +00004781 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4782 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004783 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004784 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004785 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4786 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004787 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004788 NewTL.setNameLoc(TL.getNameLoc());
4789 }
John McCall550e0c22009-10-21 00:40:46 +00004790 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004791}
Mike Stump11289f42009-09-09 15:08:12 +00004792
Douglas Gregord6ff3322009-08-04 16:50:30 +00004793template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004794QualType TreeTransform<Derived>::
4795 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004796 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004797 NestedNameSpecifierLoc QualifierLoc;
4798 if (TL.getQualifierLoc()) {
4799 QualifierLoc
4800 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4801 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004802 return QualType();
4803 }
4804
John McCall31f82722010-11-12 08:19:04 +00004805 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004806 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004807}
4808
4809template<typename Derived>
4810QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00004811TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4812 DependentTemplateSpecializationTypeLoc TL,
4813 NestedNameSpecifierLoc QualifierLoc) {
4814 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4815
4816 TemplateArgumentListInfo NewTemplateArgs;
4817 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4818 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4819
4820 typedef TemplateArgumentLocContainerIterator<
4821 DependentTemplateSpecializationTypeLoc> ArgIterator;
4822 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4823 ArgIterator(TL, TL.getNumArgs()),
4824 NewTemplateArgs))
4825 return QualType();
4826
4827 QualType Result
4828 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4829 QualifierLoc,
4830 T->getIdentifier(),
4831 TL.getNameLoc(),
4832 NewTemplateArgs);
4833 if (Result.isNull())
4834 return QualType();
4835
4836 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4837 QualType NamedT = ElabT->getNamedType();
4838
4839 // Copy information relevant to the template specialization.
4840 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00004841 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004842 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004843 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4844 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004845 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004846 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004847
4848 // Copy information relevant to the elaborated type.
4849 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4850 NewTL.setKeywordLoc(TL.getKeywordLoc());
4851 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00004852 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4853 DependentTemplateSpecializationTypeLoc SpecTL
4854 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor11ddf132011-03-07 15:13:34 +00004855 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004856 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004857 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004858 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4859 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004860 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004861 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004862 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00004863 TemplateSpecializationTypeLoc SpecTL
4864 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004865 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004866 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4867 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004868 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004869 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004870 }
4871 return Result;
4872}
4873
4874template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004875QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4876 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004877 QualType Pattern
4878 = getDerived().TransformType(TLB, TL.getPatternLoc());
4879 if (Pattern.isNull())
4880 return QualType();
4881
4882 QualType Result = TL.getType();
4883 if (getDerived().AlwaysRebuild() ||
4884 Pattern != TL.getPatternLoc().getType()) {
4885 Result = getDerived().RebuildPackExpansionType(Pattern,
4886 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004887 TL.getEllipsisLoc(),
4888 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004889 if (Result.isNull())
4890 return QualType();
4891 }
4892
4893 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4894 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4895 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004896}
4897
4898template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004899QualType
4900TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004901 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004902 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004903 TLB.pushFullCopy(TL);
4904 return TL.getType();
4905}
4906
4907template<typename Derived>
4908QualType
4909TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004910 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004911 // ObjCObjectType is never dependent.
4912 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004913 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004914}
Mike Stump11289f42009-09-09 15:08:12 +00004915
4916template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004917QualType
4918TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004919 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004920 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004921 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004922 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004923}
4924
Douglas Gregord6ff3322009-08-04 16:50:30 +00004925//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004926// Statement transformation
4927//===----------------------------------------------------------------------===//
4928template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004929StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004930TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004931 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004932}
4933
4934template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004935StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004936TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4937 return getDerived().TransformCompoundStmt(S, false);
4938}
4939
4940template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004941StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004942TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004943 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004944 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004945 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004946 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004947 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4948 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004949 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004950 if (Result.isInvalid()) {
4951 // Immediately fail if this was a DeclStmt, since it's very
4952 // likely that this will cause problems for future statements.
4953 if (isa<DeclStmt>(*B))
4954 return StmtError();
4955
4956 // Otherwise, just keep processing substatements and fail later.
4957 SubStmtInvalid = true;
4958 continue;
4959 }
Mike Stump11289f42009-09-09 15:08:12 +00004960
Douglas Gregorebe10102009-08-20 07:17:43 +00004961 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4962 Statements.push_back(Result.takeAs<Stmt>());
4963 }
Mike Stump11289f42009-09-09 15:08:12 +00004964
John McCall1ababa62010-08-27 19:56:05 +00004965 if (SubStmtInvalid)
4966 return StmtError();
4967
Douglas Gregorebe10102009-08-20 07:17:43 +00004968 if (!getDerived().AlwaysRebuild() &&
4969 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004970 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004971
4972 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4973 move_arg(Statements),
4974 S->getRBracLoc(),
4975 IsStmtExpr);
4976}
Mike Stump11289f42009-09-09 15:08:12 +00004977
Douglas Gregorebe10102009-08-20 07:17:43 +00004978template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004979StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004980TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004981 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004982 {
4983 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004984 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004985
Eli Friedman06577382009-11-19 03:14:00 +00004986 // Transform the left-hand case value.
4987 LHS = getDerived().TransformExpr(S->getLHS());
4988 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004989 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004990
Eli Friedman06577382009-11-19 03:14:00 +00004991 // Transform the right-hand case value (for the GNU case-range extension).
4992 RHS = getDerived().TransformExpr(S->getRHS());
4993 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004994 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004995 }
Mike Stump11289f42009-09-09 15:08:12 +00004996
Douglas Gregorebe10102009-08-20 07:17:43 +00004997 // Build the case statement.
4998 // Case statements are always rebuilt so that they will attached to their
4999 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005000 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005001 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005002 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005003 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005004 S->getColonLoc());
5005 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005006 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005007
Douglas Gregorebe10102009-08-20 07:17:43 +00005008 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005009 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005010 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005011 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005012
Douglas Gregorebe10102009-08-20 07:17:43 +00005013 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005014 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005015}
5016
5017template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005018StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005019TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005020 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005021 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005022 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005023 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005024
Douglas Gregorebe10102009-08-20 07:17:43 +00005025 // Default statements are always rebuilt
5026 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005027 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005028}
Mike Stump11289f42009-09-09 15:08:12 +00005029
Douglas Gregorebe10102009-08-20 07:17:43 +00005030template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005031StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005032TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005033 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005034 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005035 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005036
Chris Lattnercab02a62011-02-17 20:34:02 +00005037 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5038 S->getDecl());
5039 if (!LD)
5040 return StmtError();
5041
5042
Douglas Gregorebe10102009-08-20 07:17:43 +00005043 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005044 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005045 cast<LabelDecl>(LD), SourceLocation(),
5046 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005047}
Mike Stump11289f42009-09-09 15:08:12 +00005048
Douglas Gregorebe10102009-08-20 07:17:43 +00005049template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005050StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005051TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005052 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005053 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00005054 VarDecl *ConditionVar = 0;
5055 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005056 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005057 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005058 getDerived().TransformDefinition(
5059 S->getConditionVariable()->getLocation(),
5060 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005061 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005062 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005063 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005064 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005065
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005066 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005067 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005068
5069 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005070 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005071 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5072 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005073 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005074 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005075
John McCallb268a282010-08-23 23:25:46 +00005076 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005077 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005078 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005079
John McCallb268a282010-08-23 23:25:46 +00005080 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5081 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005082 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005083
Douglas Gregorebe10102009-08-20 07:17:43 +00005084 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005085 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005086 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005087 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005088
Douglas Gregorebe10102009-08-20 07:17:43 +00005089 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005090 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005091 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005092 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005093
Douglas Gregorebe10102009-08-20 07:17:43 +00005094 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005095 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005096 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005097 Then.get() == S->getThen() &&
5098 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00005099 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005100
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005101 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005102 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005103 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005104}
5105
5106template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005107StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005108TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005109 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005110 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00005111 VarDecl *ConditionVar = 0;
5112 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005113 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005114 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005115 getDerived().TransformDefinition(
5116 S->getConditionVariable()->getLocation(),
5117 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005118 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005119 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005120 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005121 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005122
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005123 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005124 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005125 }
Mike Stump11289f42009-09-09 15:08:12 +00005126
Douglas Gregorebe10102009-08-20 07:17:43 +00005127 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005128 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005129 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005130 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005131 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005132 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005133
Douglas Gregorebe10102009-08-20 07:17:43 +00005134 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005135 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005136 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005137 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005138
Douglas Gregorebe10102009-08-20 07:17:43 +00005139 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005140 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5141 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005142}
Mike Stump11289f42009-09-09 15:08:12 +00005143
Douglas Gregorebe10102009-08-20 07:17:43 +00005144template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005145StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005146TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005147 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005148 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005149 VarDecl *ConditionVar = 0;
5150 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005151 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005152 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005153 getDerived().TransformDefinition(
5154 S->getConditionVariable()->getLocation(),
5155 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005156 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005157 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005158 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005159 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005160
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005161 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005162 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005163
5164 if (S->getCond()) {
5165 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005166 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5167 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005168 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005169 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005170 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005171 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005172 }
Mike Stump11289f42009-09-09 15:08:12 +00005173
John McCallb268a282010-08-23 23:25:46 +00005174 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5175 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005176 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005177
Douglas Gregorebe10102009-08-20 07:17:43 +00005178 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005179 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005180 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005181 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005182
Douglas Gregorebe10102009-08-20 07:17:43 +00005183 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005184 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005185 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005186 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005187 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005188
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005189 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005190 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005191}
Mike Stump11289f42009-09-09 15:08:12 +00005192
Douglas Gregorebe10102009-08-20 07:17:43 +00005193template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005194StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005195TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005196 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005197 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005198 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005199 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005200
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005201 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005202 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005203 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005204 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005205
Douglas Gregorebe10102009-08-20 07:17:43 +00005206 if (!getDerived().AlwaysRebuild() &&
5207 Cond.get() == S->getCond() &&
5208 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005209 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005210
John McCallb268a282010-08-23 23:25:46 +00005211 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5212 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005213 S->getRParenLoc());
5214}
Mike Stump11289f42009-09-09 15:08:12 +00005215
Douglas Gregorebe10102009-08-20 07:17:43 +00005216template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005217StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005218TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005219 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005220 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005221 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005222 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005223
Douglas Gregorebe10102009-08-20 07:17:43 +00005224 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005225 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005226 VarDecl *ConditionVar = 0;
5227 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005228 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005229 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005230 getDerived().TransformDefinition(
5231 S->getConditionVariable()->getLocation(),
5232 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005233 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005234 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005235 } else {
5236 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005237
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005238 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005239 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005240
5241 if (S->getCond()) {
5242 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005243 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5244 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005245 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005246 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005247
John McCallb268a282010-08-23 23:25:46 +00005248 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005249 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005250 }
Mike Stump11289f42009-09-09 15:08:12 +00005251
John McCallb268a282010-08-23 23:25:46 +00005252 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5253 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005254 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005255
Douglas Gregorebe10102009-08-20 07:17:43 +00005256 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005257 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005258 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005259 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005260
John McCallb268a282010-08-23 23:25:46 +00005261 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5262 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005263 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005264
Douglas Gregorebe10102009-08-20 07:17:43 +00005265 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005266 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005267 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005268 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005269
Douglas Gregorebe10102009-08-20 07:17:43 +00005270 if (!getDerived().AlwaysRebuild() &&
5271 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005272 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005273 Inc.get() == S->getInc() &&
5274 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005275 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005276
Douglas Gregorebe10102009-08-20 07:17:43 +00005277 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005278 Init.get(), FullCond, ConditionVar,
5279 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005280}
5281
5282template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005283StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005284TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005285 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5286 S->getLabel());
5287 if (!LD)
5288 return StmtError();
5289
Douglas Gregorebe10102009-08-20 07:17:43 +00005290 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005291 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005292 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005293}
5294
5295template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005296StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005297TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005298 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005299 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005300 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005301
Douglas Gregorebe10102009-08-20 07:17:43 +00005302 if (!getDerived().AlwaysRebuild() &&
5303 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005304 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005305
5306 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005307 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005308}
5309
5310template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005311StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005312TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005313 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005314}
Mike Stump11289f42009-09-09 15:08:12 +00005315
Douglas Gregorebe10102009-08-20 07:17:43 +00005316template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005317StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005318TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005319 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005320}
Mike Stump11289f42009-09-09 15:08:12 +00005321
Douglas Gregorebe10102009-08-20 07:17:43 +00005322template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005323StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005324TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005325 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005326 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005327 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005328
Mike Stump11289f42009-09-09 15:08:12 +00005329 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005330 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005331 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005332}
Mike Stump11289f42009-09-09 15:08:12 +00005333
Douglas Gregorebe10102009-08-20 07:17:43 +00005334template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005335StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005336TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005337 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005338 SmallVector<Decl *, 4> Decls;
Douglas Gregorebe10102009-08-20 07:17:43 +00005339 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5340 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005341 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5342 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005343 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005344 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005345
Douglas Gregorebe10102009-08-20 07:17:43 +00005346 if (Transformed != *D)
5347 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005348
Douglas Gregorebe10102009-08-20 07:17:43 +00005349 Decls.push_back(Transformed);
5350 }
Mike Stump11289f42009-09-09 15:08:12 +00005351
Douglas Gregorebe10102009-08-20 07:17:43 +00005352 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005353 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005354
5355 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005356 S->getStartLoc(), S->getEndLoc());
5357}
Mike Stump11289f42009-09-09 15:08:12 +00005358
Douglas Gregorebe10102009-08-20 07:17:43 +00005359template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005360StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005361TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005362
John McCall37ad5512010-08-23 06:44:23 +00005363 ASTOwningVector<Expr*> Constraints(getSema());
5364 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner01cf8db2011-07-20 06:58:45 +00005365 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005366
John McCalldadc5752010-08-24 06:29:42 +00005367 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005368 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005369
5370 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005371
Anders Carlssonaaeef072010-01-24 05:50:09 +00005372 // Go through the outputs.
5373 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005374 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005375
Anders Carlssonaaeef072010-01-24 05:50:09 +00005376 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005377 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005378
Anders Carlssonaaeef072010-01-24 05:50:09 +00005379 // Transform the output expr.
5380 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005381 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005382 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005383 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005384
Anders Carlssonaaeef072010-01-24 05:50:09 +00005385 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005386
John McCallb268a282010-08-23 23:25:46 +00005387 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005388 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005389
Anders Carlssonaaeef072010-01-24 05:50:09 +00005390 // Go through the inputs.
5391 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005392 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005393
Anders Carlssonaaeef072010-01-24 05:50:09 +00005394 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005395 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005396
Anders Carlssonaaeef072010-01-24 05:50:09 +00005397 // Transform the input expr.
5398 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005399 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005400 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005401 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005402
Anders Carlssonaaeef072010-01-24 05:50:09 +00005403 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005404
John McCallb268a282010-08-23 23:25:46 +00005405 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005406 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005407
Anders Carlssonaaeef072010-01-24 05:50:09 +00005408 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005409 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005410
5411 // Go through the clobbers.
5412 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005413 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005414
5415 // No need to transform the asm string literal.
5416 AsmString = SemaRef.Owned(S->getAsmString());
5417
5418 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5419 S->isSimple(),
5420 S->isVolatile(),
5421 S->getNumOutputs(),
5422 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005423 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005424 move_arg(Constraints),
5425 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005426 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005427 move_arg(Clobbers),
5428 S->getRParenLoc(),
5429 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005430}
5431
5432
5433template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005434StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005435TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005436 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005437 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005438 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005439 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005440
Douglas Gregor96c79492010-04-23 22:50:49 +00005441 // Transform the @catch statements (if present).
5442 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005443 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005444 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005445 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005446 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005447 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005448 if (Catch.get() != S->getCatchStmt(I))
5449 AnyCatchChanged = true;
5450 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005451 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005452
Douglas Gregor306de2f2010-04-22 23:59:56 +00005453 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005454 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005455 if (S->getFinallyStmt()) {
5456 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5457 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005458 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005459 }
5460
5461 // If nothing changed, just retain this statement.
5462 if (!getDerived().AlwaysRebuild() &&
5463 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005464 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005465 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005466 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005467
Douglas Gregor306de2f2010-04-22 23:59:56 +00005468 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005469 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5470 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005471}
Mike Stump11289f42009-09-09 15:08:12 +00005472
Douglas Gregorebe10102009-08-20 07:17:43 +00005473template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005474StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005475TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005476 // Transform the @catch parameter, if there is one.
5477 VarDecl *Var = 0;
5478 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5479 TypeSourceInfo *TSInfo = 0;
5480 if (FromVar->getTypeSourceInfo()) {
5481 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5482 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005483 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005484 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005485
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005486 QualType T;
5487 if (TSInfo)
5488 T = TSInfo->getType();
5489 else {
5490 T = getDerived().TransformType(FromVar->getType());
5491 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005492 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005493 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005494
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005495 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5496 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005497 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005498 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005499
John McCalldadc5752010-08-24 06:29:42 +00005500 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005501 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005502 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005503
5504 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005505 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005506 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005507}
Mike Stump11289f42009-09-09 15:08:12 +00005508
Douglas Gregorebe10102009-08-20 07:17:43 +00005509template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005510StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005511TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005512 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005513 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005514 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005515 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005516
Douglas Gregor306de2f2010-04-22 23:59:56 +00005517 // If nothing changed, just retain this statement.
5518 if (!getDerived().AlwaysRebuild() &&
5519 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005520 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005521
5522 // Build a new statement.
5523 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005524 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005525}
Mike Stump11289f42009-09-09 15:08:12 +00005526
Douglas Gregorebe10102009-08-20 07:17:43 +00005527template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005528StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005529TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005530 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005531 if (S->getThrowExpr()) {
5532 Operand = getDerived().TransformExpr(S->getThrowExpr());
5533 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005534 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005535 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005536
Douglas Gregor2900c162010-04-22 21:44:01 +00005537 if (!getDerived().AlwaysRebuild() &&
5538 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005539 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005540
John McCallb268a282010-08-23 23:25:46 +00005541 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005542}
Mike Stump11289f42009-09-09 15:08:12 +00005543
Douglas Gregorebe10102009-08-20 07:17:43 +00005544template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005545StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005546TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005547 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005548 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005549 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005550 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005551 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00005552 Object =
5553 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5554 Object.get());
5555 if (Object.isInvalid())
5556 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005557
Douglas Gregor6148de72010-04-22 22:01:21 +00005558 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005559 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005560 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005561 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005562
Douglas Gregor6148de72010-04-22 22:01:21 +00005563 // If nothing change, just retain the current statement.
5564 if (!getDerived().AlwaysRebuild() &&
5565 Object.get() == S->getSynchExpr() &&
5566 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005567 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005568
5569 // Build a new statement.
5570 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005571 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005572}
5573
5574template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005575StmtResult
John McCall31168b02011-06-15 23:02:42 +00005576TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5577 ObjCAutoreleasePoolStmt *S) {
5578 // Transform the body.
5579 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5580 if (Body.isInvalid())
5581 return StmtError();
5582
5583 // If nothing changed, just retain this statement.
5584 if (!getDerived().AlwaysRebuild() &&
5585 Body.get() == S->getSubStmt())
5586 return SemaRef.Owned(S);
5587
5588 // Build a new statement.
5589 return getDerived().RebuildObjCAutoreleasePoolStmt(
5590 S->getAtLoc(), Body.get());
5591}
5592
5593template<typename Derived>
5594StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005595TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005596 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005597 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005598 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005599 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005600 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005601
Douglas Gregorf68a5082010-04-22 23:10:45 +00005602 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005603 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005604 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005605 return StmtError();
John McCall53848232011-07-27 01:07:15 +00005606 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5607 Collection.take());
5608 if (Collection.isInvalid())
5609 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005610
Douglas Gregorf68a5082010-04-22 23:10:45 +00005611 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005612 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005613 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005614 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005615
Douglas Gregorf68a5082010-04-22 23:10:45 +00005616 // If nothing changed, just retain this statement.
5617 if (!getDerived().AlwaysRebuild() &&
5618 Element.get() == S->getElement() &&
5619 Collection.get() == S->getCollection() &&
5620 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005621 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005622
Douglas Gregorf68a5082010-04-22 23:10:45 +00005623 // Build a new statement.
5624 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5625 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005626 Element.get(),
5627 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005628 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005629 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005630}
5631
5632
5633template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005634StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005635TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5636 // Transform the exception declaration, if any.
5637 VarDecl *Var = 0;
5638 if (S->getExceptionDecl()) {
5639 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005640 TypeSourceInfo *T = getDerived().TransformType(
5641 ExceptionDecl->getTypeSourceInfo());
5642 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005643 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005644
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005645 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaradff19302011-03-08 08:55:46 +00005646 ExceptionDecl->getInnerLocStart(),
5647 ExceptionDecl->getLocation(),
5648 ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00005649 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005650 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005651 }
Mike Stump11289f42009-09-09 15:08:12 +00005652
Douglas Gregorebe10102009-08-20 07:17:43 +00005653 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005654 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005655 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005656 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005657
Douglas Gregorebe10102009-08-20 07:17:43 +00005658 if (!getDerived().AlwaysRebuild() &&
5659 !Var &&
5660 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005661 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005662
5663 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5664 Var,
John McCallb268a282010-08-23 23:25:46 +00005665 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005666}
Mike Stump11289f42009-09-09 15:08:12 +00005667
Douglas Gregorebe10102009-08-20 07:17:43 +00005668template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005669StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005670TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5671 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005672 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005673 = getDerived().TransformCompoundStmt(S->getTryBlock());
5674 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005675 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005676
Douglas Gregorebe10102009-08-20 07:17:43 +00005677 // Transform the handlers.
5678 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005679 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005680 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005681 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005682 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5683 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005684 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005685
Douglas Gregorebe10102009-08-20 07:17:43 +00005686 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5687 Handlers.push_back(Handler.takeAs<Stmt>());
5688 }
Mike Stump11289f42009-09-09 15:08:12 +00005689
Douglas Gregorebe10102009-08-20 07:17:43 +00005690 if (!getDerived().AlwaysRebuild() &&
5691 TryBlock.get() == S->getTryBlock() &&
5692 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005693 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005694
John McCallb268a282010-08-23 23:25:46 +00005695 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005696 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005697}
Mike Stump11289f42009-09-09 15:08:12 +00005698
Richard Smith02e85f32011-04-14 22:09:26 +00005699template<typename Derived>
5700StmtResult
5701TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5702 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5703 if (Range.isInvalid())
5704 return StmtError();
5705
5706 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5707 if (BeginEnd.isInvalid())
5708 return StmtError();
5709
5710 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5711 if (Cond.isInvalid())
5712 return StmtError();
5713
5714 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5715 if (Inc.isInvalid())
5716 return StmtError();
5717
5718 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5719 if (LoopVar.isInvalid())
5720 return StmtError();
5721
5722 StmtResult NewStmt = S;
5723 if (getDerived().AlwaysRebuild() ||
5724 Range.get() != S->getRangeStmt() ||
5725 BeginEnd.get() != S->getBeginEndStmt() ||
5726 Cond.get() != S->getCond() ||
5727 Inc.get() != S->getInc() ||
5728 LoopVar.get() != S->getLoopVarStmt())
5729 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5730 S->getColonLoc(), Range.get(),
5731 BeginEnd.get(), Cond.get(),
5732 Inc.get(), LoopVar.get(),
5733 S->getRParenLoc());
5734
5735 StmtResult Body = getDerived().TransformStmt(S->getBody());
5736 if (Body.isInvalid())
5737 return StmtError();
5738
5739 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5740 // it now so we have a new statement to attach the body to.
5741 if (Body.get() != S->getBody() && NewStmt.get() == S)
5742 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5743 S->getColonLoc(), Range.get(),
5744 BeginEnd.get(), Cond.get(),
5745 Inc.get(), LoopVar.get(),
5746 S->getRParenLoc());
5747
5748 if (NewStmt.get() == S)
5749 return SemaRef.Owned(S);
5750
5751 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5752}
5753
John Wiegley1c0675e2011-04-28 01:08:34 +00005754template<typename Derived>
5755StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00005756TreeTransform<Derived>::TransformMSDependentExistsStmt(
5757 MSDependentExistsStmt *S) {
5758 // Transform the nested-name-specifier, if any.
5759 NestedNameSpecifierLoc QualifierLoc;
5760 if (S->getQualifierLoc()) {
5761 QualifierLoc
5762 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5763 if (!QualifierLoc)
5764 return StmtError();
5765 }
5766
5767 // Transform the declaration name.
5768 DeclarationNameInfo NameInfo = S->getNameInfo();
5769 if (NameInfo.getName()) {
5770 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5771 if (!NameInfo.getName())
5772 return StmtError();
5773 }
5774
5775 // Check whether anything changed.
5776 if (!getDerived().AlwaysRebuild() &&
5777 QualifierLoc == S->getQualifierLoc() &&
5778 NameInfo.getName() == S->getNameInfo().getName())
5779 return S;
5780
5781 // Determine whether this name exists, if we can.
5782 CXXScopeSpec SS;
5783 SS.Adopt(QualifierLoc);
5784 bool Dependent = false;
5785 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5786 case Sema::IER_Exists:
5787 if (S->isIfExists())
5788 break;
5789
5790 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5791
5792 case Sema::IER_DoesNotExist:
5793 if (S->isIfNotExists())
5794 break;
5795
5796 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5797
5798 case Sema::IER_Dependent:
5799 Dependent = true;
5800 break;
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00005801
5802 case Sema::IER_Error:
5803 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00005804 }
5805
5806 // We need to continue with the instantiation, so do so now.
5807 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5808 if (SubStmt.isInvalid())
5809 return StmtError();
5810
5811 // If we have resolved the name, just transform to the substatement.
5812 if (!Dependent)
5813 return SubStmt;
5814
5815 // The name is still dependent, so build a dependent expression again.
5816 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5817 S->isIfExists(),
5818 QualifierLoc,
5819 NameInfo,
5820 SubStmt.get());
5821}
5822
5823template<typename Derived>
5824StmtResult
John Wiegley1c0675e2011-04-28 01:08:34 +00005825TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5826 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5827 if(TryBlock.isInvalid()) return StmtError();
5828
5829 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5830 if(!getDerived().AlwaysRebuild() &&
5831 TryBlock.get() == S->getTryBlock() &&
5832 Handler.get() == S->getHandler())
5833 return SemaRef.Owned(S);
5834
5835 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5836 S->getTryLoc(),
5837 TryBlock.take(),
5838 Handler.take());
5839}
5840
5841template<typename Derived>
5842StmtResult
5843TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5844 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5845 if(Block.isInvalid()) return StmtError();
5846
5847 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5848 Block.take());
5849}
5850
5851template<typename Derived>
5852StmtResult
5853TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5854 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5855 if(FilterExpr.isInvalid()) return StmtError();
5856
5857 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5858 if(Block.isInvalid()) return StmtError();
5859
5860 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5861 FilterExpr.take(),
5862 Block.take());
5863}
5864
5865template<typename Derived>
5866StmtResult
5867TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5868 if(isa<SEHFinallyStmt>(Handler))
5869 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5870 else
5871 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5872}
5873
Douglas Gregorebe10102009-08-20 07:17:43 +00005874//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005875// Expression transformation
5876//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005877template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005878ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005879TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005880 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005881}
Mike Stump11289f42009-09-09 15:08:12 +00005882
5883template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005884ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005885TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005886 NestedNameSpecifierLoc QualifierLoc;
5887 if (E->getQualifierLoc()) {
5888 QualifierLoc
5889 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5890 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005891 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005892 }
John McCallce546572009-12-08 09:08:17 +00005893
5894 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005895 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5896 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005897 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005898 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005899
John McCall815039a2010-08-17 21:27:17 +00005900 DeclarationNameInfo NameInfo = E->getNameInfo();
5901 if (NameInfo.getName()) {
5902 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5903 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005904 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005905 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005906
5907 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005908 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005909 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005910 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005911 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005912
5913 // Mark it referenced in the new context regardless.
5914 // FIXME: this is a bit instantiation-specific.
5915 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5916
John McCallc3007a22010-10-26 07:05:15 +00005917 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005918 }
John McCallce546572009-12-08 09:08:17 +00005919
5920 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005921 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005922 TemplateArgs = &TransArgs;
5923 TransArgs.setLAngleLoc(E->getLAngleLoc());
5924 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005925 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5926 E->getNumTemplateArgs(),
5927 TransArgs))
5928 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005929 }
5930
Douglas Gregorea972d32011-02-28 21:54:11 +00005931 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5932 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005933}
Mike Stump11289f42009-09-09 15:08:12 +00005934
Douglas Gregora16548e2009-08-11 05:31:07 +00005935template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005936ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005937TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005938 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005939}
Mike Stump11289f42009-09-09 15:08:12 +00005940
Douglas Gregora16548e2009-08-11 05:31:07 +00005941template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005942ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005943TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005944 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005945}
Mike Stump11289f42009-09-09 15:08:12 +00005946
Douglas Gregora16548e2009-08-11 05:31:07 +00005947template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005948ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005949TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005950 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005951}
Mike Stump11289f42009-09-09 15:08:12 +00005952
Douglas Gregora16548e2009-08-11 05:31:07 +00005953template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005954ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005955TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005956 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005957}
Mike Stump11289f42009-09-09 15:08:12 +00005958
Douglas Gregora16548e2009-08-11 05:31:07 +00005959template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005960ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005961TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005962 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005963}
5964
5965template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005966ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00005967TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5968 ExprResult ControllingExpr =
5969 getDerived().TransformExpr(E->getControllingExpr());
5970 if (ControllingExpr.isInvalid())
5971 return ExprError();
5972
Chris Lattner01cf8db2011-07-20 06:58:45 +00005973 SmallVector<Expr *, 4> AssocExprs;
5974 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00005975 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5976 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5977 if (TS) {
5978 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5979 if (!AssocType)
5980 return ExprError();
5981 AssocTypes.push_back(AssocType);
5982 } else {
5983 AssocTypes.push_back(0);
5984 }
5985
5986 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5987 if (AssocExpr.isInvalid())
5988 return ExprError();
5989 AssocExprs.push_back(AssocExpr.release());
5990 }
5991
5992 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5993 E->getDefaultLoc(),
5994 E->getRParenLoc(),
5995 ControllingExpr.release(),
5996 AssocTypes.data(),
5997 AssocExprs.data(),
5998 E->getNumAssocs());
5999}
6000
6001template<typename Derived>
6002ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006003TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006004 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006005 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006006 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006007
Douglas Gregora16548e2009-08-11 05:31:07 +00006008 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006009 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006010
John McCallb268a282010-08-23 23:25:46 +00006011 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006012 E->getRParen());
6013}
6014
Mike Stump11289f42009-09-09 15:08:12 +00006015template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006016ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006017TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006018 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006019 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006020 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006021
Douglas Gregora16548e2009-08-11 05:31:07 +00006022 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006023 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006024
Douglas Gregora16548e2009-08-11 05:31:07 +00006025 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6026 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006027 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006028}
Mike Stump11289f42009-09-09 15:08:12 +00006029
Douglas Gregora16548e2009-08-11 05:31:07 +00006030template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006031ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006032TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6033 // Transform the type.
6034 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6035 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00006036 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006037
Douglas Gregor882211c2010-04-28 22:16:22 +00006038 // Transform all of the components into components similar to what the
6039 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006040 // FIXME: It would be slightly more efficient in the non-dependent case to
6041 // just map FieldDecls, rather than requiring the rebuilder to look for
6042 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006043 // template code that we don't care.
6044 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006045 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006046 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006047 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006048 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6049 const Node &ON = E->getComponent(I);
6050 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006051 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006052 Comp.LocStart = ON.getSourceRange().getBegin();
6053 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006054 switch (ON.getKind()) {
6055 case Node::Array: {
6056 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006057 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006058 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006059 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006060
Douglas Gregor882211c2010-04-28 22:16:22 +00006061 ExprChanged = ExprChanged || Index.get() != FromIndex;
6062 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006063 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006064 break;
6065 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006066
Douglas Gregor882211c2010-04-28 22:16:22 +00006067 case Node::Field:
6068 case Node::Identifier:
6069 Comp.isBrackets = false;
6070 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006071 if (!Comp.U.IdentInfo)
6072 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006073
Douglas Gregor882211c2010-04-28 22:16:22 +00006074 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006075
Douglas Gregord1702062010-04-29 00:18:15 +00006076 case Node::Base:
6077 // Will be recomputed during the rebuild.
6078 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006079 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006080
Douglas Gregor882211c2010-04-28 22:16:22 +00006081 Components.push_back(Comp);
6082 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006083
Douglas Gregor882211c2010-04-28 22:16:22 +00006084 // If nothing changed, retain the existing expression.
6085 if (!getDerived().AlwaysRebuild() &&
6086 Type == E->getTypeSourceInfo() &&
6087 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006088 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006089
Douglas Gregor882211c2010-04-28 22:16:22 +00006090 // Build a new offsetof expression.
6091 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6092 Components.data(), Components.size(),
6093 E->getRParenLoc());
6094}
6095
6096template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006097ExprResult
John McCall8d69a212010-11-15 23:31:06 +00006098TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6099 assert(getDerived().AlreadyTransformed(E->getType()) &&
6100 "opaque value expression requires transformation");
6101 return SemaRef.Owned(E);
6102}
6103
6104template<typename Derived>
6105ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00006106TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00006107 // Rebuild the syntactic form. The original syntactic form has
6108 // opaque-value expressions in it, so strip those away and rebuild
6109 // the result. This is a really awful way of doing this, but the
6110 // better solution (rebuilding the semantic expressions and
6111 // rebinding OVEs as necessary) doesn't work; we'd need
6112 // TreeTransform to not strip away implicit conversions.
6113 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6114 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00006115 if (result.isInvalid()) return ExprError();
6116
6117 // If that gives us a pseudo-object result back, the pseudo-object
6118 // expression must have been an lvalue-to-rvalue conversion which we
6119 // should reapply.
6120 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6121 result = SemaRef.checkPseudoObjectRValue(result.take());
6122
6123 return result;
6124}
6125
6126template<typename Derived>
6127ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00006128TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6129 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006130 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006131 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006132
John McCallbcd03502009-12-07 02:54:59 +00006133 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006134 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006135 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006136
John McCall4c98fd82009-11-04 07:28:41 +00006137 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00006138 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006139
Peter Collingbournee190dee2011-03-11 19:24:49 +00006140 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6141 E->getKind(),
6142 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006143 }
Mike Stump11289f42009-09-09 15:08:12 +00006144
John McCalldadc5752010-08-24 06:29:42 +00006145 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00006146 {
Douglas Gregora16548e2009-08-11 05:31:07 +00006147 // C++0x [expr.sizeof]p1:
6148 // The operand is either an expression, which is an unevaluated operand
6149 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00006150 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006151
Douglas Gregora16548e2009-08-11 05:31:07 +00006152 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6153 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006154 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006155
Douglas Gregora16548e2009-08-11 05:31:07 +00006156 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00006157 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006158 }
Mike Stump11289f42009-09-09 15:08:12 +00006159
Peter Collingbournee190dee2011-03-11 19:24:49 +00006160 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6161 E->getOperatorLoc(),
6162 E->getKind(),
6163 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006164}
Mike Stump11289f42009-09-09 15:08:12 +00006165
Douglas Gregora16548e2009-08-11 05:31:07 +00006166template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006167ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006168TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006169 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006170 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006171 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006172
John McCalldadc5752010-08-24 06:29:42 +00006173 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006174 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006175 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006176
6177
Douglas Gregora16548e2009-08-11 05:31:07 +00006178 if (!getDerived().AlwaysRebuild() &&
6179 LHS.get() == E->getLHS() &&
6180 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006181 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006182
John McCallb268a282010-08-23 23:25:46 +00006183 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006184 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006185 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006186 E->getRBracketLoc());
6187}
Mike Stump11289f42009-09-09 15:08:12 +00006188
6189template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006190ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006191TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006192 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006193 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006194 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006195 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006196
6197 // Transform arguments.
6198 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006199 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006200 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6201 &ArgChanged))
6202 return ExprError();
6203
Douglas Gregora16548e2009-08-11 05:31:07 +00006204 if (!getDerived().AlwaysRebuild() &&
6205 Callee.get() == E->getCallee() &&
6206 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00006207 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump11289f42009-09-09 15:08:12 +00006208
Douglas Gregora16548e2009-08-11 05:31:07 +00006209 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006210 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006211 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006212 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006213 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006214 E->getRParenLoc());
6215}
Mike Stump11289f42009-09-09 15:08:12 +00006216
6217template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006218ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006219TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006220 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006221 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006222 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006223
Douglas Gregorea972d32011-02-28 21:54:11 +00006224 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006225 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006226 QualifierLoc
6227 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6228
6229 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006230 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006231 }
Mike Stump11289f42009-09-09 15:08:12 +00006232
Eli Friedman2cfcef62009-12-04 06:40:45 +00006233 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006234 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6235 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006236 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006237 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006238
John McCall16df1e52010-03-30 21:47:33 +00006239 NamedDecl *FoundDecl = E->getFoundDecl();
6240 if (FoundDecl == E->getMemberDecl()) {
6241 FoundDecl = Member;
6242 } else {
6243 FoundDecl = cast_or_null<NamedDecl>(
6244 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6245 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006246 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006247 }
6248
Douglas Gregora16548e2009-08-11 05:31:07 +00006249 if (!getDerived().AlwaysRebuild() &&
6250 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006251 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006252 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006253 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006254 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006255
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006256 // Mark it referenced in the new context regardless.
6257 // FIXME: this is a bit instantiation-specific.
6258 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00006259 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006260 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006261
John McCall6b51f282009-11-23 01:53:49 +00006262 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006263 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006264 TransArgs.setLAngleLoc(E->getLAngleLoc());
6265 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006266 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6267 E->getNumTemplateArgs(),
6268 TransArgs))
6269 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006270 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006271
Douglas Gregora16548e2009-08-11 05:31:07 +00006272 // FIXME: Bogus source location for the operator
6273 SourceLocation FakeOperatorLoc
6274 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6275
John McCall38836f02010-01-15 08:34:02 +00006276 // FIXME: to do this check properly, we will need to preserve the
6277 // first-qualifier-in-scope here, just in case we had a dependent
6278 // base (and therefore couldn't do the check) and a
6279 // nested-name-qualifier (and therefore could do the lookup).
6280 NamedDecl *FirstQualifierInScope = 0;
6281
John McCallb268a282010-08-23 23:25:46 +00006282 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006283 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006284 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006285 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006286 Member,
John McCall16df1e52010-03-30 21:47:33 +00006287 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006288 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006289 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006290 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006291}
Mike Stump11289f42009-09-09 15:08:12 +00006292
Douglas Gregora16548e2009-08-11 05:31:07 +00006293template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006294ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006295TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006296 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006297 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006298 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006299
John McCalldadc5752010-08-24 06:29:42 +00006300 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006301 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006302 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006303
Douglas Gregora16548e2009-08-11 05:31:07 +00006304 if (!getDerived().AlwaysRebuild() &&
6305 LHS.get() == E->getLHS() &&
6306 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006307 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006308
Douglas Gregora16548e2009-08-11 05:31:07 +00006309 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006310 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006311}
6312
Mike Stump11289f42009-09-09 15:08:12 +00006313template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006314ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006315TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006316 CompoundAssignOperator *E) {
6317 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006318}
Mike Stump11289f42009-09-09 15:08:12 +00006319
Douglas Gregora16548e2009-08-11 05:31:07 +00006320template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006321ExprResult TreeTransform<Derived>::
6322TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6323 // Just rebuild the common and RHS expressions and see whether we
6324 // get any changes.
6325
6326 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6327 if (commonExpr.isInvalid())
6328 return ExprError();
6329
6330 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6331 if (rhs.isInvalid())
6332 return ExprError();
6333
6334 if (!getDerived().AlwaysRebuild() &&
6335 commonExpr.get() == e->getCommon() &&
6336 rhs.get() == e->getFalseExpr())
6337 return SemaRef.Owned(e);
6338
6339 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6340 e->getQuestionLoc(),
6341 0,
6342 e->getColonLoc(),
6343 rhs.get());
6344}
6345
6346template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006347ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006348TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006349 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006350 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006351 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006352
John McCalldadc5752010-08-24 06:29:42 +00006353 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006354 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006355 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006356
John McCalldadc5752010-08-24 06:29:42 +00006357 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006358 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006359 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006360
Douglas Gregora16548e2009-08-11 05:31:07 +00006361 if (!getDerived().AlwaysRebuild() &&
6362 Cond.get() == E->getCond() &&
6363 LHS.get() == E->getLHS() &&
6364 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006365 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006366
John McCallb268a282010-08-23 23:25:46 +00006367 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006368 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006369 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006370 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006371 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006372}
Mike Stump11289f42009-09-09 15:08:12 +00006373
6374template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006375ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006376TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006377 // Implicit casts are eliminated during transformation, since they
6378 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006379 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006380}
Mike Stump11289f42009-09-09 15:08:12 +00006381
Douglas Gregora16548e2009-08-11 05:31:07 +00006382template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006383ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006384TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006385 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6386 if (!Type)
6387 return ExprError();
6388
John McCalldadc5752010-08-24 06:29:42 +00006389 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006390 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006391 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006392 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006393
Douglas Gregora16548e2009-08-11 05:31:07 +00006394 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006395 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006396 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006397 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006398
John McCall97513962010-01-15 18:39:57 +00006399 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006400 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006401 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006402 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006403}
Mike Stump11289f42009-09-09 15:08:12 +00006404
Douglas Gregora16548e2009-08-11 05:31:07 +00006405template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006406ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006407TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006408 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6409 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6410 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006411 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006412
John McCalldadc5752010-08-24 06:29:42 +00006413 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006414 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006415 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006416
Douglas Gregora16548e2009-08-11 05:31:07 +00006417 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006418 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006419 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00006420 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006421
John McCall5d7aa7f2010-01-19 22:33:45 +00006422 // Note: the expression type doesn't necessarily match the
6423 // type-as-written, but that's okay, because it should always be
6424 // derivable from the initializer.
6425
John McCalle15bbff2010-01-18 19:35:47 +00006426 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006427 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006428 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006429}
Mike Stump11289f42009-09-09 15:08:12 +00006430
Douglas Gregora16548e2009-08-11 05:31:07 +00006431template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006432ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006433TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006434 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006435 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006436 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006437
Douglas Gregora16548e2009-08-11 05:31:07 +00006438 if (!getDerived().AlwaysRebuild() &&
6439 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006440 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006441
Douglas Gregora16548e2009-08-11 05:31:07 +00006442 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00006443 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006444 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00006445 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006446 E->getAccessorLoc(),
6447 E->getAccessor());
6448}
Mike Stump11289f42009-09-09 15:08:12 +00006449
Douglas Gregora16548e2009-08-11 05:31:07 +00006450template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006451ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006452TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006453 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00006454
John McCall37ad5512010-08-23 06:44:23 +00006455 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006456 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6457 Inits, &InitChanged))
6458 return ExprError();
6459
Douglas Gregora16548e2009-08-11 05:31:07 +00006460 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00006461 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006462
Douglas Gregora16548e2009-08-11 05:31:07 +00006463 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00006464 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00006465}
Mike Stump11289f42009-09-09 15:08:12 +00006466
Douglas Gregora16548e2009-08-11 05:31:07 +00006467template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006468ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006469TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006470 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00006471
Douglas Gregorebe10102009-08-20 07:17:43 +00006472 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00006473 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006474 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006475 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006476
Douglas Gregorebe10102009-08-20 07:17:43 +00006477 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00006478 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006479 bool ExprChanged = false;
6480 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6481 DEnd = E->designators_end();
6482 D != DEnd; ++D) {
6483 if (D->isFieldDesignator()) {
6484 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6485 D->getDotLoc(),
6486 D->getFieldLoc()));
6487 continue;
6488 }
Mike Stump11289f42009-09-09 15:08:12 +00006489
Douglas Gregora16548e2009-08-11 05:31:07 +00006490 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00006491 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006492 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006493 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006494
6495 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006496 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006497
Douglas Gregora16548e2009-08-11 05:31:07 +00006498 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6499 ArrayExprs.push_back(Index.release());
6500 continue;
6501 }
Mike Stump11289f42009-09-09 15:08:12 +00006502
Douglas Gregora16548e2009-08-11 05:31:07 +00006503 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00006504 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00006505 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6506 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006507 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006508
John McCalldadc5752010-08-24 06:29:42 +00006509 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006510 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006511 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006512
6513 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006514 End.get(),
6515 D->getLBracketLoc(),
6516 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006517
Douglas Gregora16548e2009-08-11 05:31:07 +00006518 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6519 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00006520
Douglas Gregora16548e2009-08-11 05:31:07 +00006521 ArrayExprs.push_back(Start.release());
6522 ArrayExprs.push_back(End.release());
6523 }
Mike Stump11289f42009-09-09 15:08:12 +00006524
Douglas Gregora16548e2009-08-11 05:31:07 +00006525 if (!getDerived().AlwaysRebuild() &&
6526 Init.get() == E->getInit() &&
6527 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006528 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006529
Douglas Gregora16548e2009-08-11 05:31:07 +00006530 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6531 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006532 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006533}
Mike Stump11289f42009-09-09 15:08:12 +00006534
Douglas Gregora16548e2009-08-11 05:31:07 +00006535template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006536ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006537TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006538 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00006539 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006540
Douglas Gregor3da3c062009-10-28 00:29:27 +00006541 // FIXME: Will we ever have proper type location here? Will we actually
6542 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00006543 QualType T = getDerived().TransformType(E->getType());
6544 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006545 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006546
Douglas Gregora16548e2009-08-11 05:31:07 +00006547 if (!getDerived().AlwaysRebuild() &&
6548 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006549 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006550
Douglas Gregora16548e2009-08-11 05:31:07 +00006551 return getDerived().RebuildImplicitValueInitExpr(T);
6552}
Mike Stump11289f42009-09-09 15:08:12 +00006553
Douglas Gregora16548e2009-08-11 05:31:07 +00006554template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006555ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006556TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00006557 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6558 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006559 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006560
John McCalldadc5752010-08-24 06:29:42 +00006561 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006562 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006563 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006564
Douglas Gregora16548e2009-08-11 05:31:07 +00006565 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00006566 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006567 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006568 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006569
John McCallb268a282010-08-23 23:25:46 +00006570 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00006571 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006572}
6573
6574template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006575ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006576TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006577 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006578 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006579 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6580 &ArgumentChanged))
6581 return ExprError();
6582
Douglas Gregora16548e2009-08-11 05:31:07 +00006583 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6584 move_arg(Inits),
6585 E->getRParenLoc());
6586}
Mike Stump11289f42009-09-09 15:08:12 +00006587
Douglas Gregora16548e2009-08-11 05:31:07 +00006588/// \brief Transform an address-of-label expression.
6589///
6590/// By default, the transformation of an address-of-label expression always
6591/// rebuilds the expression, so that the label identifier can be resolved to
6592/// the corresponding label statement by semantic analysis.
6593template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006594ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006595TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006596 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6597 E->getLabel());
6598 if (!LD)
6599 return ExprError();
6600
Douglas Gregora16548e2009-08-11 05:31:07 +00006601 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006602 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006603}
Mike Stump11289f42009-09-09 15:08:12 +00006604
6605template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006606ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006607TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006608 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006609 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6610 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006611 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006612
Douglas Gregora16548e2009-08-11 05:31:07 +00006613 if (!getDerived().AlwaysRebuild() &&
6614 SubStmt.get() == E->getSubStmt())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00006615 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00006616
6617 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006618 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006619 E->getRParenLoc());
6620}
Mike Stump11289f42009-09-09 15:08:12 +00006621
Douglas Gregora16548e2009-08-11 05:31:07 +00006622template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006623ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006624TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006625 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006626 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006627 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006628
John McCalldadc5752010-08-24 06:29:42 +00006629 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006630 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006631 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006632
John McCalldadc5752010-08-24 06:29:42 +00006633 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006634 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006635 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006636
Douglas Gregora16548e2009-08-11 05:31:07 +00006637 if (!getDerived().AlwaysRebuild() &&
6638 Cond.get() == E->getCond() &&
6639 LHS.get() == E->getLHS() &&
6640 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006641 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006642
Douglas Gregora16548e2009-08-11 05:31:07 +00006643 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006644 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006645 E->getRParenLoc());
6646}
Mike Stump11289f42009-09-09 15:08:12 +00006647
Douglas Gregora16548e2009-08-11 05:31:07 +00006648template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006649ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006650TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006651 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006652}
6653
6654template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006655ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006656TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006657 switch (E->getOperator()) {
6658 case OO_New:
6659 case OO_Delete:
6660 case OO_Array_New:
6661 case OO_Array_Delete:
6662 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006663 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006664
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006665 case OO_Call: {
6666 // This is a call to an object's operator().
6667 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6668
6669 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006670 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006671 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006672 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006673
6674 // FIXME: Poor location information
6675 SourceLocation FakeLParenLoc
6676 = SemaRef.PP.getLocForEndOfToken(
6677 static_cast<Expr *>(Object.get())->getLocEnd());
6678
6679 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006680 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006681 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6682 Args))
6683 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006684
John McCallb268a282010-08-23 23:25:46 +00006685 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006686 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006687 E->getLocEnd());
6688 }
6689
6690#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6691 case OO_##Name:
6692#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6693#include "clang/Basic/OperatorKinds.def"
6694 case OO_Subscript:
6695 // Handled below.
6696 break;
6697
6698 case OO_Conditional:
6699 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006700 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006701
6702 case OO_None:
6703 case NUM_OVERLOADED_OPERATORS:
6704 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006705 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006706 }
6707
John McCalldadc5752010-08-24 06:29:42 +00006708 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006709 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006710 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006711
John McCalldadc5752010-08-24 06:29:42 +00006712 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006713 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006714 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006715
John McCalldadc5752010-08-24 06:29:42 +00006716 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006717 if (E->getNumArgs() == 2) {
6718 Second = getDerived().TransformExpr(E->getArg(1));
6719 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006720 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006721 }
Mike Stump11289f42009-09-09 15:08:12 +00006722
Douglas Gregora16548e2009-08-11 05:31:07 +00006723 if (!getDerived().AlwaysRebuild() &&
6724 Callee.get() == E->getCallee() &&
6725 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006726 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00006727 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00006728
Douglas Gregora16548e2009-08-11 05:31:07 +00006729 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6730 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006731 Callee.get(),
6732 First.get(),
6733 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006734}
Mike Stump11289f42009-09-09 15:08:12 +00006735
Douglas Gregora16548e2009-08-11 05:31:07 +00006736template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006737ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006738TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6739 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006740}
Mike Stump11289f42009-09-09 15:08:12 +00006741
Douglas Gregora16548e2009-08-11 05:31:07 +00006742template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006743ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006744TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6745 // Transform the callee.
6746 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6747 if (Callee.isInvalid())
6748 return ExprError();
6749
6750 // Transform exec config.
6751 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6752 if (EC.isInvalid())
6753 return ExprError();
6754
6755 // Transform arguments.
6756 bool ArgChanged = false;
6757 ASTOwningVector<Expr*> Args(SemaRef);
6758 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6759 &ArgChanged))
6760 return ExprError();
6761
6762 if (!getDerived().AlwaysRebuild() &&
6763 Callee.get() == E->getCallee() &&
6764 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00006765 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00006766
6767 // FIXME: Wrong source location information for the '('.
6768 SourceLocation FakeLParenLoc
6769 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6770 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6771 move_arg(Args),
6772 E->getRParenLoc(), EC.get());
6773}
6774
6775template<typename Derived>
6776ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006777TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006778 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6779 if (!Type)
6780 return ExprError();
6781
John McCalldadc5752010-08-24 06:29:42 +00006782 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006783 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006784 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006785 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006786
Douglas Gregora16548e2009-08-11 05:31:07 +00006787 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006788 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006789 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006790 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006791
Douglas Gregora16548e2009-08-11 05:31:07 +00006792 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006793 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006794 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6795 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6796 SourceLocation FakeRParenLoc
6797 = SemaRef.PP.getLocForEndOfToken(
6798 E->getSubExpr()->getSourceRange().getEnd());
6799 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006800 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006801 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006802 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006803 FakeRAngleLoc,
6804 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006805 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006806 FakeRParenLoc);
6807}
Mike Stump11289f42009-09-09 15:08:12 +00006808
Douglas Gregora16548e2009-08-11 05:31:07 +00006809template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006810ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006811TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6812 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006813}
Mike Stump11289f42009-09-09 15:08:12 +00006814
6815template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006816ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006817TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6818 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006819}
6820
Douglas Gregora16548e2009-08-11 05:31:07 +00006821template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006822ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006823TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006824 CXXReinterpretCastExpr *E) {
6825 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006826}
Mike Stump11289f42009-09-09 15:08:12 +00006827
Douglas Gregora16548e2009-08-11 05:31:07 +00006828template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006829ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006830TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6831 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006832}
Mike Stump11289f42009-09-09 15:08:12 +00006833
Douglas Gregora16548e2009-08-11 05:31:07 +00006834template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006835ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006836TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006837 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006838 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6839 if (!Type)
6840 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006841
John McCalldadc5752010-08-24 06:29:42 +00006842 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006843 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006844 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006845 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006846
Douglas Gregora16548e2009-08-11 05:31:07 +00006847 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006848 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006849 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006850 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006851
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006852 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006853 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006854 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006855 E->getRParenLoc());
6856}
Mike Stump11289f42009-09-09 15:08:12 +00006857
Douglas Gregora16548e2009-08-11 05:31:07 +00006858template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006859ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006860TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006861 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006862 TypeSourceInfo *TInfo
6863 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6864 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006865 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006866
Douglas Gregora16548e2009-08-11 05:31:07 +00006867 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006868 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006869 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006870
Douglas Gregor9da64192010-04-26 22:37:10 +00006871 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6872 E->getLocStart(),
6873 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006874 E->getLocEnd());
6875 }
Mike Stump11289f42009-09-09 15:08:12 +00006876
Douglas Gregora16548e2009-08-11 05:31:07 +00006877 // We don't know whether the expression is potentially evaluated until
6878 // after we perform semantic analysis, so the expression is potentially
6879 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006880 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006881 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006882
John McCalldadc5752010-08-24 06:29:42 +00006883 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006884 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006885 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006886
Douglas Gregora16548e2009-08-11 05:31:07 +00006887 if (!getDerived().AlwaysRebuild() &&
6888 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006889 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006890
Douglas Gregor9da64192010-04-26 22:37:10 +00006891 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6892 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006893 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006894 E->getLocEnd());
6895}
6896
6897template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006898ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006899TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6900 if (E->isTypeOperand()) {
6901 TypeSourceInfo *TInfo
6902 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6903 if (!TInfo)
6904 return ExprError();
6905
6906 if (!getDerived().AlwaysRebuild() &&
6907 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006908 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006909
Douglas Gregor69735112011-03-06 17:40:41 +00006910 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00006911 E->getLocStart(),
6912 TInfo,
6913 E->getLocEnd());
6914 }
6915
6916 // We don't know whether the expression is potentially evaluated until
6917 // after we perform semantic analysis, so the expression is potentially
6918 // potentially evaluated.
6919 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6920
6921 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6922 if (SubExpr.isInvalid())
6923 return ExprError();
6924
6925 if (!getDerived().AlwaysRebuild() &&
6926 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006927 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006928
6929 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6930 E->getLocStart(),
6931 SubExpr.get(),
6932 E->getLocEnd());
6933}
6934
6935template<typename Derived>
6936ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006937TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006938 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006939}
Mike Stump11289f42009-09-09 15:08:12 +00006940
Douglas Gregora16548e2009-08-11 05:31:07 +00006941template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006942ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006943TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006944 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006945 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006946}
Mike Stump11289f42009-09-09 15:08:12 +00006947
Douglas Gregora16548e2009-08-11 05:31:07 +00006948template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006949ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006950TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006951 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith938f40b2011-06-11 17:19:42 +00006952 QualType T;
6953 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
6954 T = MD->getThisType(getSema().Context);
6955 else
6956 T = getSema().Context.getPointerType(
6957 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump11289f42009-09-09 15:08:12 +00006958
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006959 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006960 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006961
Douglas Gregorb15af892010-01-07 23:12:05 +00006962 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006963}
Mike Stump11289f42009-09-09 15:08:12 +00006964
Douglas Gregora16548e2009-08-11 05:31:07 +00006965template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006966ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006967TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006968 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006969 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006970 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006971
Douglas Gregora16548e2009-08-11 05:31:07 +00006972 if (!getDerived().AlwaysRebuild() &&
6973 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006974 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006975
Douglas Gregor53e191ed2011-07-06 22:04:06 +00006976 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
6977 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00006978}
Mike Stump11289f42009-09-09 15:08:12 +00006979
Douglas Gregora16548e2009-08-11 05:31:07 +00006980template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006981ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006982TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006983 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006984 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6985 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006986 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006987 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006988
Chandler Carruth794da4c2010-02-08 06:42:49 +00006989 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006990 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006991 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006992
Douglas Gregor033f6752009-12-23 23:03:06 +00006993 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006994}
Mike Stump11289f42009-09-09 15:08:12 +00006995
Douglas Gregora16548e2009-08-11 05:31:07 +00006996template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006997ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006998TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6999 CXXScalarValueInitExpr *E) {
7000 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7001 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007002 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00007003
Douglas Gregora16548e2009-08-11 05:31:07 +00007004 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007005 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007006 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007007
Douglas Gregor2b88c112010-09-08 00:15:04 +00007008 return getDerived().RebuildCXXScalarValueInitExpr(T,
7009 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00007010 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007011}
Mike Stump11289f42009-09-09 15:08:12 +00007012
Douglas Gregora16548e2009-08-11 05:31:07 +00007013template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007014ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007015TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007016 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00007017 TypeSourceInfo *AllocTypeInfo
7018 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7019 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007020 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007021
Douglas Gregora16548e2009-08-11 05:31:07 +00007022 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007023 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007024 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007025 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007026
Douglas Gregora16548e2009-08-11 05:31:07 +00007027 // Transform the placement arguments (if any).
7028 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007029 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007030 if (getDerived().TransformExprs(E->getPlacementArgs(),
7031 E->getNumPlacementArgs(), true,
7032 PlacementArgs, &ArgumentChanged))
7033 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007034
Douglas Gregorf333f8c2011-10-18 02:43:19 +00007035 // Transform the constructor arguments (if any).
7036 // As an annoying corner case, we may have introduced an implicit value-
7037 // initialization expression when allocating a new array, which we implicitly
7038 // drop. It will be re-created during type checking.
John McCall37ad5512010-08-23 06:44:23 +00007039 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregorf333f8c2011-10-18 02:43:19 +00007040 if (!(E->isArray() && E->getNumConstructorArgs() == 1 &&
7041 isa<ImplicitValueInitExpr>(E->getConstructorArgs()[0])) &&
7042 TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007043 ConstructorArgs, &ArgumentChanged))
7044 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007045
Douglas Gregord2d9da02010-02-26 00:38:10 +00007046 // Transform constructor, new operator, and delete operator.
7047 CXXConstructorDecl *Constructor = 0;
7048 if (E->getConstructor()) {
7049 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007050 getDerived().TransformDecl(E->getLocStart(),
7051 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007052 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007053 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007054 }
7055
7056 FunctionDecl *OperatorNew = 0;
7057 if (E->getOperatorNew()) {
7058 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007059 getDerived().TransformDecl(E->getLocStart(),
7060 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007061 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007062 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007063 }
7064
7065 FunctionDecl *OperatorDelete = 0;
7066 if (E->getOperatorDelete()) {
7067 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007068 getDerived().TransformDecl(E->getLocStart(),
7069 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007070 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007071 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007072 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007073
Douglas Gregora16548e2009-08-11 05:31:07 +00007074 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00007075 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007076 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007077 Constructor == E->getConstructor() &&
7078 OperatorNew == E->getOperatorNew() &&
7079 OperatorDelete == E->getOperatorDelete() &&
7080 !ArgumentChanged) {
7081 // Mark any declarations we need as referenced.
7082 // FIXME: instantiation-specific.
7083 if (Constructor)
7084 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
7085 if (OperatorNew)
7086 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
7087 if (OperatorDelete)
7088 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor72912fb2011-07-26 15:11:03 +00007089
7090 if (E->isArray() && Constructor &&
7091 !E->getAllocatedType()->isDependentType()) {
7092 QualType ElementType
7093 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7094 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7095 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7096 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
7097 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Destructor);
7098 }
7099 }
7100 }
7101
John McCallc3007a22010-10-26 07:05:15 +00007102 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007103 }
Mike Stump11289f42009-09-09 15:08:12 +00007104
Douglas Gregor0744ef62010-09-07 21:49:58 +00007105 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007106 if (!ArraySize.get()) {
7107 // If no array size was specified, but the new expression was
7108 // instantiated with an array type (e.g., "new T" where T is
7109 // instantiated with "int[4]"), extract the outer bound from the
7110 // array type as our array size. We do this with constant and
7111 // dependently-sized array types.
7112 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7113 if (!ArrayT) {
7114 // Do nothing
7115 } else if (const ConstantArrayType *ConsArrayT
7116 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007117 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007118 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7119 ConsArrayT->getSize(),
7120 SemaRef.Context.getSizeType(),
7121 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007122 AllocType = ConsArrayT->getElementType();
7123 } else if (const DependentSizedArrayType *DepArrayT
7124 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7125 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00007126 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007127 AllocType = DepArrayT->getElementType();
7128 }
7129 }
7130 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00007131
Douglas Gregora16548e2009-08-11 05:31:07 +00007132 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7133 E->isGlobalNew(),
7134 /*FIXME:*/E->getLocStart(),
7135 move_arg(PlacementArgs),
7136 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007137 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007138 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007139 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007140 ArraySize.get(),
Douglas Gregorf333f8c2011-10-18 02:43:19 +00007141 E->getConstructorLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007142 move_arg(ConstructorArgs),
Douglas Gregorf333f8c2011-10-18 02:43:19 +00007143 E->getConstructorRParen());
Douglas Gregora16548e2009-08-11 05:31:07 +00007144}
Mike Stump11289f42009-09-09 15:08:12 +00007145
Douglas Gregora16548e2009-08-11 05:31:07 +00007146template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007147ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007148TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007149 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007150 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007151 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007152
Douglas Gregord2d9da02010-02-26 00:38:10 +00007153 // Transform the delete operator, if known.
7154 FunctionDecl *OperatorDelete = 0;
7155 if (E->getOperatorDelete()) {
7156 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007157 getDerived().TransformDecl(E->getLocStart(),
7158 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007159 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007160 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007161 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007162
Douglas Gregora16548e2009-08-11 05:31:07 +00007163 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007164 Operand.get() == E->getArgument() &&
7165 OperatorDelete == E->getOperatorDelete()) {
7166 // Mark any declarations we need as referenced.
7167 // FIXME: instantiation-specific.
7168 if (OperatorDelete)
7169 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007170
7171 if (!E->getArgument()->isTypeDependent()) {
7172 QualType Destroyed = SemaRef.Context.getBaseElementType(
7173 E->getDestroyedType());
7174 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7175 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
7176 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
7177 SemaRef.LookupDestructor(Record));
7178 }
7179 }
7180
John McCallc3007a22010-10-26 07:05:15 +00007181 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007182 }
Mike Stump11289f42009-09-09 15:08:12 +00007183
Douglas Gregora16548e2009-08-11 05:31:07 +00007184 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7185 E->isGlobalDelete(),
7186 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007187 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007188}
Mike Stump11289f42009-09-09 15:08:12 +00007189
Douglas Gregora16548e2009-08-11 05:31:07 +00007190template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007191ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007192TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007193 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007194 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007195 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007196 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007197
John McCallba7bf592010-08-24 05:47:05 +00007198 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007199 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007200 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007201 E->getOperatorLoc(),
7202 E->isArrow()? tok::arrow : tok::period,
7203 ObjectTypePtr,
7204 MayBePseudoDestructor);
7205 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007206 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007207
John McCallba7bf592010-08-24 05:47:05 +00007208 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007209 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7210 if (QualifierLoc) {
7211 QualifierLoc
7212 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7213 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007214 return ExprError();
7215 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007216 CXXScopeSpec SS;
7217 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007218
Douglas Gregor678f90d2010-02-25 01:56:36 +00007219 PseudoDestructorTypeStorage Destroyed;
7220 if (E->getDestroyedTypeInfo()) {
7221 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007222 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00007223 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007224 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007225 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007226 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00007227 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00007228 // We aren't likely to be able to resolve the identifier down to a type
7229 // now anyway, so just retain the identifier.
7230 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7231 E->getDestroyedTypeLoc());
7232 } else {
7233 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007234 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007235 *E->getDestroyedTypeIdentifier(),
7236 E->getDestroyedTypeLoc(),
7237 /*Scope=*/0,
7238 SS, ObjectTypePtr,
7239 false);
7240 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007241 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007242
Douglas Gregor678f90d2010-02-25 01:56:36 +00007243 Destroyed
7244 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7245 E->getDestroyedTypeLoc());
7246 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007247
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007248 TypeSourceInfo *ScopeTypeInfo = 0;
7249 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00007250 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007251 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007252 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007253 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007254
John McCallb268a282010-08-23 23:25:46 +00007255 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007256 E->getOperatorLoc(),
7257 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007258 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007259 ScopeTypeInfo,
7260 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007261 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007262 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007263}
Mike Stump11289f42009-09-09 15:08:12 +00007264
Douglas Gregorad8a3362009-09-04 17:36:40 +00007265template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007266ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007267TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007268 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007269 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7270 Sema::LookupOrdinaryName);
7271
7272 // Transform all the decls.
7273 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7274 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007275 NamedDecl *InstD = static_cast<NamedDecl*>(
7276 getDerived().TransformDecl(Old->getNameLoc(),
7277 *I));
John McCall84d87672009-12-10 09:41:52 +00007278 if (!InstD) {
7279 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7280 // This can happen because of dependent hiding.
7281 if (isa<UsingShadowDecl>(*I))
7282 continue;
7283 else
John McCallfaf5fb42010-08-26 23:41:50 +00007284 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00007285 }
John McCalle66edc12009-11-24 19:00:30 +00007286
7287 // Expand using declarations.
7288 if (isa<UsingDecl>(InstD)) {
7289 UsingDecl *UD = cast<UsingDecl>(InstD);
7290 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7291 E = UD->shadow_end(); I != E; ++I)
7292 R.addDecl(*I);
7293 continue;
7294 }
7295
7296 R.addDecl(InstD);
7297 }
7298
7299 // Resolve a kind, but don't do any further analysis. If it's
7300 // ambiguous, the callee needs to deal with it.
7301 R.resolveKind();
7302
7303 // Rebuild the nested-name qualifier, if present.
7304 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007305 if (Old->getQualifierLoc()) {
7306 NestedNameSpecifierLoc QualifierLoc
7307 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7308 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007309 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007310
Douglas Gregor0da1d432011-02-28 20:01:57 +00007311 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007312 }
7313
Douglas Gregor9262f472010-04-27 18:19:34 +00007314 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007315 CXXRecordDecl *NamingClass
7316 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7317 Old->getNameLoc(),
7318 Old->getNamingClass()));
7319 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007320 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007321
Douglas Gregorda7be082010-04-27 16:10:10 +00007322 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007323 }
7324
7325 // If we have no template arguments, it's a normal declaration name.
7326 if (!Old->hasExplicitTemplateArgs())
7327 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7328
7329 // If we have template arguments, rebuild them, then rebuild the
7330 // templateid expression.
7331 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007332 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7333 Old->getNumTemplateArgs(),
7334 TransArgs))
7335 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00007336
7337 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7338 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007339}
Mike Stump11289f42009-09-09 15:08:12 +00007340
Douglas Gregora16548e2009-08-11 05:31:07 +00007341template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007342ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007343TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00007344 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7345 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007346 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007347
Douglas Gregora16548e2009-08-11 05:31:07 +00007348 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00007349 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007350 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007351
Mike Stump11289f42009-09-09 15:08:12 +00007352 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007353 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007354 T,
7355 E->getLocEnd());
7356}
Mike Stump11289f42009-09-09 15:08:12 +00007357
Douglas Gregora16548e2009-08-11 05:31:07 +00007358template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007359ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00007360TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7361 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7362 if (!LhsT)
7363 return ExprError();
7364
7365 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7366 if (!RhsT)
7367 return ExprError();
7368
7369 if (!getDerived().AlwaysRebuild() &&
7370 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7371 return SemaRef.Owned(E);
7372
7373 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7374 E->getLocStart(),
7375 LhsT, RhsT,
7376 E->getLocEnd());
7377}
7378
7379template<typename Derived>
7380ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00007381TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7382 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7383 if (!T)
7384 return ExprError();
7385
7386 if (!getDerived().AlwaysRebuild() &&
7387 T == E->getQueriedTypeSourceInfo())
7388 return SemaRef.Owned(E);
7389
7390 ExprResult SubExpr;
7391 {
7392 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7393 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7394 if (SubExpr.isInvalid())
7395 return ExprError();
7396
7397 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7398 return SemaRef.Owned(E);
7399 }
7400
7401 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7402 E->getLocStart(),
7403 T,
7404 SubExpr.get(),
7405 E->getLocEnd());
7406}
7407
7408template<typename Derived>
7409ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00007410TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7411 ExprResult SubExpr;
7412 {
7413 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7414 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7415 if (SubExpr.isInvalid())
7416 return ExprError();
7417
7418 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7419 return SemaRef.Owned(E);
7420 }
7421
7422 return getDerived().RebuildExpressionTrait(
7423 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7424}
7425
7426template<typename Derived>
7427ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007428TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007429 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007430 NestedNameSpecifierLoc QualifierLoc
7431 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7432 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007433 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007434
John McCall31f82722010-11-12 08:19:04 +00007435 // TODO: If this is a conversion-function-id, verify that the
7436 // destination type name (if present) resolves the same way after
7437 // instantiation as it did in the local scope.
7438
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007439 DeclarationNameInfo NameInfo
7440 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7441 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007442 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007443
John McCalle66edc12009-11-24 19:00:30 +00007444 if (!E->hasExplicitTemplateArgs()) {
7445 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007446 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007447 // Note: it is sufficient to compare the Name component of NameInfo:
7448 // if name has not changed, DNLoc has not changed either.
7449 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00007450 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007451
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007452 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007453 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007454 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00007455 }
John McCall6b51f282009-11-23 01:53:49 +00007456
7457 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007458 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7459 E->getNumTemplateArgs(),
7460 TransArgs))
7461 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007462
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007463 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007464 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007465 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007466}
7467
7468template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007469ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007470TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00007471 // CXXConstructExprs are always implicit, so when we have a
7472 // 1-argument construction we just transform that argument.
7473 if (E->getNumArgs() == 1 ||
7474 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7475 return getDerived().TransformExpr(E->getArg(0));
7476
Douglas Gregora16548e2009-08-11 05:31:07 +00007477 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7478
7479 QualType T = getDerived().TransformType(E->getType());
7480 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007481 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007482
7483 CXXConstructorDecl *Constructor
7484 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007485 getDerived().TransformDecl(E->getLocStart(),
7486 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007487 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007488 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007489
Douglas Gregora16548e2009-08-11 05:31:07 +00007490 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007491 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007492 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7493 &ArgumentChanged))
7494 return ExprError();
7495
Douglas Gregora16548e2009-08-11 05:31:07 +00007496 if (!getDerived().AlwaysRebuild() &&
7497 T == E->getType() &&
7498 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00007499 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00007500 // Mark the constructor as referenced.
7501 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00007502 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007503 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00007504 }
Mike Stump11289f42009-09-09 15:08:12 +00007505
Douglas Gregordb121ba2009-12-14 16:27:04 +00007506 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7507 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00007508 move_arg(Args),
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00007509 E->hadMultipleCandidates(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00007510 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00007511 E->getConstructionKind(),
7512 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007513}
Mike Stump11289f42009-09-09 15:08:12 +00007514
Douglas Gregora16548e2009-08-11 05:31:07 +00007515/// \brief Transform a C++ temporary-binding expression.
7516///
Douglas Gregor363b1512009-12-24 18:51:59 +00007517/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7518/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007519template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007520ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007521TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007522 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007523}
Mike Stump11289f42009-09-09 15:08:12 +00007524
John McCall5d413782010-12-06 08:20:24 +00007525/// \brief Transform a C++ expression that contains cleanups that should
7526/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00007527///
John McCall5d413782010-12-06 08:20:24 +00007528/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00007529/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007530template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007531ExprResult
John McCall5d413782010-12-06 08:20:24 +00007532TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007533 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007534}
Mike Stump11289f42009-09-09 15:08:12 +00007535
Douglas Gregora16548e2009-08-11 05:31:07 +00007536template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007537ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007538TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00007539 CXXTemporaryObjectExpr *E) {
7540 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7541 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007542 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007543
Douglas Gregora16548e2009-08-11 05:31:07 +00007544 CXXConstructorDecl *Constructor
7545 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00007546 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007547 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007548 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007549 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007550
Douglas Gregora16548e2009-08-11 05:31:07 +00007551 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007552 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00007553 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00007554 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7555 &ArgumentChanged))
7556 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007557
Douglas Gregora16548e2009-08-11 05:31:07 +00007558 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007559 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007560 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007561 !ArgumentChanged) {
7562 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00007563 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007564 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007565 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00007566
7567 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7568 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007569 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007570 E->getLocEnd());
7571}
Mike Stump11289f42009-09-09 15:08:12 +00007572
Douglas Gregora16548e2009-08-11 05:31:07 +00007573template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007574ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007575TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007576 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00007577 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7578 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007579 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007580
Douglas Gregora16548e2009-08-11 05:31:07 +00007581 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007582 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007583 Args.reserve(E->arg_size());
7584 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7585 &ArgumentChanged))
7586 return ExprError();
7587
Douglas Gregora16548e2009-08-11 05:31:07 +00007588 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007589 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007590 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007591 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007592
Douglas Gregora16548e2009-08-11 05:31:07 +00007593 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00007594 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00007595 E->getLParenLoc(),
7596 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007597 E->getRParenLoc());
7598}
Mike Stump11289f42009-09-09 15:08:12 +00007599
Douglas Gregora16548e2009-08-11 05:31:07 +00007600template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007601ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007602TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007603 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007604 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007605 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007606 Expr *OldBase;
7607 QualType BaseType;
7608 QualType ObjectType;
7609 if (!E->isImplicitAccess()) {
7610 OldBase = E->getBase();
7611 Base = getDerived().TransformExpr(OldBase);
7612 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007613 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007614
John McCall2d74de92009-12-01 22:10:20 +00007615 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00007616 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00007617 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007618 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007619 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007620 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00007621 ObjectTy,
7622 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00007623 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007624 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007625
John McCallba7bf592010-08-24 05:47:05 +00007626 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00007627 BaseType = ((Expr*) Base.get())->getType();
7628 } else {
7629 OldBase = 0;
7630 BaseType = getDerived().TransformType(E->getBaseType());
7631 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7632 }
Mike Stump11289f42009-09-09 15:08:12 +00007633
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007634 // Transform the first part of the nested-name-specifier that qualifies
7635 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007636 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007637 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00007638 E->getFirstQualifierFoundInScope(),
7639 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00007640
Douglas Gregore16af532011-02-28 18:50:33 +00007641 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007642 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00007643 QualifierLoc
7644 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7645 ObjectType,
7646 FirstQualifierInScope);
7647 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007648 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007649 }
Mike Stump11289f42009-09-09 15:08:12 +00007650
John McCall31f82722010-11-12 08:19:04 +00007651 // TODO: If this is a conversion-function-id, verify that the
7652 // destination type name (if present) resolves the same way after
7653 // instantiation as it did in the local scope.
7654
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007655 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007656 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007657 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007658 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007659
John McCall2d74de92009-12-01 22:10:20 +00007660 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007661 // This is a reference to a member without an explicitly-specified
7662 // template argument list. Optimize for this common case.
7663 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007664 Base.get() == OldBase &&
7665 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007666 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007667 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007668 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007669 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007670
John McCallb268a282010-08-23 23:25:46 +00007671 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007672 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007673 E->isArrow(),
7674 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007675 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007676 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007677 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007678 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007679 }
7680
John McCall6b51f282009-11-23 01:53:49 +00007681 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007682 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7683 E->getNumTemplateArgs(),
7684 TransArgs))
7685 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007686
John McCallb268a282010-08-23 23:25:46 +00007687 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007688 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007689 E->isArrow(),
7690 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007691 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007692 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007693 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007694 &TransArgs);
7695}
7696
7697template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007698ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007699TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007700 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007701 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007702 QualType BaseType;
7703 if (!Old->isImplicitAccess()) {
7704 Base = getDerived().TransformExpr(Old->getBase());
7705 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007706 return ExprError();
Richard Smithcab9a7d2011-10-26 19:06:56 +00007707 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
7708 Old->isArrow());
7709 if (Base.isInvalid())
7710 return ExprError();
7711 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00007712 } else {
7713 BaseType = getDerived().TransformType(Old->getBaseType());
7714 }
John McCall10eae182009-11-30 22:42:35 +00007715
Douglas Gregor0da1d432011-02-28 20:01:57 +00007716 NestedNameSpecifierLoc QualifierLoc;
7717 if (Old->getQualifierLoc()) {
7718 QualifierLoc
7719 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7720 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007721 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007722 }
7723
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007724 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007725 Sema::LookupOrdinaryName);
7726
7727 // Transform all the decls.
7728 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7729 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007730 NamedDecl *InstD = static_cast<NamedDecl*>(
7731 getDerived().TransformDecl(Old->getMemberLoc(),
7732 *I));
John McCall84d87672009-12-10 09:41:52 +00007733 if (!InstD) {
7734 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7735 // This can happen because of dependent hiding.
7736 if (isa<UsingShadowDecl>(*I))
7737 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007738 else {
7739 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007740 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007741 }
John McCall84d87672009-12-10 09:41:52 +00007742 }
John McCall10eae182009-11-30 22:42:35 +00007743
7744 // Expand using declarations.
7745 if (isa<UsingDecl>(InstD)) {
7746 UsingDecl *UD = cast<UsingDecl>(InstD);
7747 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7748 E = UD->shadow_end(); I != E; ++I)
7749 R.addDecl(*I);
7750 continue;
7751 }
7752
7753 R.addDecl(InstD);
7754 }
7755
7756 R.resolveKind();
7757
Douglas Gregor9262f472010-04-27 18:19:34 +00007758 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007759 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007760 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007761 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007762 Old->getMemberLoc(),
7763 Old->getNamingClass()));
7764 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007765 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007766
Douglas Gregorda7be082010-04-27 16:10:10 +00007767 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007768 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007769
John McCall10eae182009-11-30 22:42:35 +00007770 TemplateArgumentListInfo TransArgs;
7771 if (Old->hasExplicitTemplateArgs()) {
7772 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7773 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007774 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7775 Old->getNumTemplateArgs(),
7776 TransArgs))
7777 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007778 }
John McCall38836f02010-01-15 08:34:02 +00007779
7780 // FIXME: to do this check properly, we will need to preserve the
7781 // first-qualifier-in-scope here, just in case we had a dependent
7782 // base (and therefore couldn't do the check) and a
7783 // nested-name-qualifier (and therefore could do the lookup).
7784 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007785
John McCallb268a282010-08-23 23:25:46 +00007786 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007787 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007788 Old->getOperatorLoc(),
7789 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007790 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007791 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007792 R,
7793 (Old->hasExplicitTemplateArgs()
7794 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007795}
7796
7797template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007798ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007799TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00007800 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007801 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7802 if (SubExpr.isInvalid())
7803 return ExprError();
7804
7805 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007806 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007807
7808 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7809}
7810
7811template<typename Derived>
7812ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007813TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007814 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7815 if (Pattern.isInvalid())
7816 return ExprError();
7817
7818 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7819 return SemaRef.Owned(E);
7820
Douglas Gregorb8840002011-01-14 21:20:45 +00007821 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7822 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007823}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007824
7825template<typename Derived>
7826ExprResult
7827TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7828 // If E is not value-dependent, then nothing will change when we transform it.
7829 // Note: This is an instantiation-centric view.
7830 if (!E->isValueDependent())
7831 return SemaRef.Owned(E);
7832
7833 // Note: None of the implementations of TryExpandParameterPacks can ever
7834 // produce a diagnostic when given only a single unexpanded parameter pack,
7835 // so
7836 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7837 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007838 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007839 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007840 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00007841 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007842 ShouldExpand, RetainExpansion,
7843 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007844 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007845
Douglas Gregorab96bcf2011-10-10 18:59:29 +00007846 if (RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007847 return SemaRef.Owned(E);
Douglas Gregorab96bcf2011-10-10 18:59:29 +00007848
7849 NamedDecl *Pack = E->getPack();
7850 if (!ShouldExpand) {
7851 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
7852 Pack));
7853 if (!Pack)
7854 return ExprError();
7855 }
7856
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007857
7858 // We now know the length of the parameter pack, so build a new expression
7859 // that stores that length.
Douglas Gregorab96bcf2011-10-10 18:59:29 +00007860 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007861 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00007862 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007863}
7864
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007865template<typename Derived>
7866ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007867TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7868 SubstNonTypeTemplateParmPackExpr *E) {
7869 // Default behavior is to do nothing with this transformation.
7870 return SemaRef.Owned(E);
7871}
7872
7873template<typename Derived>
7874ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00007875TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
7876 SubstNonTypeTemplateParmExpr *E) {
7877 // Default behavior is to do nothing with this transformation.
7878 return SemaRef.Owned(E);
7879}
7880
7881template<typename Derived>
7882ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00007883TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
7884 MaterializeTemporaryExpr *E) {
7885 return getDerived().TransformExpr(E->GetTemporaryExpr());
7886}
7887
7888template<typename Derived>
7889ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007890TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007891 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007892}
7893
Mike Stump11289f42009-09-09 15:08:12 +00007894template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007895ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007896TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007897 TypeSourceInfo *EncodedTypeInfo
7898 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7899 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007900 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007901
Douglas Gregora16548e2009-08-11 05:31:07 +00007902 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007903 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007904 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007905
7906 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007907 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007908 E->getRParenLoc());
7909}
Mike Stump11289f42009-09-09 15:08:12 +00007910
Douglas Gregora16548e2009-08-11 05:31:07 +00007911template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00007912ExprResult TreeTransform<Derived>::
7913TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7914 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7915 if (result.isInvalid()) return ExprError();
7916 Expr *subExpr = result.take();
7917
7918 if (!getDerived().AlwaysRebuild() &&
7919 subExpr == E->getSubExpr())
7920 return SemaRef.Owned(E);
7921
7922 return SemaRef.Owned(new(SemaRef.Context)
7923 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7924}
7925
7926template<typename Derived>
7927ExprResult TreeTransform<Derived>::
7928TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7929 TypeSourceInfo *TSInfo
7930 = getDerived().TransformType(E->getTypeInfoAsWritten());
7931 if (!TSInfo)
7932 return ExprError();
7933
7934 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7935 if (Result.isInvalid())
7936 return ExprError();
7937
7938 if (!getDerived().AlwaysRebuild() &&
7939 TSInfo == E->getTypeInfoAsWritten() &&
7940 Result.get() == E->getSubExpr())
7941 return SemaRef.Owned(E);
7942
7943 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
7944 E->getBridgeKeywordLoc(), TSInfo,
7945 Result.get());
7946}
7947
7948template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007949ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007950TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007951 // Transform arguments.
7952 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007953 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007954 Args.reserve(E->getNumArgs());
7955 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7956 &ArgChanged))
7957 return ExprError();
7958
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007959 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7960 // Class message: transform the receiver type.
7961 TypeSourceInfo *ReceiverTypeInfo
7962 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7963 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007964 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007965
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007966 // If nothing changed, just retain the existing message send.
7967 if (!getDerived().AlwaysRebuild() &&
7968 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007969 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007970
7971 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00007972 SmallVector<SourceLocation, 16> SelLocs;
7973 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007974 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7975 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00007976 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007977 E->getMethodDecl(),
7978 E->getLeftLoc(),
7979 move_arg(Args),
7980 E->getRightLoc());
7981 }
7982
7983 // Instance message: transform the receiver
7984 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7985 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007986 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007987 = getDerived().TransformExpr(E->getInstanceReceiver());
7988 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007989 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007990
7991 // If nothing changed, just retain the existing message send.
7992 if (!getDerived().AlwaysRebuild() &&
7993 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007994 return SemaRef.MaybeBindToTemporary(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007995
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007996 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00007997 SmallVector<SourceLocation, 16> SelLocs;
7998 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00007999 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00008000 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00008001 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00008002 E->getMethodDecl(),
8003 E->getLeftLoc(),
8004 move_arg(Args),
8005 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008006}
8007
Mike Stump11289f42009-09-09 15:08:12 +00008008template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008009ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008010TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00008011 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008012}
8013
Mike Stump11289f42009-09-09 15:08:12 +00008014template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008015ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008016TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00008017 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008018}
8019
Mike Stump11289f42009-09-09 15:08:12 +00008020template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008021ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008022TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00008023 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00008024 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00008025 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008026 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00008027
8028 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00008029
Douglas Gregord51d90d2010-04-26 20:11:03 +00008030 // If nothing changed, just retain the existing expression.
8031 if (!getDerived().AlwaysRebuild() &&
8032 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00008033 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00008034
John McCallb268a282010-08-23 23:25:46 +00008035 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00008036 E->getLocation(),
8037 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00008038}
8039
Mike Stump11289f42009-09-09 15:08:12 +00008040template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008041ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008042TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00008043 // 'super' and types never change. Property never changes. Just
8044 // retain the existing expression.
8045 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00008046 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00008047
Douglas Gregor9faee212010-04-26 20:47:02 +00008048 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00008049 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00008050 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008051 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00008052
Douglas Gregor9faee212010-04-26 20:47:02 +00008053 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00008054
Douglas Gregor9faee212010-04-26 20:47:02 +00008055 // If nothing changed, just retain the existing expression.
8056 if (!getDerived().AlwaysRebuild() &&
8057 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00008058 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008059
John McCallb7bd14f2010-12-02 01:19:52 +00008060 if (E->isExplicitProperty())
8061 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8062 E->getExplicitProperty(),
8063 E->getLocation());
8064
8065 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00008066 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00008067 E->getImplicitPropertyGetter(),
8068 E->getImplicitPropertySetter(),
8069 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00008070}
8071
Mike Stump11289f42009-09-09 15:08:12 +00008072template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008073ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008074TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00008075 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00008076 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00008077 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008078 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00008079
Douglas Gregord51d90d2010-04-26 20:11:03 +00008080 // If nothing changed, just retain the existing expression.
8081 if (!getDerived().AlwaysRebuild() &&
8082 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00008083 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00008084
John McCallb268a282010-08-23 23:25:46 +00008085 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00008086 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00008087}
8088
Mike Stump11289f42009-09-09 15:08:12 +00008089template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008090ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008091TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008092 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00008093 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00008094 SubExprs.reserve(E->getNumSubExprs());
8095 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8096 SubExprs, &ArgumentChanged))
8097 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008098
Douglas Gregora16548e2009-08-11 05:31:07 +00008099 if (!getDerived().AlwaysRebuild() &&
8100 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00008101 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008102
Douglas Gregora16548e2009-08-11 05:31:07 +00008103 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8104 move_arg(SubExprs),
8105 E->getRParenLoc());
8106}
8107
Mike Stump11289f42009-09-09 15:08:12 +00008108template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008109ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008110TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00008111 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008112
John McCall490112f2011-02-04 18:33:18 +00008113 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8114 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8115
8116 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian4cc5df72011-05-05 17:18:12 +00008117 // We built a new blockScopeInfo in call to ActOnBlockStart
8118 // in above, CapturesCXXThis need be set here from the block
8119 // expression.
8120 blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00008121 blockScope->TheDecl->setBlockMissingReturnType(
8122 oldBlock->blockMissingReturnType());
Fariborz Jahanian4cc5df72011-05-05 17:18:12 +00008123
Chris Lattner01cf8db2011-07-20 06:58:45 +00008124 SmallVector<ParmVarDecl*, 4> params;
8125 SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008126
8127 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00008128 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8129 oldBlock->param_begin(),
8130 oldBlock->param_size(),
8131 0, paramTypes, &params))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008132 return ExprError();
John McCall490112f2011-02-04 18:33:18 +00008133
8134 const FunctionType *exprFunctionType = E->getFunctionType();
8135 QualType exprResultType = exprFunctionType->getResultType();
8136 if (!exprResultType.isNull()) {
8137 if (!exprResultType->isDependentType())
8138 blockScope->ReturnType = exprResultType;
8139 else if (exprResultType != getSema().Context.DependentTy)
8140 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008141 }
Douglas Gregor476e3022011-01-19 21:32:01 +00008142
8143 // If the return type has not been determined yet, leave it as a dependent
8144 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00008145 if (blockScope->ReturnType.isNull())
8146 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00008147
8148 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00008149 if (blockScope->ReturnType->isObjCObjectType()) {
8150 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00008151 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00008152 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00008153 return ExprError();
8154 }
John McCall3882ace2011-01-05 12:14:39 +00008155
John McCall490112f2011-02-04 18:33:18 +00008156 QualType functionType = getDerived().RebuildFunctionProtoType(
8157 blockScope->ReturnType,
8158 paramTypes.data(),
8159 paramTypes.size(),
8160 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00008161 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00008162 exprFunctionType->getExtInfo());
8163 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00008164
8165 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00008166 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00008167 blockScope->TheDecl->setParams(params);
Douglas Gregor476e3022011-01-19 21:32:01 +00008168
8169 // If the return type wasn't explicitly set, it will have been marked as a
8170 // dependent type (DependentTy); clear out the return type setting so
8171 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00008172 if (blockScope->ReturnType == getSema().Context.DependentTy)
8173 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00008174
John McCall3882ace2011-01-05 12:14:39 +00008175 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00008176 StmtResult body = getDerived().TransformStmt(E->getBody());
8177 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00008178 return ExprError();
8179
John McCall490112f2011-02-04 18:33:18 +00008180#ifndef NDEBUG
8181 // In builds with assertions, make sure that we captured everything we
8182 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00008183 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8184 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8185 e = oldBlock->capture_end(); i != e; ++i) {
8186 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00008187
Douglas Gregor4385d8b2011-05-20 15:32:55 +00008188 // Ignore parameter packs.
8189 if (isa<ParmVarDecl>(oldCapture) &&
8190 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8191 continue;
John McCall490112f2011-02-04 18:33:18 +00008192
Douglas Gregor4385d8b2011-05-20 15:32:55 +00008193 VarDecl *newCapture =
8194 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8195 oldCapture));
8196 assert(blockScope->CaptureMap.count(newCapture));
8197 }
John McCall490112f2011-02-04 18:33:18 +00008198 }
8199#endif
8200
8201 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8202 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00008203}
8204
Mike Stump11289f42009-09-09 15:08:12 +00008205template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008206ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008207TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008208 ValueDecl *ND
8209 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8210 E->getDecl()));
8211 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008212 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008213
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008214 if (!getDerived().AlwaysRebuild() &&
8215 ND == E->getDecl()) {
8216 // Mark it referenced in the new context regardless.
8217 // FIXME: this is a bit instantiation-specific.
8218 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
8219
John McCallc3007a22010-10-26 07:05:15 +00008220 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008221 }
8222
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008223 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00008224 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008225 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00008226}
Mike Stump11289f42009-09-09 15:08:12 +00008227
Tanya Lattner55808c12011-06-04 00:47:47 +00008228template<typename Derived>
8229ExprResult
8230TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00008231 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00008232}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00008233
8234template<typename Derived>
8235ExprResult
8236TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00008237 QualType RetTy = getDerived().TransformType(E->getType());
8238 bool ArgumentChanged = false;
8239 ASTOwningVector<Expr*> SubExprs(SemaRef);
8240 SubExprs.reserve(E->getNumSubExprs());
8241 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8242 SubExprs, &ArgumentChanged))
8243 return ExprError();
8244
8245 if (!getDerived().AlwaysRebuild() &&
8246 !ArgumentChanged)
8247 return SemaRef.Owned(E);
8248
8249 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8250 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00008251}
Tanya Lattner55808c12011-06-04 00:47:47 +00008252
Douglas Gregora16548e2009-08-11 05:31:07 +00008253//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008254// Type reconstruction
8255//===----------------------------------------------------------------------===//
8256
Mike Stump11289f42009-09-09 15:08:12 +00008257template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00008258QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8259 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00008260 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008261 getDerived().getBaseEntity());
8262}
8263
Mike Stump11289f42009-09-09 15:08:12 +00008264template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00008265QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8266 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00008267 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008268 getDerived().getBaseEntity());
8269}
8270
Mike Stump11289f42009-09-09 15:08:12 +00008271template<typename Derived>
8272QualType
John McCall70dd5f62009-10-30 00:06:24 +00008273TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8274 bool WrittenAsLValue,
8275 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00008276 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00008277 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008278}
8279
8280template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008281QualType
John McCall70dd5f62009-10-30 00:06:24 +00008282TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8283 QualType ClassType,
8284 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00008285 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00008286 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008287}
8288
8289template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008290QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00008291TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8292 ArrayType::ArraySizeModifier SizeMod,
8293 const llvm::APInt *Size,
8294 Expr *SizeExpr,
8295 unsigned IndexTypeQuals,
8296 SourceRange BracketsRange) {
8297 if (SizeExpr || !Size)
8298 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8299 IndexTypeQuals, BracketsRange,
8300 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00008301
8302 QualType Types[] = {
8303 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8304 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8305 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00008306 };
8307 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8308 QualType SizeType;
8309 for (unsigned I = 0; I != NumTypes; ++I)
8310 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8311 SizeType = Types[I];
8312 break;
8313 }
Mike Stump11289f42009-09-09 15:08:12 +00008314
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00008315 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
8316 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00008317 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008318 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00008319 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008320}
Mike Stump11289f42009-09-09 15:08:12 +00008321
Douglas Gregord6ff3322009-08-04 16:50:30 +00008322template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008323QualType
8324TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008325 ArrayType::ArraySizeModifier SizeMod,
8326 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00008327 unsigned IndexTypeQuals,
8328 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008329 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00008330 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008331}
8332
8333template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008334QualType
Mike Stump11289f42009-09-09 15:08:12 +00008335TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008336 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00008337 unsigned IndexTypeQuals,
8338 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008339 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00008340 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008341}
Mike Stump11289f42009-09-09 15:08:12 +00008342
Douglas Gregord6ff3322009-08-04 16:50:30 +00008343template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008344QualType
8345TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008346 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00008347 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008348 unsigned IndexTypeQuals,
8349 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008350 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00008351 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008352 IndexTypeQuals, BracketsRange);
8353}
8354
8355template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008356QualType
8357TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008358 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00008359 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008360 unsigned IndexTypeQuals,
8361 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008362 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00008363 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008364 IndexTypeQuals, BracketsRange);
8365}
8366
8367template<typename Derived>
8368QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00008369 unsigned NumElements,
8370 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00008371 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00008372 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008373}
Mike Stump11289f42009-09-09 15:08:12 +00008374
Douglas Gregord6ff3322009-08-04 16:50:30 +00008375template<typename Derived>
8376QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8377 unsigned NumElements,
8378 SourceLocation AttributeLoc) {
8379 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8380 NumElements, true);
8381 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00008382 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8383 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00008384 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008385}
Mike Stump11289f42009-09-09 15:08:12 +00008386
Douglas Gregord6ff3322009-08-04 16:50:30 +00008387template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008388QualType
8389TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00008390 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008391 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00008392 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008393}
Mike Stump11289f42009-09-09 15:08:12 +00008394
Douglas Gregord6ff3322009-08-04 16:50:30 +00008395template<typename Derived>
8396QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00008397 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008398 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00008399 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00008400 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00008401 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00008402 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00008403 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00008404 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008405 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00008406 getDerived().getBaseEntity(),
8407 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008408}
Mike Stump11289f42009-09-09 15:08:12 +00008409
Douglas Gregord6ff3322009-08-04 16:50:30 +00008410template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00008411QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8412 return SemaRef.Context.getFunctionNoProtoType(T);
8413}
8414
8415template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00008416QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8417 assert(D && "no decl found");
8418 if (D->isInvalidDecl()) return QualType();
8419
Douglas Gregorc298ffc2010-04-22 16:44:27 +00008420 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00008421 TypeDecl *Ty;
8422 if (isa<UsingDecl>(D)) {
8423 UsingDecl *Using = cast<UsingDecl>(D);
8424 assert(Using->isTypeName() &&
8425 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8426
8427 // A valid resolved using typename decl points to exactly one type decl.
8428 assert(++Using->shadow_begin() == Using->shadow_end());
8429 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00008430
John McCallb96ec562009-12-04 22:46:56 +00008431 } else {
8432 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8433 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8434 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8435 }
8436
8437 return SemaRef.Context.getTypeDeclType(Ty);
8438}
8439
8440template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008441QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8442 SourceLocation Loc) {
8443 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008444}
8445
8446template<typename Derived>
8447QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8448 return SemaRef.Context.getTypeOfType(Underlying);
8449}
8450
8451template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008452QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8453 SourceLocation Loc) {
8454 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008455}
8456
8457template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00008458QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8459 UnaryTransformType::UTTKind UKind,
8460 SourceLocation Loc) {
8461 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8462}
8463
8464template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00008465QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00008466 TemplateName Template,
8467 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00008468 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00008469 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008470}
Mike Stump11289f42009-09-09 15:08:12 +00008471
Douglas Gregor1135c352009-08-06 05:28:30 +00008472template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00008473QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
8474 SourceLocation KWLoc) {
8475 return SemaRef.BuildAtomicType(ValueType, KWLoc);
8476}
8477
8478template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008479TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008480TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008481 bool TemplateKW,
8482 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008483 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008484 Template);
8485}
8486
8487template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008488TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008489TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8490 const IdentifierInfo &Name,
8491 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00008492 QualType ObjectType,
8493 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008494 UnqualifiedId TemplateName;
8495 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00008496 Sema::TemplateTy Template;
8497 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008498 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008499 SS,
Douglas Gregor9db53502011-03-02 18:07:45 +00008500 TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00008501 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008502 /*EnteringContext=*/false,
8503 Template);
John McCall31f82722010-11-12 08:19:04 +00008504 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00008505}
Mike Stump11289f42009-09-09 15:08:12 +00008506
Douglas Gregora16548e2009-08-11 05:31:07 +00008507template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00008508TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008509TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008510 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00008511 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008512 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00008513 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00008514 // FIXME: Bogus location information.
8515 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8516 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00008517 Sema::TemplateTy Template;
8518 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008519 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008520 SS,
8521 Name,
John McCallba7bf592010-08-24 05:47:05 +00008522 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008523 /*EnteringContext=*/false,
8524 Template);
8525 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00008526}
Alexis Hunta8136cc2010-05-05 15:23:54 +00008527
Douglas Gregor71395fa2009-11-04 00:56:37 +00008528template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008529ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008530TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8531 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008532 Expr *OrigCallee,
8533 Expr *First,
8534 Expr *Second) {
8535 Expr *Callee = OrigCallee->IgnoreParenCasts();
8536 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00008537
Douglas Gregora16548e2009-08-11 05:31:07 +00008538 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00008539 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00008540 if (!First->getType()->isOverloadableType() &&
8541 !Second->getType()->isOverloadableType())
8542 return getSema().CreateBuiltinArraySubscriptExpr(First,
8543 Callee->getLocStart(),
8544 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00008545 } else if (Op == OO_Arrow) {
8546 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00008547 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8548 } else if (Second == 0 || isPostIncDec) {
8549 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008550 // The argument is not of overloadable type, so try to create a
8551 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00008552 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008553 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00008554
John McCallb268a282010-08-23 23:25:46 +00008555 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008556 }
8557 } else {
John McCallb268a282010-08-23 23:25:46 +00008558 if (!First->getType()->isOverloadableType() &&
8559 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008560 // Neither of the arguments is an overloadable type, so try to
8561 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00008562 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008563 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00008564 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00008565 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008566 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008567
Douglas Gregora16548e2009-08-11 05:31:07 +00008568 return move(Result);
8569 }
8570 }
Mike Stump11289f42009-09-09 15:08:12 +00008571
8572 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00008573 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00008574 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00008575
John McCallb268a282010-08-23 23:25:46 +00008576 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00008577 assert(ULE->requiresADL());
8578
8579 // FIXME: Do we have to check
8580 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00008581 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00008582 } else {
John McCallb268a282010-08-23 23:25:46 +00008583 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00008584 }
Mike Stump11289f42009-09-09 15:08:12 +00008585
Douglas Gregora16548e2009-08-11 05:31:07 +00008586 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00008587 Expr *Args[2] = { First, Second };
8588 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00008589
Douglas Gregora16548e2009-08-11 05:31:07 +00008590 // Create the overloaded operator invocation for unary operators.
8591 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00008592 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008593 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00008594 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008595 }
Mike Stump11289f42009-09-09 15:08:12 +00008596
Douglas Gregore9d62932011-07-15 16:25:15 +00008597 if (Op == OO_Subscript) {
8598 SourceLocation LBrace;
8599 SourceLocation RBrace;
8600
8601 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
8602 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
8603 LBrace = SourceLocation::getFromRawEncoding(
8604 NameLoc.CXXOperatorName.BeginOpNameLoc);
8605 RBrace = SourceLocation::getFromRawEncoding(
8606 NameLoc.CXXOperatorName.EndOpNameLoc);
8607 } else {
8608 LBrace = Callee->getLocStart();
8609 RBrace = OpLoc;
8610 }
8611
8612 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
8613 First, Second);
8614 }
Sebastian Redladba46e2009-10-29 20:17:01 +00008615
Douglas Gregora16548e2009-08-11 05:31:07 +00008616 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00008617 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008618 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00008619 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8620 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008621 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008622
Mike Stump11289f42009-09-09 15:08:12 +00008623 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00008624}
Mike Stump11289f42009-09-09 15:08:12 +00008625
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008626template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008627ExprResult
John McCallb268a282010-08-23 23:25:46 +00008628TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008629 SourceLocation OperatorLoc,
8630 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00008631 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008632 TypeSourceInfo *ScopeType,
8633 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008634 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008635 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00008636 QualType BaseType = Base->getType();
8637 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008638 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00008639 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00008640 !BaseType->getAs<PointerType>()->getPointeeType()
8641 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008642 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00008643 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008644 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008645 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008646 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008647 /*FIXME?*/true);
8648 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008649
Douglas Gregor678f90d2010-02-25 01:56:36 +00008650 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008651 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8652 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8653 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8654 NameInfo.setNamedTypeInfo(DestroyedType);
8655
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008656 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008657
John McCallb268a282010-08-23 23:25:46 +00008658 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008659 OperatorLoc, isArrow,
8660 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008661 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008662 /*TemplateArgs*/ 0);
8663}
8664
Douglas Gregord6ff3322009-08-04 16:50:30 +00008665} // end namespace clang
8666
8667#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H