blob: 46bd05b14ba6787cedf134d96a136533d5c629dd [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) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001471 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001472 // We have a reference to an unnamed field. This is always the
1473 // base of an anonymous struct/union member access, i.e. the
1474 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001475 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001476 assert(Member->getType()->isRecordType() &&
1477 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001478
John Wiegley01296292011-04-08 18:41:53 +00001479 ExprResult BaseResult =
1480 getSema().PerformObjectMemberConversion(Base,
1481 QualifierLoc.getNestedNameSpecifier(),
1482 FoundDecl, Member);
1483 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001484 return ExprError();
John Wiegley01296292011-04-08 18:41:53 +00001485 Base = BaseResult.take();
John McCall7decc9e2010-11-18 06:31:45 +00001486 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001487 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001488 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001489 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001490 cast<FieldDecl>(Member)->getType(),
1491 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001492 return getSema().Owned(ME);
1493 }
Mike Stump11289f42009-09-09 15:08:12 +00001494
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001495 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001496 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001497
John Wiegley01296292011-04-08 18:41:53 +00001498 ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base);
1499 if (BaseResult.isInvalid())
1500 return ExprError();
Richard Smith841222e2011-10-25 00:41:24 +00001501 if (isArrow) {
1502 BaseResult = getSema().DefaultLvalueConversion(BaseResult.get());
1503 if (BaseResult.isInvalid())
1504 return ExprError();
1505 }
John Wiegley01296292011-04-08 18:41:53 +00001506 Base = BaseResult.take();
John McCallb268a282010-08-23 23:25:46 +00001507 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001508
John McCall16df1e52010-03-30 21:47:33 +00001509 // FIXME: this involves duplicating earlier analysis in a lot of
1510 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001511 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001512 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001513 R.resolveKind();
1514
John McCallb268a282010-08-23 23:25:46 +00001515 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001516 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001517 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001518 }
Mike Stump11289f42009-09-09 15:08:12 +00001519
Douglas Gregora16548e2009-08-11 05:31:07 +00001520 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001521 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 /// By default, performs semantic analysis to build the new expression.
1523 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001524 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001525 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001526 Expr *LHS, Expr *RHS) {
1527 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001528 }
1529
1530 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001531 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001532 /// By default, performs semantic analysis to build the new expression.
1533 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001534 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001535 SourceLocation QuestionLoc,
1536 Expr *LHS,
1537 SourceLocation ColonLoc,
1538 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001539 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1540 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001541 }
1542
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001544 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001545 /// By default, performs semantic analysis to build the new expression.
1546 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001547 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001548 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001549 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001550 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001551 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001552 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001553 }
Mike Stump11289f42009-09-09 15:08:12 +00001554
Douglas Gregora16548e2009-08-11 05:31:07 +00001555 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001556 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001557 /// By default, performs semantic analysis to build the new expression.
1558 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001559 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001560 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001561 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001562 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001563 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001564 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001565 }
Mike Stump11289f42009-09-09 15:08:12 +00001566
Douglas Gregora16548e2009-08-11 05:31:07 +00001567 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001568 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001569 /// By default, performs semantic analysis to build the new expression.
1570 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001571 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001572 SourceLocation OpLoc,
1573 SourceLocation AccessorLoc,
1574 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001575
John McCall10eae182009-11-30 22:42:35 +00001576 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001577 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001578 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001579 OpLoc, /*IsArrow*/ false,
1580 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001581 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001582 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001583 }
Mike Stump11289f42009-09-09 15:08:12 +00001584
Douglas Gregora16548e2009-08-11 05:31:07 +00001585 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001586 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001587 /// By default, performs semantic analysis to build the new expression.
1588 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001589 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001590 MultiExprArg Inits,
1591 SourceLocation RBraceLoc,
1592 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001593 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001594 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1595 if (Result.isInvalid() || ResultTy->isDependentType())
1596 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001597
Douglas Gregord3d93062009-11-09 17:16:50 +00001598 // Patch in the result type we were given, which may have been computed
1599 // when the initial InitListExpr was built.
1600 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1601 ILE->setType(ResultTy);
1602 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001603 }
Mike Stump11289f42009-09-09 15:08:12 +00001604
Douglas Gregora16548e2009-08-11 05:31:07 +00001605 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001606 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001607 /// By default, performs semantic analysis to build the new expression.
1608 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001609 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001610 MultiExprArg ArrayExprs,
1611 SourceLocation EqualOrColonLoc,
1612 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001613 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001614 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001615 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001616 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001617 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001618 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001619
Douglas Gregora16548e2009-08-11 05:31:07 +00001620 ArrayExprs.release();
1621 return move(Result);
1622 }
Mike Stump11289f42009-09-09 15:08:12 +00001623
Douglas Gregora16548e2009-08-11 05:31:07 +00001624 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001625 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001626 /// By default, builds the implicit value initialization without performing
1627 /// any semantic analysis. Subclasses may override this routine to provide
1628 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001629 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001630 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1631 }
Mike Stump11289f42009-09-09 15:08:12 +00001632
Douglas Gregora16548e2009-08-11 05:31:07 +00001633 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001634 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 /// By default, performs semantic analysis to build the new expression.
1636 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001637 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001638 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001639 SourceLocation RParenLoc) {
1640 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001641 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001642 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001643 }
1644
1645 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001646 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001647 /// By default, performs semantic analysis to build the new expression.
1648 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001649 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001650 MultiExprArg SubExprs,
1651 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001652 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001653 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001654 }
Mike Stump11289f42009-09-09 15:08:12 +00001655
Douglas Gregora16548e2009-08-11 05:31:07 +00001656 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001657 ///
1658 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001659 /// rather than attempting to map the label statement itself.
1660 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001661 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001662 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001663 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001664 }
Mike Stump11289f42009-09-09 15:08:12 +00001665
Douglas Gregora16548e2009-08-11 05:31:07 +00001666 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001667 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001668 /// By default, performs semantic analysis to build the new expression.
1669 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001670 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001671 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001672 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001673 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001674 }
Mike Stump11289f42009-09-09 15:08:12 +00001675
Douglas Gregora16548e2009-08-11 05:31:07 +00001676 /// \brief Build a new __builtin_choose_expr expression.
1677 ///
1678 /// By default, performs semantic analysis to build the new expression.
1679 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001680 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001681 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001682 SourceLocation RParenLoc) {
1683 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001684 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001685 RParenLoc);
1686 }
Mike Stump11289f42009-09-09 15:08:12 +00001687
Peter Collingbourne91147592011-04-15 00:35:48 +00001688 /// \brief Build a new generic selection expression.
1689 ///
1690 /// By default, performs semantic analysis to build the new expression.
1691 /// Subclasses may override this routine to provide different behavior.
1692 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1693 SourceLocation DefaultLoc,
1694 SourceLocation RParenLoc,
1695 Expr *ControllingExpr,
1696 TypeSourceInfo **Types,
1697 Expr **Exprs,
1698 unsigned NumAssocs) {
1699 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1700 ControllingExpr, Types, Exprs,
1701 NumAssocs);
1702 }
1703
Douglas Gregora16548e2009-08-11 05:31:07 +00001704 /// \brief Build a new overloaded operator call expression.
1705 ///
1706 /// By default, performs semantic analysis to build the new expression.
1707 /// The semantic analysis provides the behavior of template instantiation,
1708 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001709 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001710 /// argument-dependent lookup, etc. Subclasses may override this routine to
1711 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001712 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001713 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001714 Expr *Callee,
1715 Expr *First,
1716 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001717
1718 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001719 /// reinterpret_cast.
1720 ///
1721 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001722 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001723 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001724 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001725 Stmt::StmtClass Class,
1726 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001727 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001728 SourceLocation RAngleLoc,
1729 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001730 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001731 SourceLocation RParenLoc) {
1732 switch (Class) {
1733 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001734 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001735 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001736 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001737
1738 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001739 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001740 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001741 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001742
Douglas Gregora16548e2009-08-11 05:31:07 +00001743 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001744 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001745 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001746 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001747 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001748
Douglas Gregora16548e2009-08-11 05:31:07 +00001749 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001750 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001751 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001752 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001753
Douglas Gregora16548e2009-08-11 05:31:07 +00001754 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001755 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00001756 }
Mike Stump11289f42009-09-09 15:08:12 +00001757
John McCallfaf5fb42010-08-26 23:41:50 +00001758 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001759 }
Mike Stump11289f42009-09-09 15:08:12 +00001760
Douglas Gregora16548e2009-08-11 05:31:07 +00001761 /// \brief Build a new C++ static_cast expression.
1762 ///
1763 /// By default, performs semantic analysis to build the new expression.
1764 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001765 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001766 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001767 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001768 SourceLocation RAngleLoc,
1769 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001770 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001771 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001772 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001773 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001774 SourceRange(LAngleLoc, RAngleLoc),
1775 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001776 }
1777
1778 /// \brief Build a new C++ dynamic_cast expression.
1779 ///
1780 /// By default, performs semantic analysis to build the new expression.
1781 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001782 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001783 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001784 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001785 SourceLocation RAngleLoc,
1786 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001787 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001788 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001789 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001790 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001791 SourceRange(LAngleLoc, RAngleLoc),
1792 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001793 }
1794
1795 /// \brief Build a new C++ reinterpret_cast expression.
1796 ///
1797 /// By default, performs semantic analysis to build the new expression.
1798 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001799 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001800 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001801 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001802 SourceLocation RAngleLoc,
1803 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001804 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001805 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001806 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001807 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001808 SourceRange(LAngleLoc, RAngleLoc),
1809 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001810 }
1811
1812 /// \brief Build a new C++ const_cast expression.
1813 ///
1814 /// By default, performs semantic analysis to build the new expression.
1815 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001816 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001817 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001818 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001819 SourceLocation RAngleLoc,
1820 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001821 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001822 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001823 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001824 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001825 SourceRange(LAngleLoc, RAngleLoc),
1826 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001827 }
Mike Stump11289f42009-09-09 15:08:12 +00001828
Douglas Gregora16548e2009-08-11 05:31:07 +00001829 /// \brief Build a new C++ functional-style cast expression.
1830 ///
1831 /// By default, performs semantic analysis to build the new expression.
1832 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001833 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1834 SourceLocation LParenLoc,
1835 Expr *Sub,
1836 SourceLocation RParenLoc) {
1837 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001838 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001839 RParenLoc);
1840 }
Mike Stump11289f42009-09-09 15:08:12 +00001841
Douglas Gregora16548e2009-08-11 05:31:07 +00001842 /// \brief Build a new C++ typeid(type) expression.
1843 ///
1844 /// By default, performs semantic analysis to build the new expression.
1845 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001846 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001847 SourceLocation TypeidLoc,
1848 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001849 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001850 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001851 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001852 }
Mike Stump11289f42009-09-09 15:08:12 +00001853
Francois Pichet9f4f2072010-09-08 12:20:18 +00001854
Douglas Gregora16548e2009-08-11 05:31:07 +00001855 /// \brief Build a new C++ typeid(expr) expression.
1856 ///
1857 /// By default, performs semantic analysis to build the new expression.
1858 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001859 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001860 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001861 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001862 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001863 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001864 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001865 }
1866
Francois Pichet9f4f2072010-09-08 12:20:18 +00001867 /// \brief Build a new C++ __uuidof(type) expression.
1868 ///
1869 /// By default, performs semantic analysis to build the new expression.
1870 /// Subclasses may override this routine to provide different behavior.
1871 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1872 SourceLocation TypeidLoc,
1873 TypeSourceInfo *Operand,
1874 SourceLocation RParenLoc) {
1875 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1876 RParenLoc);
1877 }
1878
1879 /// \brief Build a new C++ __uuidof(expr) expression.
1880 ///
1881 /// By default, performs semantic analysis to build the new expression.
1882 /// Subclasses may override this routine to provide different behavior.
1883 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1884 SourceLocation TypeidLoc,
1885 Expr *Operand,
1886 SourceLocation RParenLoc) {
1887 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1888 RParenLoc);
1889 }
1890
Douglas Gregora16548e2009-08-11 05:31:07 +00001891 /// \brief Build a new C++ "this" expression.
1892 ///
1893 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001894 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001895 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001896 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001897 QualType ThisType,
1898 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001899 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001900 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1901 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001902 }
1903
1904 /// \brief Build a new C++ throw expression.
1905 ///
1906 /// By default, performs semantic analysis to build the new expression.
1907 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00001908 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1909 bool IsThrownVariableInScope) {
1910 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00001911 }
1912
1913 /// \brief Build a new C++ default-argument expression.
1914 ///
1915 /// By default, builds a new default-argument expression, which does not
1916 /// require any semantic analysis. Subclasses may override this routine to
1917 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001918 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001919 ParmVarDecl *Param) {
1920 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1921 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001922 }
1923
1924 /// \brief Build a new C++ zero-initialization expression.
1925 ///
1926 /// By default, performs semantic analysis to build the new expression.
1927 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001928 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1929 SourceLocation LParenLoc,
1930 SourceLocation RParenLoc) {
1931 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001932 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001933 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001934 }
Mike Stump11289f42009-09-09 15:08:12 +00001935
Douglas Gregora16548e2009-08-11 05:31:07 +00001936 /// \brief Build a new C++ "new" expression.
1937 ///
1938 /// By default, performs semantic analysis to build the new expression.
1939 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001940 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001941 bool UseGlobal,
1942 SourceLocation PlacementLParen,
1943 MultiExprArg PlacementArgs,
1944 SourceLocation PlacementRParen,
1945 SourceRange TypeIdParens,
1946 QualType AllocatedType,
1947 TypeSourceInfo *AllocatedTypeInfo,
1948 Expr *ArraySize,
1949 SourceLocation ConstructorLParen,
1950 MultiExprArg ConstructorArgs,
1951 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001952 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001953 PlacementLParen,
1954 move(PlacementArgs),
1955 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001956 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001957 AllocatedType,
1958 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001959 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001960 ConstructorLParen,
1961 move(ConstructorArgs),
1962 ConstructorRParen);
1963 }
Mike Stump11289f42009-09-09 15:08:12 +00001964
Douglas Gregora16548e2009-08-11 05:31:07 +00001965 /// \brief Build a new C++ "delete" expression.
1966 ///
1967 /// By default, performs semantic analysis to build the new expression.
1968 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001969 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001970 bool IsGlobalDelete,
1971 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001972 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001973 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001974 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001975 }
Mike Stump11289f42009-09-09 15:08:12 +00001976
Douglas Gregora16548e2009-08-11 05:31:07 +00001977 /// \brief Build a new unary type trait expression.
1978 ///
1979 /// By default, performs semantic analysis to build the new expression.
1980 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001981 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001982 SourceLocation StartLoc,
1983 TypeSourceInfo *T,
1984 SourceLocation RParenLoc) {
1985 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001986 }
1987
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001988 /// \brief Build a new binary type trait expression.
1989 ///
1990 /// By default, performs semantic analysis to build the new expression.
1991 /// Subclasses may override this routine to provide different behavior.
1992 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1993 SourceLocation StartLoc,
1994 TypeSourceInfo *LhsT,
1995 TypeSourceInfo *RhsT,
1996 SourceLocation RParenLoc) {
1997 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1998 }
1999
John Wiegley6242b6a2011-04-28 00:16:57 +00002000 /// \brief Build a new array type trait expression.
2001 ///
2002 /// By default, performs semantic analysis to build the new expression.
2003 /// Subclasses may override this routine to provide different behavior.
2004 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2005 SourceLocation StartLoc,
2006 TypeSourceInfo *TSInfo,
2007 Expr *DimExpr,
2008 SourceLocation RParenLoc) {
2009 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2010 }
2011
John Wiegleyf9f65842011-04-25 06:54:41 +00002012 /// \brief Build a new expression trait expression.
2013 ///
2014 /// By default, performs semantic analysis to build the new expression.
2015 /// Subclasses may override this routine to provide different behavior.
2016 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2017 SourceLocation StartLoc,
2018 Expr *Queried,
2019 SourceLocation RParenLoc) {
2020 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2021 }
2022
Mike Stump11289f42009-09-09 15:08:12 +00002023 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002024 /// expression.
2025 ///
2026 /// By default, performs semantic analysis to build the new expression.
2027 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002028 ExprResult RebuildDependentScopeDeclRefExpr(
2029 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002030 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00002031 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002032 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002033 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002034
2035 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002036 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00002037 *TemplateArgs);
2038
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002039 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00002040 }
2041
2042 /// \brief Build a new template-id expression.
2043 ///
2044 /// By default, performs semantic analysis to build the new expression.
2045 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002046 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00002047 LookupResult &R,
2048 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00002049 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00002050 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002051 }
2052
2053 /// \brief Build a new object-construction expression.
2054 ///
2055 /// By default, performs semantic analysis to build the new expression.
2056 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002057 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002058 SourceLocation Loc,
2059 CXXConstructorDecl *Constructor,
2060 bool IsElidable,
2061 MultiExprArg Args,
2062 bool HadMultipleCandidates,
2063 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002064 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002065 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00002066 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002067 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002068 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002069 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002070
Douglas Gregordb121ba2009-12-14 16:27:04 +00002071 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00002072 move_arg(ConvertedArgs),
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002073 HadMultipleCandidates,
Chandler Carruth01718152010-10-25 08:47:36 +00002074 RequiresZeroInit, ConstructKind,
2075 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002076 }
2077
2078 /// \brief Build a new object-construction expression.
2079 ///
2080 /// By default, performs semantic analysis to build the new expression.
2081 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002082 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2083 SourceLocation LParenLoc,
2084 MultiExprArg Args,
2085 SourceLocation RParenLoc) {
2086 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002087 LParenLoc,
2088 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002089 RParenLoc);
2090 }
2091
2092 /// \brief Build a new object-construction expression.
2093 ///
2094 /// By default, performs semantic analysis to build the new expression.
2095 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002096 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2097 SourceLocation LParenLoc,
2098 MultiExprArg Args,
2099 SourceLocation RParenLoc) {
2100 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002101 LParenLoc,
2102 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002103 RParenLoc);
2104 }
Mike Stump11289f42009-09-09 15:08:12 +00002105
Douglas Gregora16548e2009-08-11 05:31:07 +00002106 /// \brief Build a new member reference expression.
2107 ///
2108 /// By default, performs semantic analysis to build the new expression.
2109 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002110 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002111 QualType BaseType,
2112 bool IsArrow,
2113 SourceLocation OperatorLoc,
2114 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00002115 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002116 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002117 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002118 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002119 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002120
John McCallb268a282010-08-23 23:25:46 +00002121 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002122 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00002123 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002124 MemberNameInfo,
2125 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002126 }
2127
John McCall10eae182009-11-30 22:42:35 +00002128 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002129 ///
2130 /// By default, performs semantic analysis to build the new expression.
2131 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002132 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00002133 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00002134 SourceLocation OperatorLoc,
2135 bool IsArrow,
Douglas Gregor0da1d432011-02-28 20:01:57 +00002136 NestedNameSpecifierLoc QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00002137 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00002138 LookupResult &R,
2139 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002140 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002141 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002142
John McCallb268a282010-08-23 23:25:46 +00002143 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002144 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00002145 SS, FirstQualifierInScope,
2146 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002147 }
Mike Stump11289f42009-09-09 15:08:12 +00002148
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002149 /// \brief Build a new noexcept expression.
2150 ///
2151 /// By default, performs semantic analysis to build the new expression.
2152 /// Subclasses may override this routine to provide different behavior.
2153 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2154 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2155 }
2156
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002157 /// \brief Build a new expression to compute the length of a parameter pack.
2158 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2159 SourceLocation PackLoc,
2160 SourceLocation RParenLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002161 llvm::Optional<unsigned> Length) {
2162 if (Length)
2163 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2164 OperatorLoc, Pack, PackLoc,
2165 RParenLoc, *Length);
2166
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002167 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2168 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002169 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002170 }
2171
Douglas Gregora16548e2009-08-11 05:31:07 +00002172 /// \brief Build a new Objective-C @encode expression.
2173 ///
2174 /// By default, performs semantic analysis to build the new expression.
2175 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002176 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002177 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002178 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002179 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002180 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002181 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002182
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002183 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002184 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002185 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002186 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002187 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002188 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002189 MultiExprArg Args,
2190 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002191 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2192 ReceiverTypeInfo->getType(),
2193 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002194 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002195 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002196 }
2197
2198 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002199 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002200 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002201 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002202 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002203 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002204 MultiExprArg Args,
2205 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002206 return SemaRef.BuildInstanceMessage(Receiver,
2207 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002208 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002209 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002210 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002211 }
2212
Douglas Gregord51d90d2010-04-26 20:11:03 +00002213 /// \brief Build a new Objective-C ivar reference expression.
2214 ///
2215 /// By default, performs semantic analysis to build the new expression.
2216 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002217 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002218 SourceLocation IvarLoc,
2219 bool IsArrow, bool IsFreeIvar) {
2220 // FIXME: We lose track of the IsFreeIvar bit.
2221 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002222 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002223 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2224 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002225 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002226 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002227 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002228 false);
John Wiegley01296292011-04-08 18:41:53 +00002229 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002230 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002231
Douglas Gregord51d90d2010-04-26 20:11:03 +00002232 if (Result.get())
2233 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002234
John Wiegley01296292011-04-08 18:41:53 +00002235 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002236 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002237 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002238 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002239 /*TemplateArgs=*/0);
2240 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002241
2242 /// \brief Build a new Objective-C property reference expression.
2243 ///
2244 /// By default, performs semantic analysis to build the new expression.
2245 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002246 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002247 ObjCPropertyDecl *Property,
2248 SourceLocation PropertyLoc) {
2249 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002250 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002251 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2252 Sema::LookupMemberName);
2253 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002254 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002255 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002256 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002257 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002258 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002259
Douglas Gregor9faee212010-04-26 20:47:02 +00002260 if (Result.get())
2261 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002262
John Wiegley01296292011-04-08 18:41:53 +00002263 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002264 /*FIXME:*/PropertyLoc, IsArrow,
2265 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002266 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002267 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002268 /*TemplateArgs=*/0);
2269 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002270
John McCallb7bd14f2010-12-02 01:19:52 +00002271 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002272 ///
2273 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002274 /// Subclasses may override this routine to provide different behavior.
2275 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2276 ObjCMethodDecl *Getter,
2277 ObjCMethodDecl *Setter,
2278 SourceLocation PropertyLoc) {
2279 // Since these expressions can only be value-dependent, we do not
2280 // need to perform semantic analysis again.
2281 return Owned(
2282 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2283 VK_LValue, OK_ObjCProperty,
2284 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002285 }
2286
Douglas Gregord51d90d2010-04-26 20:11:03 +00002287 /// \brief Build a new Objective-C "isa" expression.
2288 ///
2289 /// By default, performs semantic analysis to build the new expression.
2290 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002291 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002292 bool IsArrow) {
2293 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002294 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002295 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2296 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002297 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002298 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002299 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002300 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002301 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002302
Douglas Gregord51d90d2010-04-26 20:11:03 +00002303 if (Result.get())
2304 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002305
John Wiegley01296292011-04-08 18:41:53 +00002306 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002307 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002308 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002309 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002310 /*TemplateArgs=*/0);
2311 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002312
Douglas Gregora16548e2009-08-11 05:31:07 +00002313 /// \brief Build a new shuffle vector expression.
2314 ///
2315 /// By default, performs semantic analysis to build the new expression.
2316 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002317 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002318 MultiExprArg SubExprs,
2319 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002320 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002321 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002322 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2323 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2324 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2325 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002326
Douglas Gregora16548e2009-08-11 05:31:07 +00002327 // Build a reference to the __builtin_shufflevector builtin
2328 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley01296292011-04-08 18:41:53 +00002329 ExprResult Callee
2330 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2331 VK_LValue, BuiltinLoc));
2332 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2333 if (Callee.isInvalid())
2334 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002335
2336 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002337 unsigned NumSubExprs = SubExprs.size();
2338 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley01296292011-04-08 18:41:53 +00002339 ExprResult TheCall = SemaRef.Owned(
2340 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregora16548e2009-08-11 05:31:07 +00002341 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002342 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002343 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley01296292011-04-08 18:41:53 +00002344 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002345
Douglas Gregora16548e2009-08-11 05:31:07 +00002346 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002347 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002348 }
John McCall31f82722010-11-12 08:19:04 +00002349
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002350 /// \brief Build a new template argument pack expansion.
2351 ///
2352 /// By default, performs semantic analysis to build a new pack expansion
2353 /// for a template argument. Subclasses may override this routine to provide
2354 /// different behavior.
2355 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002356 SourceLocation EllipsisLoc,
2357 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002358 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002359 case TemplateArgument::Expression: {
2360 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002361 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2362 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002363 if (Result.isInvalid())
2364 return TemplateArgumentLoc();
2365
2366 return TemplateArgumentLoc(Result.get(), Result.get());
2367 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002368
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002369 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002370 return TemplateArgumentLoc(TemplateArgument(
2371 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002372 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002373 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002374 Pattern.getTemplateNameLoc(),
2375 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002376
2377 case TemplateArgument::Null:
2378 case TemplateArgument::Integral:
2379 case TemplateArgument::Declaration:
2380 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002381 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002382 llvm_unreachable("Pack expansion pattern has no parameter packs");
2383
2384 case TemplateArgument::Type:
2385 if (TypeSourceInfo *Expansion
2386 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002387 EllipsisLoc,
2388 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002389 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2390 Expansion);
2391 break;
2392 }
2393
2394 return TemplateArgumentLoc();
2395 }
2396
Douglas Gregor968f23a2011-01-03 19:31:53 +00002397 /// \brief Build a new expression pack expansion.
2398 ///
2399 /// By default, performs semantic analysis to build a new pack expansion
2400 /// for an expression. Subclasses may override this routine to provide
2401 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002402 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2403 llvm::Optional<unsigned> NumExpansions) {
2404 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002405 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002406
2407 /// \brief Build a new atomic operation expression.
2408 ///
2409 /// By default, performs semantic analysis to build the new expression.
2410 /// Subclasses may override this routine to provide different behavior.
2411 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2412 MultiExprArg SubExprs,
2413 QualType RetTy,
2414 AtomicExpr::AtomicOp Op,
2415 SourceLocation RParenLoc) {
2416 // Just create the expression; there is not any interesting semantic
2417 // analysis here because we can't actually build an AtomicExpr until
2418 // we are sure it is semantically sound.
2419 unsigned NumSubExprs = SubExprs.size();
2420 Expr **Subs = (Expr **)SubExprs.release();
2421 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2422 NumSubExprs, RetTy, Op,
2423 RParenLoc);
2424 }
2425
John McCall31f82722010-11-12 08:19:04 +00002426private:
Douglas Gregor14454802011-02-25 02:25:35 +00002427 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2428 QualType ObjectType,
2429 NamedDecl *FirstQualifierInScope,
2430 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002431
2432 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2433 QualType ObjectType,
2434 NamedDecl *FirstQualifierInScope,
2435 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002436};
Douglas Gregora16548e2009-08-11 05:31:07 +00002437
Douglas Gregorebe10102009-08-20 07:17:43 +00002438template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002439StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002440 if (!S)
2441 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002442
Douglas Gregorebe10102009-08-20 07:17:43 +00002443 switch (S->getStmtClass()) {
2444 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002445
Douglas Gregorebe10102009-08-20 07:17:43 +00002446 // Transform individual statement nodes
2447#define STMT(Node, Parent) \
2448 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002449#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002450#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002451#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002452
Douglas Gregorebe10102009-08-20 07:17:43 +00002453 // Transform expressions by calling TransformExpr.
2454#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002455#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002456#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002457#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002458 {
John McCalldadc5752010-08-24 06:29:42 +00002459 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002460 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002461 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002462
John McCallb268a282010-08-23 23:25:46 +00002463 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002464 }
Mike Stump11289f42009-09-09 15:08:12 +00002465 }
2466
John McCallc3007a22010-10-26 07:05:15 +00002467 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002468}
Mike Stump11289f42009-09-09 15:08:12 +00002469
2470
Douglas Gregore922c772009-08-04 22:27:00 +00002471template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002472ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002473 if (!E)
2474 return SemaRef.Owned(E);
2475
2476 switch (E->getStmtClass()) {
2477 case Stmt::NoStmtClass: break;
2478#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002479#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002480#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002481 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002482#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002483 }
2484
John McCallc3007a22010-10-26 07:05:15 +00002485 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002486}
2487
2488template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002489bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2490 unsigned NumInputs,
2491 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002492 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002493 bool *ArgChanged) {
2494 for (unsigned I = 0; I != NumInputs; ++I) {
2495 // If requested, drop call arguments that need to be dropped.
2496 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2497 if (ArgChanged)
2498 *ArgChanged = true;
2499
2500 break;
2501 }
2502
Douglas Gregor968f23a2011-01-03 19:31:53 +00002503 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2504 Expr *Pattern = Expansion->getPattern();
2505
Chris Lattner01cf8db2011-07-20 06:58:45 +00002506 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002507 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2508 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2509
2510 // Determine whether the set of unexpanded parameter packs can and should
2511 // be expanded.
2512 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002513 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002514 llvm::Optional<unsigned> OrigNumExpansions
2515 = Expansion->getNumExpansions();
2516 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002517 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2518 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002519 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002520 Expand, RetainExpansion,
2521 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002522 return true;
2523
2524 if (!Expand) {
2525 // The transform has determined that we should perform a simple
2526 // transformation on the pack expansion, producing another pack
2527 // expansion.
2528 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2529 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2530 if (OutPattern.isInvalid())
2531 return true;
2532
2533 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002534 Expansion->getEllipsisLoc(),
2535 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002536 if (Out.isInvalid())
2537 return true;
2538
2539 if (ArgChanged)
2540 *ArgChanged = true;
2541 Outputs.push_back(Out.get());
2542 continue;
2543 }
John McCall542e7c62011-07-06 07:30:07 +00002544
2545 // Record right away that the argument was changed. This needs
2546 // to happen even if the array expands to nothing.
2547 if (ArgChanged) *ArgChanged = true;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002548
2549 // The transform has determined that we should perform an elementwise
2550 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002551 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002552 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2553 ExprResult Out = getDerived().TransformExpr(Pattern);
2554 if (Out.isInvalid())
2555 return true;
2556
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002557 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002558 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2559 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002560 if (Out.isInvalid())
2561 return true;
2562 }
2563
Douglas Gregor968f23a2011-01-03 19:31:53 +00002564 Outputs.push_back(Out.get());
2565 }
2566
2567 continue;
2568 }
2569
Douglas Gregora3efea12011-01-03 19:04:46 +00002570 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2571 if (Result.isInvalid())
2572 return true;
2573
2574 if (Result.get() != Inputs[I] && ArgChanged)
2575 *ArgChanged = true;
2576
2577 Outputs.push_back(Result.get());
2578 }
2579
2580 return false;
2581}
2582
2583template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002584NestedNameSpecifierLoc
2585TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2586 NestedNameSpecifierLoc NNS,
2587 QualType ObjectType,
2588 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002589 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregor14454802011-02-25 02:25:35 +00002590 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2591 Qualifier = Qualifier.getPrefix())
2592 Qualifiers.push_back(Qualifier);
2593
2594 CXXScopeSpec SS;
2595 while (!Qualifiers.empty()) {
2596 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2597 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2598
2599 switch (QNNS->getKind()) {
2600 case NestedNameSpecifier::Identifier:
2601 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2602 *QNNS->getAsIdentifier(),
2603 Q.getLocalBeginLoc(),
2604 Q.getLocalEndLoc(),
2605 ObjectType, false, SS,
2606 FirstQualifierInScope, false))
2607 return NestedNameSpecifierLoc();
2608
2609 break;
2610
2611 case NestedNameSpecifier::Namespace: {
2612 NamespaceDecl *NS
2613 = cast_or_null<NamespaceDecl>(
2614 getDerived().TransformDecl(
2615 Q.getLocalBeginLoc(),
2616 QNNS->getAsNamespace()));
2617 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2618 break;
2619 }
2620
2621 case NestedNameSpecifier::NamespaceAlias: {
2622 NamespaceAliasDecl *Alias
2623 = cast_or_null<NamespaceAliasDecl>(
2624 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2625 QNNS->getAsNamespaceAlias()));
2626 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2627 Q.getLocalEndLoc());
2628 break;
2629 }
2630
2631 case NestedNameSpecifier::Global:
2632 // There is no meaningful transformation that one could perform on the
2633 // global scope.
2634 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2635 break;
2636
2637 case NestedNameSpecifier::TypeSpecWithTemplate:
2638 case NestedNameSpecifier::TypeSpec: {
2639 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2640 FirstQualifierInScope, SS);
2641
2642 if (!TL)
2643 return NestedNameSpecifierLoc();
2644
2645 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2646 (SemaRef.getLangOptions().CPlusPlus0x &&
2647 TL.getType()->isEnumeralType())) {
2648 assert(!TL.getType().hasLocalQualifiers() &&
2649 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00002650 if (TL.getType()->isEnumeralType())
2651 SemaRef.Diag(TL.getBeginLoc(),
2652 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00002653 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2654 Q.getLocalEndLoc());
2655 break;
2656 }
Richard Trieude756fb2011-05-07 01:36:37 +00002657 // If the nested-name-specifier is an invalid type def, don't emit an
2658 // error because a previous error should have already been emitted.
2659 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2660 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2661 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2662 << TL.getType() << SS.getRange();
2663 }
Douglas Gregor14454802011-02-25 02:25:35 +00002664 return NestedNameSpecifierLoc();
2665 }
Douglas Gregore16af532011-02-28 18:50:33 +00002666 }
Douglas Gregor14454802011-02-25 02:25:35 +00002667
Douglas Gregore16af532011-02-28 18:50:33 +00002668 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002669 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002670 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002671 }
2672
2673 // Don't rebuild the nested-name-specifier if we don't have to.
2674 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2675 !getDerived().AlwaysRebuild())
2676 return NNS;
2677
2678 // If we can re-use the source-location data from the original
2679 // nested-name-specifier, do so.
2680 if (SS.location_size() == NNS.getDataLength() &&
2681 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2682 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2683
2684 // Allocate new nested-name-specifier location information.
2685 return SS.getWithLocInContext(SemaRef.Context);
2686}
2687
2688template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002689DeclarationNameInfo
2690TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002691::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002692 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002693 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002694 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002695
2696 switch (Name.getNameKind()) {
2697 case DeclarationName::Identifier:
2698 case DeclarationName::ObjCZeroArgSelector:
2699 case DeclarationName::ObjCOneArgSelector:
2700 case DeclarationName::ObjCMultiArgSelector:
2701 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002702 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002703 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002704 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002705
Douglas Gregorf816bd72009-09-03 22:13:48 +00002706 case DeclarationName::CXXConstructorName:
2707 case DeclarationName::CXXDestructorName:
2708 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002709 TypeSourceInfo *NewTInfo;
2710 CanQualType NewCanTy;
2711 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002712 NewTInfo = getDerived().TransformType(OldTInfo);
2713 if (!NewTInfo)
2714 return DeclarationNameInfo();
2715 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002716 }
2717 else {
2718 NewTInfo = 0;
2719 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002720 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002721 if (NewT.isNull())
2722 return DeclarationNameInfo();
2723 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2724 }
Mike Stump11289f42009-09-09 15:08:12 +00002725
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002726 DeclarationName NewName
2727 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2728 NewCanTy);
2729 DeclarationNameInfo NewNameInfo(NameInfo);
2730 NewNameInfo.setName(NewName);
2731 NewNameInfo.setNamedTypeInfo(NewTInfo);
2732 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002733 }
Mike Stump11289f42009-09-09 15:08:12 +00002734 }
2735
David Blaikie83d382b2011-09-23 05:06:16 +00002736 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00002737}
2738
2739template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002740TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00002741TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2742 TemplateName Name,
2743 SourceLocation NameLoc,
2744 QualType ObjectType,
2745 NamedDecl *FirstQualifierInScope) {
2746 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2747 TemplateDecl *Template = QTN->getTemplateDecl();
2748 assert(Template && "qualified template name must refer to a template");
2749
2750 TemplateDecl *TransTemplate
2751 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2752 Template));
2753 if (!TransTemplate)
2754 return TemplateName();
2755
2756 if (!getDerived().AlwaysRebuild() &&
2757 SS.getScopeRep() == QTN->getQualifier() &&
2758 TransTemplate == Template)
2759 return Name;
2760
2761 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2762 TransTemplate);
2763 }
2764
2765 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2766 if (SS.getScopeRep()) {
2767 // These apply to the scope specifier, not the template.
2768 ObjectType = QualType();
2769 FirstQualifierInScope = 0;
2770 }
2771
2772 if (!getDerived().AlwaysRebuild() &&
2773 SS.getScopeRep() == DTN->getQualifier() &&
2774 ObjectType.isNull())
2775 return Name;
2776
2777 if (DTN->isIdentifier()) {
2778 return getDerived().RebuildTemplateName(SS,
2779 *DTN->getIdentifier(),
2780 NameLoc,
2781 ObjectType,
2782 FirstQualifierInScope);
2783 }
2784
2785 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2786 ObjectType);
2787 }
2788
2789 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2790 TemplateDecl *TransTemplate
2791 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2792 Template));
2793 if (!TransTemplate)
2794 return TemplateName();
2795
2796 if (!getDerived().AlwaysRebuild() &&
2797 TransTemplate == Template)
2798 return Name;
2799
2800 return TemplateName(TransTemplate);
2801 }
2802
2803 if (SubstTemplateTemplateParmPackStorage *SubstPack
2804 = Name.getAsSubstTemplateTemplateParmPack()) {
2805 TemplateTemplateParmDecl *TransParam
2806 = cast_or_null<TemplateTemplateParmDecl>(
2807 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2808 if (!TransParam)
2809 return TemplateName();
2810
2811 if (!getDerived().AlwaysRebuild() &&
2812 TransParam == SubstPack->getParameterPack())
2813 return Name;
2814
2815 return getDerived().RebuildTemplateName(TransParam,
2816 SubstPack->getArgumentPack());
2817 }
2818
2819 // These should be getting filtered out before they reach the AST.
2820 llvm_unreachable("overloaded function decl survived to here");
2821 return TemplateName();
2822}
2823
2824template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002825void TreeTransform<Derived>::InventTemplateArgumentLoc(
2826 const TemplateArgument &Arg,
2827 TemplateArgumentLoc &Output) {
2828 SourceLocation Loc = getDerived().getBaseLocation();
2829 switch (Arg.getKind()) {
2830 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002831 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002832 break;
2833
2834 case TemplateArgument::Type:
2835 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002836 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002837
John McCall0ad16662009-10-29 08:12:44 +00002838 break;
2839
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002840 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00002841 case TemplateArgument::TemplateExpansion: {
2842 NestedNameSpecifierLocBuilder Builder;
2843 TemplateName Template = Arg.getAsTemplate();
2844 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2845 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2846 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2847 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2848
2849 if (Arg.getKind() == TemplateArgument::Template)
2850 Output = TemplateArgumentLoc(Arg,
2851 Builder.getWithLocInContext(SemaRef.Context),
2852 Loc);
2853 else
2854 Output = TemplateArgumentLoc(Arg,
2855 Builder.getWithLocInContext(SemaRef.Context),
2856 Loc, Loc);
2857
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002858 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00002859 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002860
John McCall0ad16662009-10-29 08:12:44 +00002861 case TemplateArgument::Expression:
2862 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2863 break;
2864
2865 case TemplateArgument::Declaration:
2866 case TemplateArgument::Integral:
2867 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002868 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002869 break;
2870 }
2871}
2872
2873template<typename Derived>
2874bool TreeTransform<Derived>::TransformTemplateArgument(
2875 const TemplateArgumentLoc &Input,
2876 TemplateArgumentLoc &Output) {
2877 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002878 switch (Arg.getKind()) {
2879 case TemplateArgument::Null:
2880 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002881 Output = Input;
2882 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002883
Douglas Gregore922c772009-08-04 22:27:00 +00002884 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002885 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002886 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002887 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002888
2889 DI = getDerived().TransformType(DI);
2890 if (!DI) return true;
2891
2892 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2893 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002894 }
Mike Stump11289f42009-09-09 15:08:12 +00002895
Douglas Gregore922c772009-08-04 22:27:00 +00002896 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002897 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002898 DeclarationName Name;
2899 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2900 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002901 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002902 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002903 if (!D) return true;
2904
John McCall0d07eb32009-10-29 18:45:58 +00002905 Expr *SourceExpr = Input.getSourceDeclExpression();
2906 if (SourceExpr) {
2907 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002908 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002909 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002910 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002911 }
2912
2913 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002914 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002915 }
Mike Stump11289f42009-09-09 15:08:12 +00002916
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002917 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00002918 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2919 if (QualifierLoc) {
2920 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2921 if (!QualifierLoc)
2922 return true;
2923 }
2924
Douglas Gregordf846d12011-03-02 18:46:51 +00002925 CXXScopeSpec SS;
2926 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002927 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00002928 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2929 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002930 if (Template.isNull())
2931 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002932
Douglas Gregor9d802122011-03-02 17:09:35 +00002933 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002934 Input.getTemplateNameLoc());
2935 return false;
2936 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002937
2938 case TemplateArgument::TemplateExpansion:
2939 llvm_unreachable("Caller should expand pack expansions");
2940
Douglas Gregore922c772009-08-04 22:27:00 +00002941 case TemplateArgument::Expression: {
2942 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002943 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002944 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002945
John McCall0ad16662009-10-29 08:12:44 +00002946 Expr *InputExpr = Input.getSourceExpression();
2947 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2948
Chris Lattnercdb591a2011-04-25 20:37:58 +00002949 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall0ad16662009-10-29 08:12:44 +00002950 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002951 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002952 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002953 }
Mike Stump11289f42009-09-09 15:08:12 +00002954
Douglas Gregore922c772009-08-04 22:27:00 +00002955 case TemplateArgument::Pack: {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002956 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregore922c772009-08-04 22:27:00 +00002957 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002958 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002959 AEnd = Arg.pack_end();
2960 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002961
John McCall0ad16662009-10-29 08:12:44 +00002962 // FIXME: preserve source information here when we start
2963 // caring about parameter packs.
2964
John McCall0d07eb32009-10-29 18:45:58 +00002965 TemplateArgumentLoc InputArg;
2966 TemplateArgumentLoc OutputArg;
2967 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2968 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002969 return true;
2970
John McCall0d07eb32009-10-29 18:45:58 +00002971 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002972 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002973
2974 TemplateArgument *TransformedArgsPtr
2975 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2976 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2977 TransformedArgsPtr);
2978 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2979 TransformedArgs.size()),
2980 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002981 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002982 }
2983 }
Mike Stump11289f42009-09-09 15:08:12 +00002984
Douglas Gregore922c772009-08-04 22:27:00 +00002985 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002986 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002987}
2988
Douglas Gregorfe921a72010-12-20 23:36:19 +00002989/// \brief Iterator adaptor that invents template argument location information
2990/// for each of the template arguments in its underlying iterator.
2991template<typename Derived, typename InputIterator>
2992class TemplateArgumentLocInventIterator {
2993 TreeTransform<Derived> &Self;
2994 InputIterator Iter;
2995
2996public:
2997 typedef TemplateArgumentLoc value_type;
2998 typedef TemplateArgumentLoc reference;
2999 typedef typename std::iterator_traits<InputIterator>::difference_type
3000 difference_type;
3001 typedef std::input_iterator_tag iterator_category;
3002
3003 class pointer {
3004 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003005
Douglas Gregorfe921a72010-12-20 23:36:19 +00003006 public:
3007 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3008
3009 const TemplateArgumentLoc *operator->() const { return &Arg; }
3010 };
3011
3012 TemplateArgumentLocInventIterator() { }
3013
3014 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3015 InputIterator Iter)
3016 : Self(Self), Iter(Iter) { }
3017
3018 TemplateArgumentLocInventIterator &operator++() {
3019 ++Iter;
3020 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003021 }
3022
Douglas Gregorfe921a72010-12-20 23:36:19 +00003023 TemplateArgumentLocInventIterator operator++(int) {
3024 TemplateArgumentLocInventIterator Old(*this);
3025 ++(*this);
3026 return Old;
3027 }
3028
3029 reference operator*() const {
3030 TemplateArgumentLoc Result;
3031 Self.InventTemplateArgumentLoc(*Iter, Result);
3032 return Result;
3033 }
3034
3035 pointer operator->() const { return pointer(**this); }
3036
3037 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3038 const TemplateArgumentLocInventIterator &Y) {
3039 return X.Iter == Y.Iter;
3040 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003041
Douglas Gregorfe921a72010-12-20 23:36:19 +00003042 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3043 const TemplateArgumentLocInventIterator &Y) {
3044 return X.Iter != Y.Iter;
3045 }
3046};
3047
Douglas Gregor42cafa82010-12-20 17:42:22 +00003048template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003049template<typename InputIterator>
3050bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3051 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003052 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003053 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003054 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003055 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003056
3057 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3058 // Unpack argument packs, which we translate them into separate
3059 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003060 // FIXME: We could do much better if we could guarantee that the
3061 // TemplateArgumentLocInfo for the pack expansion would be usable for
3062 // all of the template arguments in the argument pack.
3063 typedef TemplateArgumentLocInventIterator<Derived,
3064 TemplateArgument::pack_iterator>
3065 PackLocIterator;
3066 if (TransformTemplateArguments(PackLocIterator(*this,
3067 In.getArgument().pack_begin()),
3068 PackLocIterator(*this,
3069 In.getArgument().pack_end()),
3070 Outputs))
3071 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003072
3073 continue;
3074 }
3075
3076 if (In.getArgument().isPackExpansion()) {
3077 // We have a pack expansion, for which we will be substituting into
3078 // the pattern.
3079 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003080 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003081 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003082 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3083 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003084
Chris Lattner01cf8db2011-07-20 06:58:45 +00003085 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003086 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3087 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3088
3089 // Determine whether the set of unexpanded parameter packs can and should
3090 // be expanded.
3091 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003092 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003093 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003094 if (getDerived().TryExpandParameterPacks(Ellipsis,
3095 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003096 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003097 Expand,
3098 RetainExpansion,
3099 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003100 return true;
3101
3102 if (!Expand) {
3103 // The transform has determined that we should perform a simple
3104 // transformation on the pack expansion, producing another pack
3105 // expansion.
3106 TemplateArgumentLoc OutPattern;
3107 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3108 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3109 return true;
3110
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003111 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3112 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003113 if (Out.getArgument().isNull())
3114 return true;
3115
3116 Outputs.addArgument(Out);
3117 continue;
3118 }
3119
3120 // The transform has determined that we should perform an elementwise
3121 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003122 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003123 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3124
3125 if (getDerived().TransformTemplateArgument(Pattern, Out))
3126 return true;
3127
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003128 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003129 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3130 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003131 if (Out.getArgument().isNull())
3132 return true;
3133 }
3134
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003135 Outputs.addArgument(Out);
3136 }
3137
Douglas Gregor48d24112011-01-10 20:53:55 +00003138 // If we're supposed to retain a pack expansion, do so by temporarily
3139 // forgetting the partially-substituted parameter pack.
3140 if (RetainExpansion) {
3141 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3142
3143 if (getDerived().TransformTemplateArgument(Pattern, Out))
3144 return true;
3145
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003146 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3147 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003148 if (Out.getArgument().isNull())
3149 return true;
3150
3151 Outputs.addArgument(Out);
3152 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003153
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003154 continue;
3155 }
3156
3157 // The simple case:
3158 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003159 return true;
3160
3161 Outputs.addArgument(Out);
3162 }
3163
3164 return false;
3165
3166}
3167
Douglas Gregord6ff3322009-08-04 16:50:30 +00003168//===----------------------------------------------------------------------===//
3169// Type transformation
3170//===----------------------------------------------------------------------===//
3171
3172template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003173QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003174 if (getDerived().AlreadyTransformed(T))
3175 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003176
John McCall550e0c22009-10-21 00:40:46 +00003177 // Temporary workaround. All of these transformations should
3178 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003179 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3180 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003181
John McCall31f82722010-11-12 08:19:04 +00003182 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003183
John McCall550e0c22009-10-21 00:40:46 +00003184 if (!NewDI)
3185 return QualType();
3186
3187 return NewDI->getType();
3188}
3189
3190template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003191TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003192 if (getDerived().AlreadyTransformed(DI->getType()))
3193 return DI;
3194
3195 TypeLocBuilder TLB;
3196
3197 TypeLoc TL = DI->getTypeLoc();
3198 TLB.reserve(TL.getFullDataSize());
3199
John McCall31f82722010-11-12 08:19:04 +00003200 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003201 if (Result.isNull())
3202 return 0;
3203
John McCallbcd03502009-12-07 02:54:59 +00003204 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003205}
3206
3207template<typename Derived>
3208QualType
John McCall31f82722010-11-12 08:19:04 +00003209TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003210 switch (T.getTypeLocClass()) {
3211#define ABSTRACT_TYPELOC(CLASS, PARENT)
3212#define TYPELOC(CLASS, PARENT) \
3213 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003214 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003215#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003216 }
Mike Stump11289f42009-09-09 15:08:12 +00003217
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003218 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003219 return QualType();
3220}
3221
3222/// FIXME: By default, this routine adds type qualifiers only to types
3223/// that can have qualifiers, and silently suppresses those qualifiers
3224/// that are not permitted (e.g., qualifiers on reference or function
3225/// types). This is the right thing for template instantiation, but
3226/// probably not for other clients.
3227template<typename Derived>
3228QualType
3229TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003230 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003231 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003232
John McCall31f82722010-11-12 08:19:04 +00003233 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003234 if (Result.isNull())
3235 return QualType();
3236
3237 // Silently suppress qualifiers if the result type can't be qualified.
3238 // FIXME: this is the right thing for template instantiation, but
3239 // probably not for other clients.
3240 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003241 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003242
John McCall31168b02011-06-15 23:02:42 +00003243 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003244 // resulting type.
3245 if (Quals.hasObjCLifetime()) {
3246 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3247 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003248 else if (Result.getObjCLifetime()) {
Douglas Gregore46db902011-06-17 22:11:49 +00003249 // Objective-C ARC:
3250 // A lifetime qualifier applied to a substituted template parameter
3251 // overrides the lifetime qualifier from the template argument.
3252 if (const SubstTemplateTypeParmType *SubstTypeParam
3253 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3254 QualType Replacement = SubstTypeParam->getReplacementType();
3255 Qualifiers Qs = Replacement.getQualifiers();
3256 Qs.removeObjCLifetime();
3257 Replacement
3258 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3259 Qs);
3260 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3261 SubstTypeParam->getReplacedParameter(),
3262 Replacement);
3263 TLB.TypeWasModifiedSafely(Result);
3264 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003265 // Otherwise, complain about the addition of a qualifier to an
3266 // already-qualified type.
3267 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003268 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003269 << Result << R;
3270
Douglas Gregore46db902011-06-17 22:11:49 +00003271 Quals.removeObjCLifetime();
3272 }
3273 }
3274 }
John McCallcb0f89a2010-06-05 06:41:15 +00003275 if (!Quals.empty()) {
3276 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3277 TLB.push<QualifiedTypeLoc>(Result);
3278 // No location information to preserve.
3279 }
John McCall550e0c22009-10-21 00:40:46 +00003280
3281 return Result;
3282}
3283
Douglas Gregor14454802011-02-25 02:25:35 +00003284template<typename Derived>
3285TypeLoc
3286TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3287 QualType ObjectType,
3288 NamedDecl *UnqualLookup,
3289 CXXScopeSpec &SS) {
Douglas Gregor14454802011-02-25 02:25:35 +00003290 QualType T = TL.getType();
3291 if (getDerived().AlreadyTransformed(T))
3292 return TL;
3293
3294 TypeLocBuilder TLB;
3295 QualType Result;
3296
3297 if (isa<TemplateSpecializationType>(T)) {
3298 TemplateSpecializationTypeLoc SpecTL
3299 = cast<TemplateSpecializationTypeLoc>(TL);
3300
3301 TemplateName Template =
Douglas Gregor9db53502011-03-02 18:07:45 +00003302 getDerived().TransformTemplateName(SS,
3303 SpecTL.getTypePtr()->getTemplateName(),
3304 SpecTL.getTemplateNameLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003305 ObjectType, UnqualLookup);
3306 if (Template.isNull())
3307 return TypeLoc();
3308
3309 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3310 Template);
3311 } else if (isa<DependentTemplateSpecializationType>(T)) {
3312 DependentTemplateSpecializationTypeLoc SpecTL
3313 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3314
Douglas Gregor5a064722011-02-28 17:23:35 +00003315 TemplateName Template
Douglas Gregor9db53502011-03-02 18:07:45 +00003316 = getDerived().RebuildTemplateName(SS,
Douglas Gregore16af532011-02-28 18:50:33 +00003317 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003318 SpecTL.getNameLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00003319 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003320 if (Template.isNull())
3321 return TypeLoc();
3322
Douglas Gregor14454802011-02-25 02:25:35 +00003323 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003324 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003325 Template,
3326 SS);
Douglas Gregor14454802011-02-25 02:25:35 +00003327 } else {
3328 // Nothing special needs to be done for these.
3329 Result = getDerived().TransformType(TLB, TL);
3330 }
3331
3332 if (Result.isNull())
3333 return TypeLoc();
3334
3335 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3336}
3337
Douglas Gregor579c15f2011-03-02 18:32:08 +00003338template<typename Derived>
3339TypeSourceInfo *
3340TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3341 QualType ObjectType,
3342 NamedDecl *UnqualLookup,
3343 CXXScopeSpec &SS) {
3344 // FIXME: Painfully copy-paste from the above!
3345
3346 QualType T = TSInfo->getType();
3347 if (getDerived().AlreadyTransformed(T))
3348 return TSInfo;
3349
3350 TypeLocBuilder TLB;
3351 QualType Result;
3352
3353 TypeLoc TL = TSInfo->getTypeLoc();
3354 if (isa<TemplateSpecializationType>(T)) {
3355 TemplateSpecializationTypeLoc SpecTL
3356 = cast<TemplateSpecializationTypeLoc>(TL);
3357
3358 TemplateName Template
3359 = getDerived().TransformTemplateName(SS,
3360 SpecTL.getTypePtr()->getTemplateName(),
3361 SpecTL.getTemplateNameLoc(),
3362 ObjectType, UnqualLookup);
3363 if (Template.isNull())
3364 return 0;
3365
3366 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3367 Template);
3368 } else if (isa<DependentTemplateSpecializationType>(T)) {
3369 DependentTemplateSpecializationTypeLoc SpecTL
3370 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3371
3372 TemplateName Template
3373 = getDerived().RebuildTemplateName(SS,
3374 *SpecTL.getTypePtr()->getIdentifier(),
3375 SpecTL.getNameLoc(),
3376 ObjectType, UnqualLookup);
3377 if (Template.isNull())
3378 return 0;
3379
3380 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3381 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003382 Template,
3383 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003384 } else {
3385 // Nothing special needs to be done for these.
3386 Result = getDerived().TransformType(TLB, TL);
3387 }
3388
3389 if (Result.isNull())
3390 return 0;
3391
3392 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3393}
3394
John McCall550e0c22009-10-21 00:40:46 +00003395template <class TyLoc> static inline
3396QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3397 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3398 NewT.setNameLoc(T.getNameLoc());
3399 return T.getType();
3400}
3401
John McCall550e0c22009-10-21 00:40:46 +00003402template<typename Derived>
3403QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003404 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003405 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3406 NewT.setBuiltinLoc(T.getBuiltinLoc());
3407 if (T.needsExtraLocalData())
3408 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3409 return T.getType();
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>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003414 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003415 // FIXME: recurse?
3416 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003417}
Mike Stump11289f42009-09-09 15:08:12 +00003418
Douglas Gregord6ff3322009-08-04 16:50:30 +00003419template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003420QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003421 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003422 QualType PointeeType
3423 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003424 if (PointeeType.isNull())
3425 return QualType();
3426
3427 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003428 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003429 // A dependent pointer type 'T *' has is being transformed such
3430 // that an Objective-C class type is being replaced for 'T'. The
3431 // resulting pointer type is an ObjCObjectPointerType, not a
3432 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003433 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003434
John McCall8b07ec22010-05-15 11:32:37 +00003435 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3436 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003437 return Result;
3438 }
John McCall31f82722010-11-12 08:19:04 +00003439
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003440 if (getDerived().AlwaysRebuild() ||
3441 PointeeType != TL.getPointeeLoc().getType()) {
3442 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3443 if (Result.isNull())
3444 return QualType();
3445 }
John McCall31168b02011-06-15 23:02:42 +00003446
3447 // Objective-C ARC can add lifetime qualifiers to the type that we're
3448 // pointing to.
3449 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3450
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003451 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3452 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003453 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003454}
Mike Stump11289f42009-09-09 15:08:12 +00003455
3456template<typename Derived>
3457QualType
John McCall550e0c22009-10-21 00:40:46 +00003458TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003459 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003460 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003461 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3462 if (PointeeType.isNull())
3463 return QualType();
3464
3465 QualType Result = TL.getType();
3466 if (getDerived().AlwaysRebuild() ||
3467 PointeeType != TL.getPointeeLoc().getType()) {
3468 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003469 TL.getSigilLoc());
3470 if (Result.isNull())
3471 return QualType();
3472 }
3473
Douglas Gregor049211a2010-04-22 16:50:51 +00003474 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003475 NewT.setSigilLoc(TL.getSigilLoc());
3476 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003477}
3478
John McCall70dd5f62009-10-30 00:06:24 +00003479/// Transforms a reference type. Note that somewhat paradoxically we
3480/// don't care whether the type itself is an l-value type or an r-value
3481/// type; we only care if the type was *written* as an l-value type
3482/// or an r-value type.
3483template<typename Derived>
3484QualType
3485TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003486 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003487 const ReferenceType *T = TL.getTypePtr();
3488
3489 // Note that this works with the pointee-as-written.
3490 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3491 if (PointeeType.isNull())
3492 return QualType();
3493
3494 QualType Result = TL.getType();
3495 if (getDerived().AlwaysRebuild() ||
3496 PointeeType != T->getPointeeTypeAsWritten()) {
3497 Result = getDerived().RebuildReferenceType(PointeeType,
3498 T->isSpelledAsLValue(),
3499 TL.getSigilLoc());
3500 if (Result.isNull())
3501 return QualType();
3502 }
3503
John McCall31168b02011-06-15 23:02:42 +00003504 // Objective-C ARC can add lifetime qualifiers to the type that we're
3505 // referring to.
3506 TLB.TypeWasModifiedSafely(
3507 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3508
John McCall70dd5f62009-10-30 00:06:24 +00003509 // r-value references can be rebuilt as l-value references.
3510 ReferenceTypeLoc NewTL;
3511 if (isa<LValueReferenceType>(Result))
3512 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3513 else
3514 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3515 NewTL.setSigilLoc(TL.getSigilLoc());
3516
3517 return Result;
3518}
3519
Mike Stump11289f42009-09-09 15:08:12 +00003520template<typename Derived>
3521QualType
John McCall550e0c22009-10-21 00:40:46 +00003522TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003523 LValueReferenceTypeLoc TL) {
3524 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003525}
3526
Mike Stump11289f42009-09-09 15:08:12 +00003527template<typename Derived>
3528QualType
John McCall550e0c22009-10-21 00:40:46 +00003529TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003530 RValueReferenceTypeLoc TL) {
3531 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003532}
Mike Stump11289f42009-09-09 15:08:12 +00003533
Douglas Gregord6ff3322009-08-04 16:50:30 +00003534template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003535QualType
John McCall550e0c22009-10-21 00:40:46 +00003536TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003537 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003538 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003539 if (PointeeType.isNull())
3540 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003541
Abramo Bagnara509357842011-03-05 14:42:21 +00003542 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3543 TypeSourceInfo* NewClsTInfo = 0;
3544 if (OldClsTInfo) {
3545 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3546 if (!NewClsTInfo)
3547 return QualType();
3548 }
3549
3550 const MemberPointerType *T = TL.getTypePtr();
3551 QualType OldClsType = QualType(T->getClass(), 0);
3552 QualType NewClsType;
3553 if (NewClsTInfo)
3554 NewClsType = NewClsTInfo->getType();
3555 else {
3556 NewClsType = getDerived().TransformType(OldClsType);
3557 if (NewClsType.isNull())
3558 return QualType();
3559 }
Mike Stump11289f42009-09-09 15:08:12 +00003560
John McCall550e0c22009-10-21 00:40:46 +00003561 QualType Result = TL.getType();
3562 if (getDerived().AlwaysRebuild() ||
3563 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003564 NewClsType != OldClsType) {
3565 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003566 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003567 if (Result.isNull())
3568 return QualType();
3569 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003570
John McCall550e0c22009-10-21 00:40:46 +00003571 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3572 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003573 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003574
3575 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003576}
3577
Mike Stump11289f42009-09-09 15:08:12 +00003578template<typename Derived>
3579QualType
John McCall550e0c22009-10-21 00:40:46 +00003580TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003581 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003582 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003583 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003584 if (ElementType.isNull())
3585 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003586
John McCall550e0c22009-10-21 00:40:46 +00003587 QualType Result = TL.getType();
3588 if (getDerived().AlwaysRebuild() ||
3589 ElementType != T->getElementType()) {
3590 Result = getDerived().RebuildConstantArrayType(ElementType,
3591 T->getSizeModifier(),
3592 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003593 T->getIndexTypeCVRQualifiers(),
3594 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003595 if (Result.isNull())
3596 return QualType();
3597 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003598
John McCall550e0c22009-10-21 00:40:46 +00003599 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3600 NewTL.setLBracketLoc(TL.getLBracketLoc());
3601 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003602
John McCall550e0c22009-10-21 00:40:46 +00003603 Expr *Size = TL.getSizeExpr();
3604 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003605 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003606 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3607 }
3608 NewTL.setSizeExpr(Size);
3609
3610 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003611}
Mike Stump11289f42009-09-09 15:08:12 +00003612
Douglas Gregord6ff3322009-08-04 16:50:30 +00003613template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003614QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003615 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003616 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003617 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003618 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003619 if (ElementType.isNull())
3620 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003621
John McCall550e0c22009-10-21 00:40:46 +00003622 QualType Result = TL.getType();
3623 if (getDerived().AlwaysRebuild() ||
3624 ElementType != T->getElementType()) {
3625 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003626 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003627 T->getIndexTypeCVRQualifiers(),
3628 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003629 if (Result.isNull())
3630 return QualType();
3631 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003632
John McCall550e0c22009-10-21 00:40:46 +00003633 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3634 NewTL.setLBracketLoc(TL.getLBracketLoc());
3635 NewTL.setRBracketLoc(TL.getRBracketLoc());
3636 NewTL.setSizeExpr(0);
3637
3638 return Result;
3639}
3640
3641template<typename Derived>
3642QualType
3643TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003644 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003645 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003646 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3647 if (ElementType.isNull())
3648 return QualType();
3649
3650 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003651 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003652
John McCalldadc5752010-08-24 06:29:42 +00003653 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003654 = getDerived().TransformExpr(T->getSizeExpr());
3655 if (SizeResult.isInvalid())
3656 return QualType();
3657
John McCallb268a282010-08-23 23:25:46 +00003658 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003659
3660 QualType Result = TL.getType();
3661 if (getDerived().AlwaysRebuild() ||
3662 ElementType != T->getElementType() ||
3663 Size != T->getSizeExpr()) {
3664 Result = getDerived().RebuildVariableArrayType(ElementType,
3665 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003666 Size,
John McCall550e0c22009-10-21 00:40:46 +00003667 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003668 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003669 if (Result.isNull())
3670 return QualType();
3671 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003672
John McCall550e0c22009-10-21 00:40:46 +00003673 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3674 NewTL.setLBracketLoc(TL.getLBracketLoc());
3675 NewTL.setRBracketLoc(TL.getRBracketLoc());
3676 NewTL.setSizeExpr(Size);
3677
3678 return Result;
3679}
3680
3681template<typename Derived>
3682QualType
3683TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003684 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003685 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003686 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3687 if (ElementType.isNull())
3688 return QualType();
3689
3690 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003691 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003692
John McCall33ddac02011-01-19 10:06:00 +00003693 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3694 Expr *origSize = TL.getSizeExpr();
3695 if (!origSize) origSize = T->getSizeExpr();
3696
3697 ExprResult sizeResult
3698 = getDerived().TransformExpr(origSize);
3699 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003700 return QualType();
3701
John McCall33ddac02011-01-19 10:06:00 +00003702 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003703
3704 QualType Result = TL.getType();
3705 if (getDerived().AlwaysRebuild() ||
3706 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003707 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003708 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3709 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003710 size,
John McCall550e0c22009-10-21 00:40:46 +00003711 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003712 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003713 if (Result.isNull())
3714 return QualType();
3715 }
John McCall550e0c22009-10-21 00:40:46 +00003716
3717 // We might have any sort of array type now, but fortunately they
3718 // all have the same location layout.
3719 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3720 NewTL.setLBracketLoc(TL.getLBracketLoc());
3721 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003722 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003723
3724 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003725}
Mike Stump11289f42009-09-09 15:08:12 +00003726
3727template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003728QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003729 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003730 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003731 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003732
3733 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003734 QualType ElementType = getDerived().TransformType(T->getElementType());
3735 if (ElementType.isNull())
3736 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003737
Douglas Gregore922c772009-08-04 22:27:00 +00003738 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003739 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003740
John McCalldadc5752010-08-24 06:29:42 +00003741 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003742 if (Size.isInvalid())
3743 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003744
John McCall550e0c22009-10-21 00:40:46 +00003745 QualType Result = TL.getType();
3746 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003747 ElementType != T->getElementType() ||
3748 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003749 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003750 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003751 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003752 if (Result.isNull())
3753 return QualType();
3754 }
John McCall550e0c22009-10-21 00:40:46 +00003755
3756 // Result might be dependent or not.
3757 if (isa<DependentSizedExtVectorType>(Result)) {
3758 DependentSizedExtVectorTypeLoc NewTL
3759 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3760 NewTL.setNameLoc(TL.getNameLoc());
3761 } else {
3762 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3763 NewTL.setNameLoc(TL.getNameLoc());
3764 }
3765
3766 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003767}
Mike Stump11289f42009-09-09 15:08:12 +00003768
3769template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003770QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003771 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003772 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003773 QualType ElementType = getDerived().TransformType(T->getElementType());
3774 if (ElementType.isNull())
3775 return QualType();
3776
John McCall550e0c22009-10-21 00:40:46 +00003777 QualType Result = TL.getType();
3778 if (getDerived().AlwaysRebuild() ||
3779 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003780 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003781 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003782 if (Result.isNull())
3783 return QualType();
3784 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003785
John McCall550e0c22009-10-21 00:40:46 +00003786 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3787 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003788
John McCall550e0c22009-10-21 00:40:46 +00003789 return Result;
3790}
3791
3792template<typename Derived>
3793QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003794 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003795 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003796 QualType ElementType = getDerived().TransformType(T->getElementType());
3797 if (ElementType.isNull())
3798 return QualType();
3799
3800 QualType Result = TL.getType();
3801 if (getDerived().AlwaysRebuild() ||
3802 ElementType != T->getElementType()) {
3803 Result = getDerived().RebuildExtVectorType(ElementType,
3804 T->getNumElements(),
3805 /*FIXME*/ SourceLocation());
3806 if (Result.isNull())
3807 return QualType();
3808 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003809
John McCall550e0c22009-10-21 00:40:46 +00003810 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3811 NewTL.setNameLoc(TL.getNameLoc());
3812
3813 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003814}
Mike Stump11289f42009-09-09 15:08:12 +00003815
3816template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003817ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003818TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003819 int indexAdjustment,
Douglas Gregor715e4612011-01-14 22:40:04 +00003820 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003821 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003822 TypeSourceInfo *NewDI = 0;
3823
3824 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3825 // If we're substituting into a pack expansion type and we know the
3826 TypeLoc OldTL = OldDI->getTypeLoc();
3827 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3828
3829 TypeLocBuilder TLB;
3830 TypeLoc NewTL = OldDI->getTypeLoc();
3831 TLB.reserve(NewTL.getFullDataSize());
3832
3833 QualType Result = getDerived().TransformType(TLB,
3834 OldExpansionTL.getPatternLoc());
3835 if (Result.isNull())
3836 return 0;
3837
3838 Result = RebuildPackExpansionType(Result,
3839 OldExpansionTL.getPatternLoc().getSourceRange(),
3840 OldExpansionTL.getEllipsisLoc(),
3841 NumExpansions);
3842 if (Result.isNull())
3843 return 0;
3844
3845 PackExpansionTypeLoc NewExpansionTL
3846 = TLB.push<PackExpansionTypeLoc>(Result);
3847 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3848 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3849 } else
3850 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003851 if (!NewDI)
3852 return 0;
3853
John McCall8fb0d9d2011-05-01 22:35:37 +00003854 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00003855 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00003856
3857 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3858 OldParm->getDeclContext(),
3859 OldParm->getInnerLocStart(),
3860 OldParm->getLocation(),
3861 OldParm->getIdentifier(),
3862 NewDI->getType(),
3863 NewDI,
3864 OldParm->getStorageClass(),
3865 OldParm->getStorageClassAsWritten(),
3866 /* DefArg */ NULL);
3867 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3868 OldParm->getFunctionScopeIndex() + indexAdjustment);
3869 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00003870}
3871
3872template<typename Derived>
3873bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003874 TransformFunctionTypeParams(SourceLocation Loc,
3875 ParmVarDecl **Params, unsigned NumParams,
3876 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003877 SmallVectorImpl<QualType> &OutParamTypes,
3878 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003879 int indexAdjustment = 0;
3880
Douglas Gregordd472162011-01-07 00:20:55 +00003881 for (unsigned i = 0; i != NumParams; ++i) {
3882 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003883 assert(OldParm->getFunctionScopeIndex() == i);
3884
Douglas Gregor715e4612011-01-14 22:40:04 +00003885 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003886 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00003887 if (OldParm->isParameterPack()) {
3888 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00003889 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003890
Douglas Gregor5499af42011-01-05 23:12:31 +00003891 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003892 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3893 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3894 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3895 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00003896 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3897
Douglas Gregor5499af42011-01-05 23:12:31 +00003898 // Determine whether we should expand the parameter packs.
3899 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003900 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003901 llvm::Optional<unsigned> OrigNumExpansions
3902 = ExpansionTL.getTypePtr()->getNumExpansions();
3903 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003904 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3905 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003906 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003907 ShouldExpand,
3908 RetainExpansion,
3909 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003910 return true;
3911 }
3912
3913 if (ShouldExpand) {
3914 // Expand the function parameter pack into multiple, separate
3915 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003916 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003917 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003918 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3919 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003920 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003921 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003922 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003923 if (!NewParm)
3924 return true;
3925
Douglas Gregordd472162011-01-07 00:20:55 +00003926 OutParamTypes.push_back(NewParm->getType());
3927 if (PVars)
3928 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003929 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003930
3931 // If we're supposed to retain a pack expansion, do so by temporarily
3932 // forgetting the partially-substituted parameter pack.
3933 if (RetainExpansion) {
3934 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3935 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003936 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003937 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003938 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003939 if (!NewParm)
3940 return true;
3941
3942 OutParamTypes.push_back(NewParm->getType());
3943 if (PVars)
3944 PVars->push_back(NewParm);
3945 }
3946
John McCall8fb0d9d2011-05-01 22:35:37 +00003947 // The next parameter should have the same adjustment as the
3948 // last thing we pushed, but we post-incremented indexAdjustment
3949 // on every push. Also, if we push nothing, the adjustment should
3950 // go down by one.
3951 indexAdjustment--;
3952
Douglas Gregor5499af42011-01-05 23:12:31 +00003953 // We're done with the pack expansion.
3954 continue;
3955 }
3956
3957 // We'll substitute the parameter now without expanding the pack
3958 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00003959 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3960 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003961 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003962 NumExpansions);
3963 } else {
3964 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003965 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003966 llvm::Optional<unsigned>());
Douglas Gregor5499af42011-01-05 23:12:31 +00003967 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00003968
John McCall58f10c32010-03-11 09:03:00 +00003969 if (!NewParm)
3970 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003971
Douglas Gregordd472162011-01-07 00:20:55 +00003972 OutParamTypes.push_back(NewParm->getType());
3973 if (PVars)
3974 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003975 continue;
3976 }
John McCall58f10c32010-03-11 09:03:00 +00003977
3978 // Deal with the possibility that we don't have a parameter
3979 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003980 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003981 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003982 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003983 QualType NewType;
Douglas Gregor5499af42011-01-05 23:12:31 +00003984 if (const PackExpansionType *Expansion
3985 = dyn_cast<PackExpansionType>(OldType)) {
3986 // We have a function parameter pack that may need to be expanded.
3987 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00003988 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00003989 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3990
3991 // Determine whether we should expand the parameter packs.
3992 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003993 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003994 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003995 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003996 ShouldExpand,
3997 RetainExpansion,
3998 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003999 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004000 }
4001
4002 if (ShouldExpand) {
4003 // Expand the function parameter pack into multiple, separate
4004 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004005 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004006 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4007 QualType NewType = getDerived().TransformType(Pattern);
4008 if (NewType.isNull())
4009 return true;
John McCall58f10c32010-03-11 09:03:00 +00004010
Douglas Gregordd472162011-01-07 00:20:55 +00004011 OutParamTypes.push_back(NewType);
4012 if (PVars)
4013 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00004014 }
4015
4016 // We're done with the pack expansion.
4017 continue;
4018 }
4019
Douglas Gregor48d24112011-01-10 20:53:55 +00004020 // If we're supposed to retain a pack expansion, do so by temporarily
4021 // forgetting the partially-substituted parameter pack.
4022 if (RetainExpansion) {
4023 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4024 QualType NewType = getDerived().TransformType(Pattern);
4025 if (NewType.isNull())
4026 return true;
4027
4028 OutParamTypes.push_back(NewType);
4029 if (PVars)
4030 PVars->push_back(0);
4031 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004032
Douglas Gregor5499af42011-01-05 23:12:31 +00004033 // We'll substitute the parameter now without expanding the pack
4034 // expansion.
4035 OldType = Expansion->getPattern();
4036 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004037 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4038 NewType = getDerived().TransformType(OldType);
4039 } else {
4040 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004041 }
4042
Douglas Gregor5499af42011-01-05 23:12:31 +00004043 if (NewType.isNull())
4044 return true;
4045
4046 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004047 NewType = getSema().Context.getPackExpansionType(NewType,
4048 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00004049
Douglas Gregordd472162011-01-07 00:20:55 +00004050 OutParamTypes.push_back(NewType);
4051 if (PVars)
4052 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00004053 }
4054
John McCall8fb0d9d2011-05-01 22:35:37 +00004055#ifndef NDEBUG
4056 if (PVars) {
4057 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4058 if (ParmVarDecl *parm = (*PVars)[i])
4059 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004060 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004061#endif
4062
4063 return false;
4064}
John McCall58f10c32010-03-11 09:03:00 +00004065
4066template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004067QualType
John McCall550e0c22009-10-21 00:40:46 +00004068TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004069 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004070 // Transform the parameters and return type.
4071 //
4072 // We instantiate in source order, with the return type first followed by
4073 // the parameters, because users tend to expect this (even if they shouldn't
4074 // rely on it!).
4075 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00004076 // When the function has a trailing return type, we instantiate the
4077 // parameters before the return type, since the return type can then refer
4078 // to the parameters themselves (via decltype, sizeof, etc.).
4079 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004080 SmallVector<QualType, 4> ParamTypes;
4081 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004082 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004083
Douglas Gregor7fb25412010-10-01 18:44:50 +00004084 QualType ResultType;
4085
4086 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00004087 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4088 TL.getParmArray(),
4089 TL.getNumArgs(),
4090 TL.getTypePtr()->arg_type_begin(),
4091 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004092 return QualType();
4093
4094 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4095 if (ResultType.isNull())
4096 return QualType();
4097 }
4098 else {
4099 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4100 if (ResultType.isNull())
4101 return QualType();
4102
Douglas Gregordd472162011-01-07 00:20:55 +00004103 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4104 TL.getParmArray(),
4105 TL.getNumArgs(),
4106 TL.getTypePtr()->arg_type_begin(),
4107 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004108 return QualType();
4109 }
4110
John McCall550e0c22009-10-21 00:40:46 +00004111 QualType Result = TL.getType();
4112 if (getDerived().AlwaysRebuild() ||
4113 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00004114 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00004115 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4116 Result = getDerived().RebuildFunctionProtoType(ResultType,
4117 ParamTypes.data(),
4118 ParamTypes.size(),
4119 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004120 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00004121 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004122 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00004123 if (Result.isNull())
4124 return QualType();
4125 }
Mike Stump11289f42009-09-09 15:08:12 +00004126
John McCall550e0c22009-10-21 00:40:46 +00004127 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004128 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4129 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004130 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00004131 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4132 NewTL.setArg(i, ParamDecls[i]);
4133
4134 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004135}
Mike Stump11289f42009-09-09 15:08:12 +00004136
Douglas Gregord6ff3322009-08-04 16:50:30 +00004137template<typename Derived>
4138QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004139 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004140 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004141 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004142 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4143 if (ResultType.isNull())
4144 return QualType();
4145
4146 QualType Result = TL.getType();
4147 if (getDerived().AlwaysRebuild() ||
4148 ResultType != T->getResultType())
4149 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4150
4151 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004152 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4153 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004154 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00004155
4156 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004157}
Mike Stump11289f42009-09-09 15:08:12 +00004158
John McCallb96ec562009-12-04 22:46:56 +00004159template<typename Derived> QualType
4160TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004161 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004162 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004163 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004164 if (!D)
4165 return QualType();
4166
4167 QualType Result = TL.getType();
4168 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4169 Result = getDerived().RebuildUnresolvedUsingType(D);
4170 if (Result.isNull())
4171 return QualType();
4172 }
4173
4174 // We might get an arbitrary type spec type back. We should at
4175 // least always get a type spec type, though.
4176 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4177 NewTL.setNameLoc(TL.getNameLoc());
4178
4179 return Result;
4180}
4181
Douglas Gregord6ff3322009-08-04 16:50:30 +00004182template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004183QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004184 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004185 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004186 TypedefNameDecl *Typedef
4187 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4188 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004189 if (!Typedef)
4190 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004191
John McCall550e0c22009-10-21 00:40:46 +00004192 QualType Result = TL.getType();
4193 if (getDerived().AlwaysRebuild() ||
4194 Typedef != T->getDecl()) {
4195 Result = getDerived().RebuildTypedefType(Typedef);
4196 if (Result.isNull())
4197 return QualType();
4198 }
Mike Stump11289f42009-09-09 15:08:12 +00004199
John McCall550e0c22009-10-21 00:40:46 +00004200 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4201 NewTL.setNameLoc(TL.getNameLoc());
4202
4203 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004204}
Mike Stump11289f42009-09-09 15:08:12 +00004205
Douglas Gregord6ff3322009-08-04 16:50:30 +00004206template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004207QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004208 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004209 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004210 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004211
John McCalldadc5752010-08-24 06:29:42 +00004212 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004213 if (E.isInvalid())
4214 return QualType();
4215
John McCall550e0c22009-10-21 00:40:46 +00004216 QualType Result = TL.getType();
4217 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004218 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004219 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004220 if (Result.isNull())
4221 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004222 }
John McCall550e0c22009-10-21 00:40:46 +00004223 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004224
John McCall550e0c22009-10-21 00:40:46 +00004225 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004226 NewTL.setTypeofLoc(TL.getTypeofLoc());
4227 NewTL.setLParenLoc(TL.getLParenLoc());
4228 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004229
4230 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004231}
Mike Stump11289f42009-09-09 15:08:12 +00004232
4233template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004234QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004235 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004236 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4237 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4238 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004239 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004240
John McCall550e0c22009-10-21 00:40:46 +00004241 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004242 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4243 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004244 if (Result.isNull())
4245 return QualType();
4246 }
Mike Stump11289f42009-09-09 15:08:12 +00004247
John McCall550e0c22009-10-21 00:40:46 +00004248 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004249 NewTL.setTypeofLoc(TL.getTypeofLoc());
4250 NewTL.setLParenLoc(TL.getLParenLoc());
4251 NewTL.setRParenLoc(TL.getRParenLoc());
4252 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004253
4254 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004255}
Mike Stump11289f42009-09-09 15:08:12 +00004256
4257template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004258QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004259 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004260 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004261
Douglas Gregore922c772009-08-04 22:27:00 +00004262 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004263 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004264
John McCalldadc5752010-08-24 06:29:42 +00004265 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004266 if (E.isInvalid())
4267 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004268
John McCall550e0c22009-10-21 00:40:46 +00004269 QualType Result = TL.getType();
4270 if (getDerived().AlwaysRebuild() ||
4271 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004272 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004273 if (Result.isNull())
4274 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004275 }
John McCall550e0c22009-10-21 00:40:46 +00004276 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004277
John McCall550e0c22009-10-21 00:40:46 +00004278 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4279 NewTL.setNameLoc(TL.getNameLoc());
4280
4281 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004282}
4283
4284template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004285QualType TreeTransform<Derived>::TransformUnaryTransformType(
4286 TypeLocBuilder &TLB,
4287 UnaryTransformTypeLoc TL) {
4288 QualType Result = TL.getType();
4289 if (Result->isDependentType()) {
4290 const UnaryTransformType *T = TL.getTypePtr();
4291 QualType NewBase =
4292 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4293 Result = getDerived().RebuildUnaryTransformType(NewBase,
4294 T->getUTTKind(),
4295 TL.getKWLoc());
4296 if (Result.isNull())
4297 return QualType();
4298 }
4299
4300 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4301 NewTL.setKWLoc(TL.getKWLoc());
4302 NewTL.setParensRange(TL.getParensRange());
4303 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4304 return Result;
4305}
4306
4307template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004308QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4309 AutoTypeLoc TL) {
4310 const AutoType *T = TL.getTypePtr();
4311 QualType OldDeduced = T->getDeducedType();
4312 QualType NewDeduced;
4313 if (!OldDeduced.isNull()) {
4314 NewDeduced = getDerived().TransformType(OldDeduced);
4315 if (NewDeduced.isNull())
4316 return QualType();
4317 }
4318
4319 QualType Result = TL.getType();
4320 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4321 Result = getDerived().RebuildAutoType(NewDeduced);
4322 if (Result.isNull())
4323 return QualType();
4324 }
4325
4326 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4327 NewTL.setNameLoc(TL.getNameLoc());
4328
4329 return Result;
4330}
4331
4332template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004333QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004334 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004335 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004336 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004337 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4338 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004339 if (!Record)
4340 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004341
John McCall550e0c22009-10-21 00:40:46 +00004342 QualType Result = TL.getType();
4343 if (getDerived().AlwaysRebuild() ||
4344 Record != T->getDecl()) {
4345 Result = getDerived().RebuildRecordType(Record);
4346 if (Result.isNull())
4347 return QualType();
4348 }
Mike Stump11289f42009-09-09 15:08:12 +00004349
John McCall550e0c22009-10-21 00:40:46 +00004350 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4351 NewTL.setNameLoc(TL.getNameLoc());
4352
4353 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004354}
Mike Stump11289f42009-09-09 15:08:12 +00004355
4356template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004357QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004358 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004359 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004360 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004361 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4362 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004363 if (!Enum)
4364 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004365
John McCall550e0c22009-10-21 00:40:46 +00004366 QualType Result = TL.getType();
4367 if (getDerived().AlwaysRebuild() ||
4368 Enum != T->getDecl()) {
4369 Result = getDerived().RebuildEnumType(Enum);
4370 if (Result.isNull())
4371 return QualType();
4372 }
Mike Stump11289f42009-09-09 15:08:12 +00004373
John McCall550e0c22009-10-21 00:40:46 +00004374 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4375 NewTL.setNameLoc(TL.getNameLoc());
4376
4377 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004378}
John McCallfcc33b02009-09-05 00:15:47 +00004379
John McCalle78aac42010-03-10 03:28:59 +00004380template<typename Derived>
4381QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4382 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004383 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004384 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4385 TL.getTypePtr()->getDecl());
4386 if (!D) return QualType();
4387
4388 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4389 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4390 return T;
4391}
4392
Douglas Gregord6ff3322009-08-04 16:50:30 +00004393template<typename Derived>
4394QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004395 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004396 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004397 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004398}
4399
Mike Stump11289f42009-09-09 15:08:12 +00004400template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004401QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004402 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004403 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004404 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4405
4406 // Substitute into the replacement type, which itself might involve something
4407 // that needs to be transformed. This only tends to occur with default
4408 // template arguments of template template parameters.
4409 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4410 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4411 if (Replacement.isNull())
4412 return QualType();
4413
4414 // Always canonicalize the replacement type.
4415 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4416 QualType Result
4417 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4418 Replacement);
4419
4420 // Propagate type-source information.
4421 SubstTemplateTypeParmTypeLoc NewTL
4422 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4423 NewTL.setNameLoc(TL.getNameLoc());
4424 return Result;
4425
John McCallcebee162009-10-18 09:09:24 +00004426}
4427
4428template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004429QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4430 TypeLocBuilder &TLB,
4431 SubstTemplateTypeParmPackTypeLoc TL) {
4432 return TransformTypeSpecType(TLB, TL);
4433}
4434
4435template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004436QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004437 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004438 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004439 const TemplateSpecializationType *T = TL.getTypePtr();
4440
Douglas Gregordf846d12011-03-02 18:46:51 +00004441 // The nested-name-specifier never matters in a TemplateSpecializationType,
4442 // because we can't have a dependent nested-name-specifier anyway.
4443 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004444 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004445 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4446 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004447 if (Template.isNull())
4448 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004449
John McCall31f82722010-11-12 08:19:04 +00004450 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4451}
4452
Eli Friedman0dfb8892011-10-06 23:00:33 +00004453template<typename Derived>
4454QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4455 AtomicTypeLoc TL) {
4456 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4457 if (ValueType.isNull())
4458 return QualType();
4459
4460 QualType Result = TL.getType();
4461 if (getDerived().AlwaysRebuild() ||
4462 ValueType != TL.getValueLoc().getType()) {
4463 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4464 if (Result.isNull())
4465 return QualType();
4466 }
4467
4468 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4469 NewTL.setKWLoc(TL.getKWLoc());
4470 NewTL.setLParenLoc(TL.getLParenLoc());
4471 NewTL.setRParenLoc(TL.getRParenLoc());
4472
4473 return Result;
4474}
4475
Douglas Gregorfe921a72010-12-20 23:36:19 +00004476namespace {
4477 /// \brief Simple iterator that traverses the template arguments in a
4478 /// container that provides a \c getArgLoc() member function.
4479 ///
4480 /// This iterator is intended to be used with the iterator form of
4481 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4482 template<typename ArgLocContainer>
4483 class TemplateArgumentLocContainerIterator {
4484 ArgLocContainer *Container;
4485 unsigned Index;
4486
4487 public:
4488 typedef TemplateArgumentLoc value_type;
4489 typedef TemplateArgumentLoc reference;
4490 typedef int difference_type;
4491 typedef std::input_iterator_tag iterator_category;
4492
4493 class pointer {
4494 TemplateArgumentLoc Arg;
4495
4496 public:
4497 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4498
4499 const TemplateArgumentLoc *operator->() const {
4500 return &Arg;
4501 }
4502 };
4503
4504
4505 TemplateArgumentLocContainerIterator() {}
4506
4507 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4508 unsigned Index)
4509 : Container(&Container), Index(Index) { }
4510
4511 TemplateArgumentLocContainerIterator &operator++() {
4512 ++Index;
4513 return *this;
4514 }
4515
4516 TemplateArgumentLocContainerIterator operator++(int) {
4517 TemplateArgumentLocContainerIterator Old(*this);
4518 ++(*this);
4519 return Old;
4520 }
4521
4522 TemplateArgumentLoc operator*() const {
4523 return Container->getArgLoc(Index);
4524 }
4525
4526 pointer operator->() const {
4527 return pointer(Container->getArgLoc(Index));
4528 }
4529
4530 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004531 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004532 return X.Container == Y.Container && X.Index == Y.Index;
4533 }
4534
4535 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004536 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004537 return !(X == Y);
4538 }
4539 };
4540}
4541
4542
John McCall31f82722010-11-12 08:19:04 +00004543template <typename Derived>
4544QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4545 TypeLocBuilder &TLB,
4546 TemplateSpecializationTypeLoc TL,
4547 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004548 TemplateArgumentListInfo NewTemplateArgs;
4549 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4550 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004551 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4552 ArgIterator;
4553 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4554 ArgIterator(TL, TL.getNumArgs()),
4555 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004556 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004557
John McCall0ad16662009-10-29 08:12:44 +00004558 // FIXME: maybe don't rebuild if all the template arguments are the same.
4559
4560 QualType Result =
4561 getDerived().RebuildTemplateSpecializationType(Template,
4562 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004563 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004564
4565 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004566 // Specializations of template template parameters are represented as
4567 // TemplateSpecializationTypes, and substitution of type alias templates
4568 // within a dependent context can transform them into
4569 // DependentTemplateSpecializationTypes.
4570 if (isa<DependentTemplateSpecializationType>(Result)) {
4571 DependentTemplateSpecializationTypeLoc NewTL
4572 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4573 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4574 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4575 NewTL.setNameLoc(TL.getTemplateNameLoc());
4576 NewTL.setLAngleLoc(TL.getLAngleLoc());
4577 NewTL.setRAngleLoc(TL.getRAngleLoc());
4578 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4579 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4580 return Result;
4581 }
4582
John McCall0ad16662009-10-29 08:12:44 +00004583 TemplateSpecializationTypeLoc NewTL
4584 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4585 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4586 NewTL.setLAngleLoc(TL.getLAngleLoc());
4587 NewTL.setRAngleLoc(TL.getRAngleLoc());
4588 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4589 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004590 }
Mike Stump11289f42009-09-09 15:08:12 +00004591
John McCall0ad16662009-10-29 08:12:44 +00004592 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004593}
Mike Stump11289f42009-09-09 15:08:12 +00004594
Douglas Gregor5a064722011-02-28 17:23:35 +00004595template <typename Derived>
4596QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4597 TypeLocBuilder &TLB,
4598 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004599 TemplateName Template,
4600 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004601 TemplateArgumentListInfo NewTemplateArgs;
4602 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4603 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4604 typedef TemplateArgumentLocContainerIterator<
4605 DependentTemplateSpecializationTypeLoc> ArgIterator;
4606 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4607 ArgIterator(TL, TL.getNumArgs()),
4608 NewTemplateArgs))
4609 return QualType();
4610
4611 // FIXME: maybe don't rebuild if all the template arguments are the same.
4612
4613 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4614 QualType Result
4615 = getSema().Context.getDependentTemplateSpecializationType(
4616 TL.getTypePtr()->getKeyword(),
4617 DTN->getQualifier(),
4618 DTN->getIdentifier(),
4619 NewTemplateArgs);
4620
4621 DependentTemplateSpecializationTypeLoc NewTL
4622 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4623 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004624
Douglas Gregora7a795b2011-03-01 20:11:18 +00004625 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004626 NewTL.setNameLoc(TL.getNameLoc());
4627 NewTL.setLAngleLoc(TL.getLAngleLoc());
4628 NewTL.setRAngleLoc(TL.getRAngleLoc());
4629 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4630 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4631 return Result;
4632 }
4633
4634 QualType Result
4635 = getDerived().RebuildTemplateSpecializationType(Template,
4636 TL.getNameLoc(),
4637 NewTemplateArgs);
4638
4639 if (!Result.isNull()) {
4640 /// FIXME: Wrap this in an elaborated-type-specifier?
4641 TemplateSpecializationTypeLoc NewTL
4642 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4643 NewTL.setTemplateNameLoc(TL.getNameLoc());
4644 NewTL.setLAngleLoc(TL.getLAngleLoc());
4645 NewTL.setRAngleLoc(TL.getRAngleLoc());
4646 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4647 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4648 }
4649
4650 return Result;
4651}
4652
Mike Stump11289f42009-09-09 15:08:12 +00004653template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004654QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004655TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004656 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004657 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004658
Douglas Gregor844cb502011-03-01 18:12:44 +00004659 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004660 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004661 if (TL.getQualifierLoc()) {
4662 QualifierLoc
4663 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4664 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004665 return QualType();
4666 }
Mike Stump11289f42009-09-09 15:08:12 +00004667
John McCall31f82722010-11-12 08:19:04 +00004668 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4669 if (NamedT.isNull())
4670 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004671
Richard Smith3f1b5d02011-05-05 21:57:07 +00004672 // C++0x [dcl.type.elab]p2:
4673 // If the identifier resolves to a typedef-name or the simple-template-id
4674 // resolves to an alias template specialization, the
4675 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00004676 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4677 if (const TemplateSpecializationType *TST =
4678 NamedT->getAs<TemplateSpecializationType>()) {
4679 TemplateName Template = TST->getTemplateName();
4680 if (TypeAliasTemplateDecl *TAT =
4681 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4682 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4683 diag::err_tag_reference_non_tag) << 4;
4684 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4685 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00004686 }
4687 }
4688
John McCall550e0c22009-10-21 00:40:46 +00004689 QualType Result = TL.getType();
4690 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004691 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004692 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004693 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004694 T->getKeyword(),
4695 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004696 if (Result.isNull())
4697 return QualType();
4698 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004699
Abramo Bagnara6150c882010-05-11 21:36:43 +00004700 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004701 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004702 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004703 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004704}
Mike Stump11289f42009-09-09 15:08:12 +00004705
4706template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004707QualType TreeTransform<Derived>::TransformAttributedType(
4708 TypeLocBuilder &TLB,
4709 AttributedTypeLoc TL) {
4710 const AttributedType *oldType = TL.getTypePtr();
4711 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4712 if (modifiedType.isNull())
4713 return QualType();
4714
4715 QualType result = TL.getType();
4716
4717 // FIXME: dependent operand expressions?
4718 if (getDerived().AlwaysRebuild() ||
4719 modifiedType != oldType->getModifiedType()) {
4720 // TODO: this is really lame; we should really be rebuilding the
4721 // equivalent type from first principles.
4722 QualType equivalentType
4723 = getDerived().TransformType(oldType->getEquivalentType());
4724 if (equivalentType.isNull())
4725 return QualType();
4726 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4727 modifiedType,
4728 equivalentType);
4729 }
4730
4731 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4732 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4733 if (TL.hasAttrOperand())
4734 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4735 if (TL.hasAttrExprOperand())
4736 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4737 else if (TL.hasAttrEnumOperand())
4738 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4739
4740 return result;
4741}
4742
4743template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004744QualType
4745TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4746 ParenTypeLoc TL) {
4747 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4748 if (Inner.isNull())
4749 return QualType();
4750
4751 QualType Result = TL.getType();
4752 if (getDerived().AlwaysRebuild() ||
4753 Inner != TL.getInnerLoc().getType()) {
4754 Result = getDerived().RebuildParenType(Inner);
4755 if (Result.isNull())
4756 return QualType();
4757 }
4758
4759 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4760 NewTL.setLParenLoc(TL.getLParenLoc());
4761 NewTL.setRParenLoc(TL.getRParenLoc());
4762 return Result;
4763}
4764
4765template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004766QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004767 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004768 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004769
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004770 NestedNameSpecifierLoc QualifierLoc
4771 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4772 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004773 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004774
John McCallc392f372010-06-11 00:33:02 +00004775 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004776 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004777 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004778 QualifierLoc,
4779 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004780 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004781 if (Result.isNull())
4782 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004783
Abramo Bagnarad7548482010-05-19 21:37:53 +00004784 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4785 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004786 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4787
Abramo Bagnarad7548482010-05-19 21:37:53 +00004788 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4789 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004790 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004791 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004792 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4793 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004794 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004795 NewTL.setNameLoc(TL.getNameLoc());
4796 }
John McCall550e0c22009-10-21 00:40:46 +00004797 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004798}
Mike Stump11289f42009-09-09 15:08:12 +00004799
Douglas Gregord6ff3322009-08-04 16:50:30 +00004800template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004801QualType TreeTransform<Derived>::
4802 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004803 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004804 NestedNameSpecifierLoc QualifierLoc;
4805 if (TL.getQualifierLoc()) {
4806 QualifierLoc
4807 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4808 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004809 return QualType();
4810 }
4811
John McCall31f82722010-11-12 08:19:04 +00004812 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004813 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004814}
4815
4816template<typename Derived>
4817QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00004818TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4819 DependentTemplateSpecializationTypeLoc TL,
4820 NestedNameSpecifierLoc QualifierLoc) {
4821 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4822
4823 TemplateArgumentListInfo NewTemplateArgs;
4824 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4825 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4826
4827 typedef TemplateArgumentLocContainerIterator<
4828 DependentTemplateSpecializationTypeLoc> ArgIterator;
4829 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4830 ArgIterator(TL, TL.getNumArgs()),
4831 NewTemplateArgs))
4832 return QualType();
4833
4834 QualType Result
4835 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4836 QualifierLoc,
4837 T->getIdentifier(),
4838 TL.getNameLoc(),
4839 NewTemplateArgs);
4840 if (Result.isNull())
4841 return QualType();
4842
4843 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4844 QualType NamedT = ElabT->getNamedType();
4845
4846 // Copy information relevant to the template specialization.
4847 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00004848 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004849 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004850 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4851 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004852 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004853 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004854
4855 // Copy information relevant to the elaborated type.
4856 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4857 NewTL.setKeywordLoc(TL.getKeywordLoc());
4858 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00004859 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4860 DependentTemplateSpecializationTypeLoc SpecTL
4861 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor11ddf132011-03-07 15:13:34 +00004862 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004863 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004864 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004865 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4866 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004867 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004868 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004869 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00004870 TemplateSpecializationTypeLoc SpecTL
4871 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004872 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004873 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4874 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004875 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004876 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004877 }
4878 return Result;
4879}
4880
4881template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004882QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4883 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004884 QualType Pattern
4885 = getDerived().TransformType(TLB, TL.getPatternLoc());
4886 if (Pattern.isNull())
4887 return QualType();
4888
4889 QualType Result = TL.getType();
4890 if (getDerived().AlwaysRebuild() ||
4891 Pattern != TL.getPatternLoc().getType()) {
4892 Result = getDerived().RebuildPackExpansionType(Pattern,
4893 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004894 TL.getEllipsisLoc(),
4895 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004896 if (Result.isNull())
4897 return QualType();
4898 }
4899
4900 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4901 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4902 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004903}
4904
4905template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004906QualType
4907TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004908 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004909 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004910 TLB.pushFullCopy(TL);
4911 return TL.getType();
4912}
4913
4914template<typename Derived>
4915QualType
4916TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004917 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004918 // ObjCObjectType is never dependent.
4919 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004920 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004921}
Mike Stump11289f42009-09-09 15:08:12 +00004922
4923template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004924QualType
4925TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004926 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004927 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004928 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004929 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004930}
4931
Douglas Gregord6ff3322009-08-04 16:50:30 +00004932//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004933// Statement transformation
4934//===----------------------------------------------------------------------===//
4935template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004936StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004937TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004938 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004939}
4940
4941template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004942StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004943TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4944 return getDerived().TransformCompoundStmt(S, false);
4945}
4946
4947template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004948StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004949TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004950 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004951 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004952 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004953 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004954 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4955 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004956 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004957 if (Result.isInvalid()) {
4958 // Immediately fail if this was a DeclStmt, since it's very
4959 // likely that this will cause problems for future statements.
4960 if (isa<DeclStmt>(*B))
4961 return StmtError();
4962
4963 // Otherwise, just keep processing substatements and fail later.
4964 SubStmtInvalid = true;
4965 continue;
4966 }
Mike Stump11289f42009-09-09 15:08:12 +00004967
Douglas Gregorebe10102009-08-20 07:17:43 +00004968 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4969 Statements.push_back(Result.takeAs<Stmt>());
4970 }
Mike Stump11289f42009-09-09 15:08:12 +00004971
John McCall1ababa62010-08-27 19:56:05 +00004972 if (SubStmtInvalid)
4973 return StmtError();
4974
Douglas Gregorebe10102009-08-20 07:17:43 +00004975 if (!getDerived().AlwaysRebuild() &&
4976 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004977 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004978
4979 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4980 move_arg(Statements),
4981 S->getRBracLoc(),
4982 IsStmtExpr);
4983}
Mike Stump11289f42009-09-09 15:08:12 +00004984
Douglas Gregorebe10102009-08-20 07:17:43 +00004985template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004986StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004987TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004988 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004989 {
4990 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004991 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004992
Eli Friedman06577382009-11-19 03:14:00 +00004993 // Transform the left-hand case value.
4994 LHS = getDerived().TransformExpr(S->getLHS());
4995 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004996 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004997
Eli Friedman06577382009-11-19 03:14:00 +00004998 // Transform the right-hand case value (for the GNU case-range extension).
4999 RHS = getDerived().TransformExpr(S->getRHS());
5000 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005001 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005002 }
Mike Stump11289f42009-09-09 15:08:12 +00005003
Douglas Gregorebe10102009-08-20 07:17:43 +00005004 // Build the case statement.
5005 // Case statements are always rebuilt so that they will attached to their
5006 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005007 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005008 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005009 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005010 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005011 S->getColonLoc());
5012 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005013 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005014
Douglas Gregorebe10102009-08-20 07:17:43 +00005015 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005016 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005017 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005018 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005019
Douglas Gregorebe10102009-08-20 07:17:43 +00005020 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005021 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005022}
5023
5024template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005025StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005026TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005027 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005028 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005029 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005030 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005031
Douglas Gregorebe10102009-08-20 07:17:43 +00005032 // Default statements are always rebuilt
5033 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005034 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005035}
Mike Stump11289f42009-09-09 15:08:12 +00005036
Douglas Gregorebe10102009-08-20 07:17:43 +00005037template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005038StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005039TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005040 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005041 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005042 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005043
Chris Lattnercab02a62011-02-17 20:34:02 +00005044 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5045 S->getDecl());
5046 if (!LD)
5047 return StmtError();
5048
5049
Douglas Gregorebe10102009-08-20 07:17:43 +00005050 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005051 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005052 cast<LabelDecl>(LD), SourceLocation(),
5053 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005054}
Mike Stump11289f42009-09-09 15:08:12 +00005055
Douglas Gregorebe10102009-08-20 07:17:43 +00005056template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005057StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005058TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005059 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005060 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00005061 VarDecl *ConditionVar = 0;
5062 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005063 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005064 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005065 getDerived().TransformDefinition(
5066 S->getConditionVariable()->getLocation(),
5067 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005068 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005069 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005070 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005071 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005072
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005073 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005074 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005075
5076 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005077 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005078 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5079 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005080 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005081 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005082
John McCallb268a282010-08-23 23:25:46 +00005083 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005084 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005085 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005086
John McCallb268a282010-08-23 23:25:46 +00005087 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5088 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005089 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005090
Douglas Gregorebe10102009-08-20 07:17:43 +00005091 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005092 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005093 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005094 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005095
Douglas Gregorebe10102009-08-20 07:17:43 +00005096 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005097 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005098 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005099 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005100
Douglas Gregorebe10102009-08-20 07:17:43 +00005101 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005102 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005103 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005104 Then.get() == S->getThen() &&
5105 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00005106 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005107
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005108 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005109 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005110 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005111}
5112
5113template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005114StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005115TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005116 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005117 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00005118 VarDecl *ConditionVar = 0;
5119 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005120 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005121 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005122 getDerived().TransformDefinition(
5123 S->getConditionVariable()->getLocation(),
5124 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005125 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005126 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005127 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005128 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005129
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005130 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005131 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005132 }
Mike Stump11289f42009-09-09 15:08:12 +00005133
Douglas Gregorebe10102009-08-20 07:17:43 +00005134 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005135 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005136 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005137 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005138 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005139 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005140
Douglas Gregorebe10102009-08-20 07:17:43 +00005141 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005142 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005143 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005144 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005145
Douglas Gregorebe10102009-08-20 07:17:43 +00005146 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005147 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5148 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005149}
Mike Stump11289f42009-09-09 15:08:12 +00005150
Douglas Gregorebe10102009-08-20 07:17:43 +00005151template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005152StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005153TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005154 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005155 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005156 VarDecl *ConditionVar = 0;
5157 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005158 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005159 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005160 getDerived().TransformDefinition(
5161 S->getConditionVariable()->getLocation(),
5162 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005163 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005164 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005165 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005166 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005167
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005168 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005169 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005170
5171 if (S->getCond()) {
5172 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005173 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5174 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005175 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005176 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005177 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005178 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005179 }
Mike Stump11289f42009-09-09 15:08:12 +00005180
John McCallb268a282010-08-23 23:25:46 +00005181 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5182 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005183 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005184
Douglas Gregorebe10102009-08-20 07:17:43 +00005185 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005186 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005187 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005188 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005189
Douglas Gregorebe10102009-08-20 07:17:43 +00005190 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005191 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005192 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005193 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005194 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005195
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005196 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005197 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005198}
Mike Stump11289f42009-09-09 15:08:12 +00005199
Douglas Gregorebe10102009-08-20 07:17:43 +00005200template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005201StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005202TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005203 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005204 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005205 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005206 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005207
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005208 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005209 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005210 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005211 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005212
Douglas Gregorebe10102009-08-20 07:17:43 +00005213 if (!getDerived().AlwaysRebuild() &&
5214 Cond.get() == S->getCond() &&
5215 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005216 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005217
John McCallb268a282010-08-23 23:25:46 +00005218 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5219 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005220 S->getRParenLoc());
5221}
Mike Stump11289f42009-09-09 15:08:12 +00005222
Douglas Gregorebe10102009-08-20 07:17:43 +00005223template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005224StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005225TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005226 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005227 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005228 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005229 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005230
Douglas Gregorebe10102009-08-20 07:17:43 +00005231 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005232 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005233 VarDecl *ConditionVar = 0;
5234 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005235 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005236 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005237 getDerived().TransformDefinition(
5238 S->getConditionVariable()->getLocation(),
5239 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005240 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005241 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005242 } else {
5243 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005244
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005245 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005246 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005247
5248 if (S->getCond()) {
5249 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005250 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5251 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005252 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005253 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005254
John McCallb268a282010-08-23 23:25:46 +00005255 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005256 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005257 }
Mike Stump11289f42009-09-09 15:08:12 +00005258
John McCallb268a282010-08-23 23:25:46 +00005259 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5260 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005261 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005262
Douglas Gregorebe10102009-08-20 07:17:43 +00005263 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005264 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005265 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005266 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005267
John McCallb268a282010-08-23 23:25:46 +00005268 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5269 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005270 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005271
Douglas Gregorebe10102009-08-20 07:17:43 +00005272 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005273 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005274 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005275 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005276
Douglas Gregorebe10102009-08-20 07:17:43 +00005277 if (!getDerived().AlwaysRebuild() &&
5278 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005279 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005280 Inc.get() == S->getInc() &&
5281 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005282 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005283
Douglas Gregorebe10102009-08-20 07:17:43 +00005284 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005285 Init.get(), FullCond, ConditionVar,
5286 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005287}
5288
5289template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005290StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005291TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005292 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5293 S->getLabel());
5294 if (!LD)
5295 return StmtError();
5296
Douglas Gregorebe10102009-08-20 07:17:43 +00005297 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005298 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005299 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005300}
5301
5302template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005303StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005304TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005305 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005306 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005307 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005308
Douglas Gregorebe10102009-08-20 07:17:43 +00005309 if (!getDerived().AlwaysRebuild() &&
5310 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005311 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005312
5313 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005314 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005315}
5316
5317template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005318StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005319TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005320 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005321}
Mike Stump11289f42009-09-09 15:08:12 +00005322
Douglas Gregorebe10102009-08-20 07:17:43 +00005323template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005324StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005325TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005326 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005327}
Mike Stump11289f42009-09-09 15:08:12 +00005328
Douglas Gregorebe10102009-08-20 07:17:43 +00005329template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005330StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005331TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005332 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005333 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005334 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005335
Mike Stump11289f42009-09-09 15:08:12 +00005336 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005337 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005338 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005339}
Mike Stump11289f42009-09-09 15:08:12 +00005340
Douglas Gregorebe10102009-08-20 07:17:43 +00005341template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005342StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005343TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005344 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005345 SmallVector<Decl *, 4> Decls;
Douglas Gregorebe10102009-08-20 07:17:43 +00005346 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5347 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005348 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5349 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005350 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005351 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005352
Douglas Gregorebe10102009-08-20 07:17:43 +00005353 if (Transformed != *D)
5354 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005355
Douglas Gregorebe10102009-08-20 07:17:43 +00005356 Decls.push_back(Transformed);
5357 }
Mike Stump11289f42009-09-09 15:08:12 +00005358
Douglas Gregorebe10102009-08-20 07:17:43 +00005359 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005360 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005361
5362 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005363 S->getStartLoc(), S->getEndLoc());
5364}
Mike Stump11289f42009-09-09 15:08:12 +00005365
Douglas Gregorebe10102009-08-20 07:17:43 +00005366template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005367StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005368TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005369
John McCall37ad5512010-08-23 06:44:23 +00005370 ASTOwningVector<Expr*> Constraints(getSema());
5371 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner01cf8db2011-07-20 06:58:45 +00005372 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005373
John McCalldadc5752010-08-24 06:29:42 +00005374 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005375 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005376
5377 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005378
Anders Carlssonaaeef072010-01-24 05:50:09 +00005379 // Go through the outputs.
5380 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005381 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005382
Anders Carlssonaaeef072010-01-24 05:50:09 +00005383 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005384 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005385
Anders Carlssonaaeef072010-01-24 05:50:09 +00005386 // Transform the output expr.
5387 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005388 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005389 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005390 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005391
Anders Carlssonaaeef072010-01-24 05:50:09 +00005392 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005393
John McCallb268a282010-08-23 23:25:46 +00005394 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005395 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005396
Anders Carlssonaaeef072010-01-24 05:50:09 +00005397 // Go through the inputs.
5398 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005399 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005400
Anders Carlssonaaeef072010-01-24 05:50:09 +00005401 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005402 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005403
Anders Carlssonaaeef072010-01-24 05:50:09 +00005404 // Transform the input expr.
5405 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005406 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005407 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005408 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005409
Anders Carlssonaaeef072010-01-24 05:50:09 +00005410 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005411
John McCallb268a282010-08-23 23:25:46 +00005412 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005413 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005414
Anders Carlssonaaeef072010-01-24 05:50:09 +00005415 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005416 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005417
5418 // Go through the clobbers.
5419 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005420 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005421
5422 // No need to transform the asm string literal.
5423 AsmString = SemaRef.Owned(S->getAsmString());
5424
5425 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5426 S->isSimple(),
5427 S->isVolatile(),
5428 S->getNumOutputs(),
5429 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005430 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005431 move_arg(Constraints),
5432 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005433 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005434 move_arg(Clobbers),
5435 S->getRParenLoc(),
5436 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005437}
5438
5439
5440template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005441StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005442TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005443 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005444 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005445 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005446 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005447
Douglas Gregor96c79492010-04-23 22:50:49 +00005448 // Transform the @catch statements (if present).
5449 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005450 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005451 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005452 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005453 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005454 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005455 if (Catch.get() != S->getCatchStmt(I))
5456 AnyCatchChanged = true;
5457 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005458 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005459
Douglas Gregor306de2f2010-04-22 23:59:56 +00005460 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005461 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005462 if (S->getFinallyStmt()) {
5463 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5464 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005465 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005466 }
5467
5468 // If nothing changed, just retain this statement.
5469 if (!getDerived().AlwaysRebuild() &&
5470 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005471 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005472 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005473 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005474
Douglas Gregor306de2f2010-04-22 23:59:56 +00005475 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005476 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5477 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005478}
Mike Stump11289f42009-09-09 15:08:12 +00005479
Douglas Gregorebe10102009-08-20 07:17:43 +00005480template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005481StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005482TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005483 // Transform the @catch parameter, if there is one.
5484 VarDecl *Var = 0;
5485 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5486 TypeSourceInfo *TSInfo = 0;
5487 if (FromVar->getTypeSourceInfo()) {
5488 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5489 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005490 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005491 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005492
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005493 QualType T;
5494 if (TSInfo)
5495 T = TSInfo->getType();
5496 else {
5497 T = getDerived().TransformType(FromVar->getType());
5498 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005499 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005500 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005501
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005502 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5503 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005504 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005505 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005506
John McCalldadc5752010-08-24 06:29:42 +00005507 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005508 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005509 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005510
5511 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005512 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005513 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005514}
Mike Stump11289f42009-09-09 15:08:12 +00005515
Douglas Gregorebe10102009-08-20 07:17:43 +00005516template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005517StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005518TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005519 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005520 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005521 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005522 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005523
Douglas Gregor306de2f2010-04-22 23:59:56 +00005524 // If nothing changed, just retain this statement.
5525 if (!getDerived().AlwaysRebuild() &&
5526 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005527 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005528
5529 // Build a new statement.
5530 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005531 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005532}
Mike Stump11289f42009-09-09 15:08:12 +00005533
Douglas Gregorebe10102009-08-20 07:17:43 +00005534template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005535StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005536TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005537 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005538 if (S->getThrowExpr()) {
5539 Operand = getDerived().TransformExpr(S->getThrowExpr());
5540 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005541 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005542 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005543
Douglas Gregor2900c162010-04-22 21:44:01 +00005544 if (!getDerived().AlwaysRebuild() &&
5545 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005546 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005547
John McCallb268a282010-08-23 23:25:46 +00005548 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005549}
Mike Stump11289f42009-09-09 15:08:12 +00005550
Douglas Gregorebe10102009-08-20 07:17:43 +00005551template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005552StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005553TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005554 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005555 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005556 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005557 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005558 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00005559 Object =
5560 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5561 Object.get());
5562 if (Object.isInvalid())
5563 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005564
Douglas Gregor6148de72010-04-22 22:01:21 +00005565 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005566 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005567 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005568 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005569
Douglas Gregor6148de72010-04-22 22:01:21 +00005570 // If nothing change, just retain the current statement.
5571 if (!getDerived().AlwaysRebuild() &&
5572 Object.get() == S->getSynchExpr() &&
5573 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005574 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005575
5576 // Build a new statement.
5577 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005578 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005579}
5580
5581template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005582StmtResult
John McCall31168b02011-06-15 23:02:42 +00005583TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5584 ObjCAutoreleasePoolStmt *S) {
5585 // Transform the body.
5586 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5587 if (Body.isInvalid())
5588 return StmtError();
5589
5590 // If nothing changed, just retain this statement.
5591 if (!getDerived().AlwaysRebuild() &&
5592 Body.get() == S->getSubStmt())
5593 return SemaRef.Owned(S);
5594
5595 // Build a new statement.
5596 return getDerived().RebuildObjCAutoreleasePoolStmt(
5597 S->getAtLoc(), Body.get());
5598}
5599
5600template<typename Derived>
5601StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005602TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005603 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005604 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005605 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005606 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005607 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005608
Douglas Gregorf68a5082010-04-22 23:10:45 +00005609 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005610 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005611 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005612 return StmtError();
John McCall53848232011-07-27 01:07:15 +00005613 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5614 Collection.take());
5615 if (Collection.isInvalid())
5616 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005617
Douglas Gregorf68a5082010-04-22 23:10:45 +00005618 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005619 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005620 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005621 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005622
Douglas Gregorf68a5082010-04-22 23:10:45 +00005623 // If nothing changed, just retain this statement.
5624 if (!getDerived().AlwaysRebuild() &&
5625 Element.get() == S->getElement() &&
5626 Collection.get() == S->getCollection() &&
5627 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005628 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005629
Douglas Gregorf68a5082010-04-22 23:10:45 +00005630 // Build a new statement.
5631 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5632 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005633 Element.get(),
5634 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005635 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005636 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005637}
5638
5639
5640template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005641StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005642TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5643 // Transform the exception declaration, if any.
5644 VarDecl *Var = 0;
5645 if (S->getExceptionDecl()) {
5646 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005647 TypeSourceInfo *T = getDerived().TransformType(
5648 ExceptionDecl->getTypeSourceInfo());
5649 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005650 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005651
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005652 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaradff19302011-03-08 08:55:46 +00005653 ExceptionDecl->getInnerLocStart(),
5654 ExceptionDecl->getLocation(),
5655 ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00005656 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005657 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005658 }
Mike Stump11289f42009-09-09 15:08:12 +00005659
Douglas Gregorebe10102009-08-20 07:17:43 +00005660 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005661 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005662 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005663 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005664
Douglas Gregorebe10102009-08-20 07:17:43 +00005665 if (!getDerived().AlwaysRebuild() &&
5666 !Var &&
5667 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005668 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005669
5670 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5671 Var,
John McCallb268a282010-08-23 23:25:46 +00005672 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005673}
Mike Stump11289f42009-09-09 15:08:12 +00005674
Douglas Gregorebe10102009-08-20 07:17:43 +00005675template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005676StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005677TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5678 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005679 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005680 = getDerived().TransformCompoundStmt(S->getTryBlock());
5681 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005682 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005683
Douglas Gregorebe10102009-08-20 07:17:43 +00005684 // Transform the handlers.
5685 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005686 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005687 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005688 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005689 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5690 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005691 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005692
Douglas Gregorebe10102009-08-20 07:17:43 +00005693 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5694 Handlers.push_back(Handler.takeAs<Stmt>());
5695 }
Mike Stump11289f42009-09-09 15:08:12 +00005696
Douglas Gregorebe10102009-08-20 07:17:43 +00005697 if (!getDerived().AlwaysRebuild() &&
5698 TryBlock.get() == S->getTryBlock() &&
5699 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005700 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005701
John McCallb268a282010-08-23 23:25:46 +00005702 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005703 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005704}
Mike Stump11289f42009-09-09 15:08:12 +00005705
Richard Smith02e85f32011-04-14 22:09:26 +00005706template<typename Derived>
5707StmtResult
5708TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5709 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5710 if (Range.isInvalid())
5711 return StmtError();
5712
5713 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5714 if (BeginEnd.isInvalid())
5715 return StmtError();
5716
5717 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5718 if (Cond.isInvalid())
5719 return StmtError();
5720
5721 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5722 if (Inc.isInvalid())
5723 return StmtError();
5724
5725 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5726 if (LoopVar.isInvalid())
5727 return StmtError();
5728
5729 StmtResult NewStmt = S;
5730 if (getDerived().AlwaysRebuild() ||
5731 Range.get() != S->getRangeStmt() ||
5732 BeginEnd.get() != S->getBeginEndStmt() ||
5733 Cond.get() != S->getCond() ||
5734 Inc.get() != S->getInc() ||
5735 LoopVar.get() != S->getLoopVarStmt())
5736 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5737 S->getColonLoc(), Range.get(),
5738 BeginEnd.get(), Cond.get(),
5739 Inc.get(), LoopVar.get(),
5740 S->getRParenLoc());
5741
5742 StmtResult Body = getDerived().TransformStmt(S->getBody());
5743 if (Body.isInvalid())
5744 return StmtError();
5745
5746 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5747 // it now so we have a new statement to attach the body to.
5748 if (Body.get() != S->getBody() && NewStmt.get() == S)
5749 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5750 S->getColonLoc(), Range.get(),
5751 BeginEnd.get(), Cond.get(),
5752 Inc.get(), LoopVar.get(),
5753 S->getRParenLoc());
5754
5755 if (NewStmt.get() == S)
5756 return SemaRef.Owned(S);
5757
5758 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5759}
5760
John Wiegley1c0675e2011-04-28 01:08:34 +00005761template<typename Derived>
5762StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00005763TreeTransform<Derived>::TransformMSDependentExistsStmt(
5764 MSDependentExistsStmt *S) {
5765 // Transform the nested-name-specifier, if any.
5766 NestedNameSpecifierLoc QualifierLoc;
5767 if (S->getQualifierLoc()) {
5768 QualifierLoc
5769 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5770 if (!QualifierLoc)
5771 return StmtError();
5772 }
5773
5774 // Transform the declaration name.
5775 DeclarationNameInfo NameInfo = S->getNameInfo();
5776 if (NameInfo.getName()) {
5777 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5778 if (!NameInfo.getName())
5779 return StmtError();
5780 }
5781
5782 // Check whether anything changed.
5783 if (!getDerived().AlwaysRebuild() &&
5784 QualifierLoc == S->getQualifierLoc() &&
5785 NameInfo.getName() == S->getNameInfo().getName())
5786 return S;
5787
5788 // Determine whether this name exists, if we can.
5789 CXXScopeSpec SS;
5790 SS.Adopt(QualifierLoc);
5791 bool Dependent = false;
5792 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5793 case Sema::IER_Exists:
5794 if (S->isIfExists())
5795 break;
5796
5797 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5798
5799 case Sema::IER_DoesNotExist:
5800 if (S->isIfNotExists())
5801 break;
5802
5803 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5804
5805 case Sema::IER_Dependent:
5806 Dependent = true;
5807 break;
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00005808
5809 case Sema::IER_Error:
5810 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00005811 }
5812
5813 // We need to continue with the instantiation, so do so now.
5814 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5815 if (SubStmt.isInvalid())
5816 return StmtError();
5817
5818 // If we have resolved the name, just transform to the substatement.
5819 if (!Dependent)
5820 return SubStmt;
5821
5822 // The name is still dependent, so build a dependent expression again.
5823 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5824 S->isIfExists(),
5825 QualifierLoc,
5826 NameInfo,
5827 SubStmt.get());
5828}
5829
5830template<typename Derived>
5831StmtResult
John Wiegley1c0675e2011-04-28 01:08:34 +00005832TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5833 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5834 if(TryBlock.isInvalid()) return StmtError();
5835
5836 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5837 if(!getDerived().AlwaysRebuild() &&
5838 TryBlock.get() == S->getTryBlock() &&
5839 Handler.get() == S->getHandler())
5840 return SemaRef.Owned(S);
5841
5842 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5843 S->getTryLoc(),
5844 TryBlock.take(),
5845 Handler.take());
5846}
5847
5848template<typename Derived>
5849StmtResult
5850TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5851 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5852 if(Block.isInvalid()) return StmtError();
5853
5854 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5855 Block.take());
5856}
5857
5858template<typename Derived>
5859StmtResult
5860TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5861 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5862 if(FilterExpr.isInvalid()) return StmtError();
5863
5864 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5865 if(Block.isInvalid()) return StmtError();
5866
5867 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5868 FilterExpr.take(),
5869 Block.take());
5870}
5871
5872template<typename Derived>
5873StmtResult
5874TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5875 if(isa<SEHFinallyStmt>(Handler))
5876 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5877 else
5878 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5879}
5880
Douglas Gregorebe10102009-08-20 07:17:43 +00005881//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005882// Expression transformation
5883//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005884template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005885ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005886TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005887 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005888}
Mike Stump11289f42009-09-09 15:08:12 +00005889
5890template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005891ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005892TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005893 NestedNameSpecifierLoc QualifierLoc;
5894 if (E->getQualifierLoc()) {
5895 QualifierLoc
5896 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5897 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005898 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005899 }
John McCallce546572009-12-08 09:08:17 +00005900
5901 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005902 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5903 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005904 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005905 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005906
John McCall815039a2010-08-17 21:27:17 +00005907 DeclarationNameInfo NameInfo = E->getNameInfo();
5908 if (NameInfo.getName()) {
5909 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5910 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005911 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005912 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005913
5914 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005915 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005916 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005917 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005918 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005919
5920 // Mark it referenced in the new context regardless.
5921 // FIXME: this is a bit instantiation-specific.
5922 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5923
John McCallc3007a22010-10-26 07:05:15 +00005924 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005925 }
John McCallce546572009-12-08 09:08:17 +00005926
5927 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005928 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005929 TemplateArgs = &TransArgs;
5930 TransArgs.setLAngleLoc(E->getLAngleLoc());
5931 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005932 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5933 E->getNumTemplateArgs(),
5934 TransArgs))
5935 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005936 }
5937
Douglas Gregorea972d32011-02-28 21:54:11 +00005938 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5939 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005940}
Mike Stump11289f42009-09-09 15:08:12 +00005941
Douglas Gregora16548e2009-08-11 05:31:07 +00005942template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005943ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005944TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005945 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005946}
Mike Stump11289f42009-09-09 15:08:12 +00005947
Douglas Gregora16548e2009-08-11 05:31:07 +00005948template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005949ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005950TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005951 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005952}
Mike Stump11289f42009-09-09 15:08:12 +00005953
Douglas Gregora16548e2009-08-11 05:31:07 +00005954template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005955ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005956TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005957 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005958}
Mike Stump11289f42009-09-09 15:08:12 +00005959
Douglas Gregora16548e2009-08-11 05:31:07 +00005960template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005961ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005962TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005963 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005964}
Mike Stump11289f42009-09-09 15:08:12 +00005965
Douglas Gregora16548e2009-08-11 05:31:07 +00005966template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005967ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005968TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005969 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005970}
5971
5972template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005973ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00005974TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5975 ExprResult ControllingExpr =
5976 getDerived().TransformExpr(E->getControllingExpr());
5977 if (ControllingExpr.isInvalid())
5978 return ExprError();
5979
Chris Lattner01cf8db2011-07-20 06:58:45 +00005980 SmallVector<Expr *, 4> AssocExprs;
5981 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00005982 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5983 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5984 if (TS) {
5985 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5986 if (!AssocType)
5987 return ExprError();
5988 AssocTypes.push_back(AssocType);
5989 } else {
5990 AssocTypes.push_back(0);
5991 }
5992
5993 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5994 if (AssocExpr.isInvalid())
5995 return ExprError();
5996 AssocExprs.push_back(AssocExpr.release());
5997 }
5998
5999 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6000 E->getDefaultLoc(),
6001 E->getRParenLoc(),
6002 ControllingExpr.release(),
6003 AssocTypes.data(),
6004 AssocExprs.data(),
6005 E->getNumAssocs());
6006}
6007
6008template<typename Derived>
6009ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006010TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006011 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006012 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006013 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006014
Douglas Gregora16548e2009-08-11 05:31:07 +00006015 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006016 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006017
John McCallb268a282010-08-23 23:25:46 +00006018 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006019 E->getRParen());
6020}
6021
Mike Stump11289f42009-09-09 15:08:12 +00006022template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006023ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006024TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006025 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006026 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006027 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006028
Douglas Gregora16548e2009-08-11 05:31:07 +00006029 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006030 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006031
Douglas Gregora16548e2009-08-11 05:31:07 +00006032 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6033 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006034 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006035}
Mike Stump11289f42009-09-09 15:08:12 +00006036
Douglas Gregora16548e2009-08-11 05:31:07 +00006037template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006038ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006039TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6040 // Transform the type.
6041 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6042 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00006043 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006044
Douglas Gregor882211c2010-04-28 22:16:22 +00006045 // Transform all of the components into components similar to what the
6046 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006047 // FIXME: It would be slightly more efficient in the non-dependent case to
6048 // just map FieldDecls, rather than requiring the rebuilder to look for
6049 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006050 // template code that we don't care.
6051 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006052 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006053 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006054 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006055 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6056 const Node &ON = E->getComponent(I);
6057 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006058 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006059 Comp.LocStart = ON.getSourceRange().getBegin();
6060 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006061 switch (ON.getKind()) {
6062 case Node::Array: {
6063 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006064 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006065 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006066 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006067
Douglas Gregor882211c2010-04-28 22:16:22 +00006068 ExprChanged = ExprChanged || Index.get() != FromIndex;
6069 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006070 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006071 break;
6072 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006073
Douglas Gregor882211c2010-04-28 22:16:22 +00006074 case Node::Field:
6075 case Node::Identifier:
6076 Comp.isBrackets = false;
6077 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006078 if (!Comp.U.IdentInfo)
6079 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006080
Douglas Gregor882211c2010-04-28 22:16:22 +00006081 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006082
Douglas Gregord1702062010-04-29 00:18:15 +00006083 case Node::Base:
6084 // Will be recomputed during the rebuild.
6085 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006086 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006087
Douglas Gregor882211c2010-04-28 22:16:22 +00006088 Components.push_back(Comp);
6089 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006090
Douglas Gregor882211c2010-04-28 22:16:22 +00006091 // If nothing changed, retain the existing expression.
6092 if (!getDerived().AlwaysRebuild() &&
6093 Type == E->getTypeSourceInfo() &&
6094 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006095 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006096
Douglas Gregor882211c2010-04-28 22:16:22 +00006097 // Build a new offsetof expression.
6098 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6099 Components.data(), Components.size(),
6100 E->getRParenLoc());
6101}
6102
6103template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006104ExprResult
John McCall8d69a212010-11-15 23:31:06 +00006105TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6106 assert(getDerived().AlreadyTransformed(E->getType()) &&
6107 "opaque value expression requires transformation");
6108 return SemaRef.Owned(E);
6109}
6110
6111template<typename Derived>
6112ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00006113TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6114 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006115 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006116 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006117
John McCallbcd03502009-12-07 02:54:59 +00006118 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006119 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006120 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006121
John McCall4c98fd82009-11-04 07:28:41 +00006122 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00006123 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006124
Peter Collingbournee190dee2011-03-11 19:24:49 +00006125 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6126 E->getKind(),
6127 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006128 }
Mike Stump11289f42009-09-09 15:08:12 +00006129
John McCalldadc5752010-08-24 06:29:42 +00006130 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00006131 {
Douglas Gregora16548e2009-08-11 05:31:07 +00006132 // C++0x [expr.sizeof]p1:
6133 // The operand is either an expression, which is an unevaluated operand
6134 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00006135 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006136
Douglas Gregora16548e2009-08-11 05:31:07 +00006137 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6138 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006139 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006140
Douglas Gregora16548e2009-08-11 05:31:07 +00006141 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00006142 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006143 }
Mike Stump11289f42009-09-09 15:08:12 +00006144
Peter Collingbournee190dee2011-03-11 19:24:49 +00006145 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6146 E->getOperatorLoc(),
6147 E->getKind(),
6148 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006149}
Mike Stump11289f42009-09-09 15:08:12 +00006150
Douglas Gregora16548e2009-08-11 05:31:07 +00006151template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006152ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006153TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006154 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006155 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006156 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006157
John McCalldadc5752010-08-24 06:29:42 +00006158 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006159 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006160 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006161
6162
Douglas Gregora16548e2009-08-11 05:31:07 +00006163 if (!getDerived().AlwaysRebuild() &&
6164 LHS.get() == E->getLHS() &&
6165 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006166 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006167
John McCallb268a282010-08-23 23:25:46 +00006168 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006169 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006170 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006171 E->getRBracketLoc());
6172}
Mike Stump11289f42009-09-09 15:08:12 +00006173
6174template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006175ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006176TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006177 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006178 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006179 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006180 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006181
6182 // Transform arguments.
6183 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006184 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006185 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6186 &ArgChanged))
6187 return ExprError();
6188
Douglas Gregora16548e2009-08-11 05:31:07 +00006189 if (!getDerived().AlwaysRebuild() &&
6190 Callee.get() == E->getCallee() &&
6191 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006192 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006193
Douglas Gregora16548e2009-08-11 05:31:07 +00006194 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006195 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006196 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006197 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006198 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006199 E->getRParenLoc());
6200}
Mike Stump11289f42009-09-09 15:08:12 +00006201
6202template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006203ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006204TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006205 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006206 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006207 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006208
Douglas Gregorea972d32011-02-28 21:54:11 +00006209 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006210 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006211 QualifierLoc
6212 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6213
6214 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006215 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006216 }
Mike Stump11289f42009-09-09 15:08:12 +00006217
Eli Friedman2cfcef62009-12-04 06:40:45 +00006218 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006219 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6220 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006221 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006222 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006223
John McCall16df1e52010-03-30 21:47:33 +00006224 NamedDecl *FoundDecl = E->getFoundDecl();
6225 if (FoundDecl == E->getMemberDecl()) {
6226 FoundDecl = Member;
6227 } else {
6228 FoundDecl = cast_or_null<NamedDecl>(
6229 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6230 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006231 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006232 }
6233
Douglas Gregora16548e2009-08-11 05:31:07 +00006234 if (!getDerived().AlwaysRebuild() &&
6235 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006236 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006237 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006238 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006239 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006240
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006241 // Mark it referenced in the new context regardless.
6242 // FIXME: this is a bit instantiation-specific.
6243 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00006244 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006245 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006246
John McCall6b51f282009-11-23 01:53:49 +00006247 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006248 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006249 TransArgs.setLAngleLoc(E->getLAngleLoc());
6250 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006251 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6252 E->getNumTemplateArgs(),
6253 TransArgs))
6254 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006255 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006256
Douglas Gregora16548e2009-08-11 05:31:07 +00006257 // FIXME: Bogus source location for the operator
6258 SourceLocation FakeOperatorLoc
6259 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6260
John McCall38836f02010-01-15 08:34:02 +00006261 // FIXME: to do this check properly, we will need to preserve the
6262 // first-qualifier-in-scope here, just in case we had a dependent
6263 // base (and therefore couldn't do the check) and a
6264 // nested-name-qualifier (and therefore could do the lookup).
6265 NamedDecl *FirstQualifierInScope = 0;
6266
John McCallb268a282010-08-23 23:25:46 +00006267 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006268 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006269 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006270 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006271 Member,
John McCall16df1e52010-03-30 21:47:33 +00006272 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006273 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006274 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006275 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006276}
Mike Stump11289f42009-09-09 15:08:12 +00006277
Douglas Gregora16548e2009-08-11 05:31:07 +00006278template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006279ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006280TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006281 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006282 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006283 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006284
John McCalldadc5752010-08-24 06:29:42 +00006285 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006286 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006287 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006288
Douglas Gregora16548e2009-08-11 05:31:07 +00006289 if (!getDerived().AlwaysRebuild() &&
6290 LHS.get() == E->getLHS() &&
6291 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006292 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006293
Douglas Gregora16548e2009-08-11 05:31:07 +00006294 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006295 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006296}
6297
Mike Stump11289f42009-09-09 15:08:12 +00006298template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006299ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006300TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006301 CompoundAssignOperator *E) {
6302 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006303}
Mike Stump11289f42009-09-09 15:08:12 +00006304
Douglas Gregora16548e2009-08-11 05:31:07 +00006305template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006306ExprResult TreeTransform<Derived>::
6307TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6308 // Just rebuild the common and RHS expressions and see whether we
6309 // get any changes.
6310
6311 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6312 if (commonExpr.isInvalid())
6313 return ExprError();
6314
6315 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6316 if (rhs.isInvalid())
6317 return ExprError();
6318
6319 if (!getDerived().AlwaysRebuild() &&
6320 commonExpr.get() == e->getCommon() &&
6321 rhs.get() == e->getFalseExpr())
6322 return SemaRef.Owned(e);
6323
6324 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6325 e->getQuestionLoc(),
6326 0,
6327 e->getColonLoc(),
6328 rhs.get());
6329}
6330
6331template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006332ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006333TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006334 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006335 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006336 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006337
John McCalldadc5752010-08-24 06:29:42 +00006338 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006339 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006340 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006341
John McCalldadc5752010-08-24 06:29:42 +00006342 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006343 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006344 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006345
Douglas Gregora16548e2009-08-11 05:31:07 +00006346 if (!getDerived().AlwaysRebuild() &&
6347 Cond.get() == E->getCond() &&
6348 LHS.get() == E->getLHS() &&
6349 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006350 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006351
John McCallb268a282010-08-23 23:25:46 +00006352 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006353 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006354 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006355 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006356 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006357}
Mike Stump11289f42009-09-09 15:08:12 +00006358
6359template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006360ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006361TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006362 // Implicit casts are eliminated during transformation, since they
6363 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006364 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006365}
Mike Stump11289f42009-09-09 15:08:12 +00006366
Douglas Gregora16548e2009-08-11 05:31:07 +00006367template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006368ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006369TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006370 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6371 if (!Type)
6372 return ExprError();
6373
John McCalldadc5752010-08-24 06:29:42 +00006374 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006375 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006376 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006377 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006378
Douglas Gregora16548e2009-08-11 05:31:07 +00006379 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006380 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006381 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006382 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006383
John McCall97513962010-01-15 18:39:57 +00006384 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006385 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006386 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006387 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006388}
Mike Stump11289f42009-09-09 15:08:12 +00006389
Douglas Gregora16548e2009-08-11 05:31:07 +00006390template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006391ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006392TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006393 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6394 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6395 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006396 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006397
John McCalldadc5752010-08-24 06:29:42 +00006398 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006399 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006400 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006401
Douglas Gregora16548e2009-08-11 05:31:07 +00006402 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006403 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006404 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00006405 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006406
John McCall5d7aa7f2010-01-19 22:33:45 +00006407 // Note: the expression type doesn't necessarily match the
6408 // type-as-written, but that's okay, because it should always be
6409 // derivable from the initializer.
6410
John McCalle15bbff2010-01-18 19:35:47 +00006411 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006412 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006413 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006414}
Mike Stump11289f42009-09-09 15:08:12 +00006415
Douglas Gregora16548e2009-08-11 05:31:07 +00006416template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006417ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006418TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006419 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006420 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006421 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006422
Douglas Gregora16548e2009-08-11 05:31:07 +00006423 if (!getDerived().AlwaysRebuild() &&
6424 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006425 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006426
Douglas Gregora16548e2009-08-11 05:31:07 +00006427 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00006428 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006429 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00006430 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006431 E->getAccessorLoc(),
6432 E->getAccessor());
6433}
Mike Stump11289f42009-09-09 15:08:12 +00006434
Douglas Gregora16548e2009-08-11 05:31:07 +00006435template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006436ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006437TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006438 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00006439
John McCall37ad5512010-08-23 06:44:23 +00006440 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006441 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6442 Inits, &InitChanged))
6443 return ExprError();
6444
Douglas Gregora16548e2009-08-11 05:31:07 +00006445 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00006446 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006447
Douglas Gregora16548e2009-08-11 05:31:07 +00006448 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00006449 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00006450}
Mike Stump11289f42009-09-09 15:08:12 +00006451
Douglas Gregora16548e2009-08-11 05:31:07 +00006452template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006453ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006454TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006455 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00006456
Douglas Gregorebe10102009-08-20 07:17:43 +00006457 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00006458 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006459 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006460 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006461
Douglas Gregorebe10102009-08-20 07:17:43 +00006462 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00006463 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006464 bool ExprChanged = false;
6465 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6466 DEnd = E->designators_end();
6467 D != DEnd; ++D) {
6468 if (D->isFieldDesignator()) {
6469 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6470 D->getDotLoc(),
6471 D->getFieldLoc()));
6472 continue;
6473 }
Mike Stump11289f42009-09-09 15:08:12 +00006474
Douglas Gregora16548e2009-08-11 05:31:07 +00006475 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00006476 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006477 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006478 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006479
6480 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006481 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006482
Douglas Gregora16548e2009-08-11 05:31:07 +00006483 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6484 ArrayExprs.push_back(Index.release());
6485 continue;
6486 }
Mike Stump11289f42009-09-09 15:08:12 +00006487
Douglas Gregora16548e2009-08-11 05:31:07 +00006488 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00006489 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00006490 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6491 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006492 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006493
John McCalldadc5752010-08-24 06:29:42 +00006494 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006495 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006496 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006497
6498 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006499 End.get(),
6500 D->getLBracketLoc(),
6501 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006502
Douglas Gregora16548e2009-08-11 05:31:07 +00006503 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6504 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00006505
Douglas Gregora16548e2009-08-11 05:31:07 +00006506 ArrayExprs.push_back(Start.release());
6507 ArrayExprs.push_back(End.release());
6508 }
Mike Stump11289f42009-09-09 15:08:12 +00006509
Douglas Gregora16548e2009-08-11 05:31:07 +00006510 if (!getDerived().AlwaysRebuild() &&
6511 Init.get() == E->getInit() &&
6512 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006513 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006514
Douglas Gregora16548e2009-08-11 05:31:07 +00006515 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6516 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006517 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006518}
Mike Stump11289f42009-09-09 15:08:12 +00006519
Douglas Gregora16548e2009-08-11 05:31:07 +00006520template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006521ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006522TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006523 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00006524 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006525
Douglas Gregor3da3c062009-10-28 00:29:27 +00006526 // FIXME: Will we ever have proper type location here? Will we actually
6527 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00006528 QualType T = getDerived().TransformType(E->getType());
6529 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006530 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006531
Douglas Gregora16548e2009-08-11 05:31:07 +00006532 if (!getDerived().AlwaysRebuild() &&
6533 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006534 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006535
Douglas Gregora16548e2009-08-11 05:31:07 +00006536 return getDerived().RebuildImplicitValueInitExpr(T);
6537}
Mike Stump11289f42009-09-09 15:08:12 +00006538
Douglas Gregora16548e2009-08-11 05:31:07 +00006539template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006540ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006541TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00006542 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6543 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006544 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006545
John McCalldadc5752010-08-24 06:29:42 +00006546 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006547 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006548 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006549
Douglas Gregora16548e2009-08-11 05:31:07 +00006550 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00006551 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006552 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006553 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006554
John McCallb268a282010-08-23 23:25:46 +00006555 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00006556 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006557}
6558
6559template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006560ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006561TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006562 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006563 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006564 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6565 &ArgumentChanged))
6566 return ExprError();
6567
Douglas Gregora16548e2009-08-11 05:31:07 +00006568 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6569 move_arg(Inits),
6570 E->getRParenLoc());
6571}
Mike Stump11289f42009-09-09 15:08:12 +00006572
Douglas Gregora16548e2009-08-11 05:31:07 +00006573/// \brief Transform an address-of-label expression.
6574///
6575/// By default, the transformation of an address-of-label expression always
6576/// rebuilds the expression, so that the label identifier can be resolved to
6577/// the corresponding label statement by semantic analysis.
6578template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006579ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006580TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006581 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6582 E->getLabel());
6583 if (!LD)
6584 return ExprError();
6585
Douglas Gregora16548e2009-08-11 05:31:07 +00006586 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006587 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006588}
Mike Stump11289f42009-09-09 15:08:12 +00006589
6590template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006591ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006592TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006593 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006594 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6595 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006596 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006597
Douglas Gregora16548e2009-08-11 05:31:07 +00006598 if (!getDerived().AlwaysRebuild() &&
6599 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006600 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006601
6602 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006603 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006604 E->getRParenLoc());
6605}
Mike Stump11289f42009-09-09 15:08:12 +00006606
Douglas Gregora16548e2009-08-11 05:31:07 +00006607template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006608ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006609TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006610 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006611 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006612 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006613
John McCalldadc5752010-08-24 06:29:42 +00006614 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006615 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006616 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006617
John McCalldadc5752010-08-24 06:29:42 +00006618 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006619 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006620 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006621
Douglas Gregora16548e2009-08-11 05:31:07 +00006622 if (!getDerived().AlwaysRebuild() &&
6623 Cond.get() == E->getCond() &&
6624 LHS.get() == E->getLHS() &&
6625 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006626 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006627
Douglas Gregora16548e2009-08-11 05:31:07 +00006628 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006629 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006630 E->getRParenLoc());
6631}
Mike Stump11289f42009-09-09 15:08:12 +00006632
Douglas Gregora16548e2009-08-11 05:31:07 +00006633template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006634ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006635TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006636 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006637}
6638
6639template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006640ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006641TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006642 switch (E->getOperator()) {
6643 case OO_New:
6644 case OO_Delete:
6645 case OO_Array_New:
6646 case OO_Array_Delete:
6647 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006648 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006649
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006650 case OO_Call: {
6651 // This is a call to an object's operator().
6652 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6653
6654 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006655 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006656 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006657 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006658
6659 // FIXME: Poor location information
6660 SourceLocation FakeLParenLoc
6661 = SemaRef.PP.getLocForEndOfToken(
6662 static_cast<Expr *>(Object.get())->getLocEnd());
6663
6664 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006665 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006666 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6667 Args))
6668 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006669
John McCallb268a282010-08-23 23:25:46 +00006670 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006671 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006672 E->getLocEnd());
6673 }
6674
6675#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6676 case OO_##Name:
6677#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6678#include "clang/Basic/OperatorKinds.def"
6679 case OO_Subscript:
6680 // Handled below.
6681 break;
6682
6683 case OO_Conditional:
6684 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006685 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006686
6687 case OO_None:
6688 case NUM_OVERLOADED_OPERATORS:
6689 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006690 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006691 }
6692
John McCalldadc5752010-08-24 06:29:42 +00006693 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006694 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006695 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006696
John McCalldadc5752010-08-24 06:29:42 +00006697 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006698 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006699 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006700
John McCalldadc5752010-08-24 06:29:42 +00006701 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006702 if (E->getNumArgs() == 2) {
6703 Second = getDerived().TransformExpr(E->getArg(1));
6704 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006705 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006706 }
Mike Stump11289f42009-09-09 15:08:12 +00006707
Douglas Gregora16548e2009-08-11 05:31:07 +00006708 if (!getDerived().AlwaysRebuild() &&
6709 Callee.get() == E->getCallee() &&
6710 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006711 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006712 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006713
Douglas Gregora16548e2009-08-11 05:31:07 +00006714 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6715 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006716 Callee.get(),
6717 First.get(),
6718 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006719}
Mike Stump11289f42009-09-09 15:08:12 +00006720
Douglas Gregora16548e2009-08-11 05:31:07 +00006721template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006722ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006723TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6724 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006725}
Mike Stump11289f42009-09-09 15:08:12 +00006726
Douglas Gregora16548e2009-08-11 05:31:07 +00006727template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006728ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006729TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6730 // Transform the callee.
6731 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6732 if (Callee.isInvalid())
6733 return ExprError();
6734
6735 // Transform exec config.
6736 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6737 if (EC.isInvalid())
6738 return ExprError();
6739
6740 // Transform arguments.
6741 bool ArgChanged = false;
6742 ASTOwningVector<Expr*> Args(SemaRef);
6743 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6744 &ArgChanged))
6745 return ExprError();
6746
6747 if (!getDerived().AlwaysRebuild() &&
6748 Callee.get() == E->getCallee() &&
6749 !ArgChanged)
6750 return SemaRef.Owned(E);
6751
6752 // FIXME: Wrong source location information for the '('.
6753 SourceLocation FakeLParenLoc
6754 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6755 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6756 move_arg(Args),
6757 E->getRParenLoc(), EC.get());
6758}
6759
6760template<typename Derived>
6761ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006762TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006763 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6764 if (!Type)
6765 return ExprError();
6766
John McCalldadc5752010-08-24 06:29:42 +00006767 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006768 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006769 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006770 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006771
Douglas Gregora16548e2009-08-11 05:31:07 +00006772 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006773 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006774 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006775 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006776
Douglas Gregora16548e2009-08-11 05:31:07 +00006777 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006778 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006779 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6780 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6781 SourceLocation FakeRParenLoc
6782 = SemaRef.PP.getLocForEndOfToken(
6783 E->getSubExpr()->getSourceRange().getEnd());
6784 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006785 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006786 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006787 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006788 FakeRAngleLoc,
6789 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006790 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006791 FakeRParenLoc);
6792}
Mike Stump11289f42009-09-09 15:08:12 +00006793
Douglas Gregora16548e2009-08-11 05:31:07 +00006794template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006795ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006796TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6797 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006798}
Mike Stump11289f42009-09-09 15:08:12 +00006799
6800template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006801ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006802TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6803 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006804}
6805
Douglas Gregora16548e2009-08-11 05:31:07 +00006806template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006807ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006808TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006809 CXXReinterpretCastExpr *E) {
6810 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006811}
Mike Stump11289f42009-09-09 15:08:12 +00006812
Douglas Gregora16548e2009-08-11 05:31:07 +00006813template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006814ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006815TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6816 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006817}
Mike Stump11289f42009-09-09 15:08:12 +00006818
Douglas Gregora16548e2009-08-11 05:31:07 +00006819template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006820ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006821TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006822 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006823 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6824 if (!Type)
6825 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006826
John McCalldadc5752010-08-24 06:29:42 +00006827 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006828 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006829 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006830 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006831
Douglas Gregora16548e2009-08-11 05:31:07 +00006832 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006833 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006834 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006835 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006836
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006837 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006838 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006839 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006840 E->getRParenLoc());
6841}
Mike Stump11289f42009-09-09 15:08:12 +00006842
Douglas Gregora16548e2009-08-11 05:31:07 +00006843template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006844ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006845TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006846 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006847 TypeSourceInfo *TInfo
6848 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6849 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006850 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006851
Douglas Gregora16548e2009-08-11 05:31:07 +00006852 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006853 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006854 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006855
Douglas Gregor9da64192010-04-26 22:37:10 +00006856 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6857 E->getLocStart(),
6858 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006859 E->getLocEnd());
6860 }
Mike Stump11289f42009-09-09 15:08:12 +00006861
Douglas Gregora16548e2009-08-11 05:31:07 +00006862 // We don't know whether the expression is potentially evaluated until
6863 // after we perform semantic analysis, so the expression is potentially
6864 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006865 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006866 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006867
John McCalldadc5752010-08-24 06:29:42 +00006868 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006869 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006870 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006871
Douglas Gregora16548e2009-08-11 05:31:07 +00006872 if (!getDerived().AlwaysRebuild() &&
6873 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006874 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006875
Douglas Gregor9da64192010-04-26 22:37:10 +00006876 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6877 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006878 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006879 E->getLocEnd());
6880}
6881
6882template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006883ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006884TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6885 if (E->isTypeOperand()) {
6886 TypeSourceInfo *TInfo
6887 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6888 if (!TInfo)
6889 return ExprError();
6890
6891 if (!getDerived().AlwaysRebuild() &&
6892 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006893 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006894
Douglas Gregor69735112011-03-06 17:40:41 +00006895 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00006896 E->getLocStart(),
6897 TInfo,
6898 E->getLocEnd());
6899 }
6900
6901 // We don't know whether the expression is potentially evaluated until
6902 // after we perform semantic analysis, so the expression is potentially
6903 // potentially evaluated.
6904 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6905
6906 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6907 if (SubExpr.isInvalid())
6908 return ExprError();
6909
6910 if (!getDerived().AlwaysRebuild() &&
6911 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006912 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006913
6914 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6915 E->getLocStart(),
6916 SubExpr.get(),
6917 E->getLocEnd());
6918}
6919
6920template<typename Derived>
6921ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006922TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006923 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006924}
Mike Stump11289f42009-09-09 15:08:12 +00006925
Douglas Gregora16548e2009-08-11 05:31:07 +00006926template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006927ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006928TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006929 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006930 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006931}
Mike Stump11289f42009-09-09 15:08:12 +00006932
Douglas Gregora16548e2009-08-11 05:31:07 +00006933template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006934ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006935TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006936 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith938f40b2011-06-11 17:19:42 +00006937 QualType T;
6938 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
6939 T = MD->getThisType(getSema().Context);
6940 else
6941 T = getSema().Context.getPointerType(
6942 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump11289f42009-09-09 15:08:12 +00006943
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006944 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006945 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006946
Douglas Gregorb15af892010-01-07 23:12:05 +00006947 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006948}
Mike Stump11289f42009-09-09 15:08:12 +00006949
Douglas Gregora16548e2009-08-11 05:31:07 +00006950template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006951ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006952TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006953 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006954 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006955 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006956
Douglas Gregora16548e2009-08-11 05:31:07 +00006957 if (!getDerived().AlwaysRebuild() &&
6958 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006959 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006960
Douglas Gregor53e191ed2011-07-06 22:04:06 +00006961 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
6962 E->isThrownVariableInScope());
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>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006968 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006969 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6970 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006971 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006972 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006973
Chandler Carruth794da4c2010-02-08 06:42:49 +00006974 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006975 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006976 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006977
Douglas Gregor033f6752009-12-23 23:03:06 +00006978 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006979}
Mike Stump11289f42009-09-09 15:08:12 +00006980
Douglas Gregora16548e2009-08-11 05:31:07 +00006981template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006982ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006983TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6984 CXXScalarValueInitExpr *E) {
6985 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6986 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006987 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006988
Douglas Gregora16548e2009-08-11 05:31:07 +00006989 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006990 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006991 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006992
Douglas Gregor2b88c112010-09-08 00:15:04 +00006993 return getDerived().RebuildCXXScalarValueInitExpr(T,
6994 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006995 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006996}
Mike Stump11289f42009-09-09 15:08:12 +00006997
Douglas Gregora16548e2009-08-11 05:31:07 +00006998template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006999ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007000TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007001 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00007002 TypeSourceInfo *AllocTypeInfo
7003 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7004 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007005 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007006
Douglas Gregora16548e2009-08-11 05:31:07 +00007007 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007008 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007009 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007010 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007011
Douglas Gregora16548e2009-08-11 05:31:07 +00007012 // Transform the placement arguments (if any).
7013 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007014 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007015 if (getDerived().TransformExprs(E->getPlacementArgs(),
7016 E->getNumPlacementArgs(), true,
7017 PlacementArgs, &ArgumentChanged))
7018 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007019
Douglas Gregorf333f8c2011-10-18 02:43:19 +00007020 // Transform the constructor arguments (if any).
7021 // As an annoying corner case, we may have introduced an implicit value-
7022 // initialization expression when allocating a new array, which we implicitly
7023 // drop. It will be re-created during type checking.
John McCall37ad5512010-08-23 06:44:23 +00007024 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregorf333f8c2011-10-18 02:43:19 +00007025 if (!(E->isArray() && E->getNumConstructorArgs() == 1 &&
7026 isa<ImplicitValueInitExpr>(E->getConstructorArgs()[0])) &&
7027 TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007028 ConstructorArgs, &ArgumentChanged))
7029 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007030
Douglas Gregord2d9da02010-02-26 00:38:10 +00007031 // Transform constructor, new operator, and delete operator.
7032 CXXConstructorDecl *Constructor = 0;
7033 if (E->getConstructor()) {
7034 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007035 getDerived().TransformDecl(E->getLocStart(),
7036 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007037 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007038 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007039 }
7040
7041 FunctionDecl *OperatorNew = 0;
7042 if (E->getOperatorNew()) {
7043 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007044 getDerived().TransformDecl(E->getLocStart(),
7045 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007046 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007047 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007048 }
7049
7050 FunctionDecl *OperatorDelete = 0;
7051 if (E->getOperatorDelete()) {
7052 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007053 getDerived().TransformDecl(E->getLocStart(),
7054 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007055 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007056 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007057 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007058
Douglas Gregora16548e2009-08-11 05:31:07 +00007059 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00007060 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007061 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007062 Constructor == E->getConstructor() &&
7063 OperatorNew == E->getOperatorNew() &&
7064 OperatorDelete == E->getOperatorDelete() &&
7065 !ArgumentChanged) {
7066 // Mark any declarations we need as referenced.
7067 // FIXME: instantiation-specific.
7068 if (Constructor)
7069 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
7070 if (OperatorNew)
7071 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
7072 if (OperatorDelete)
7073 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor72912fb2011-07-26 15:11:03 +00007074
7075 if (E->isArray() && Constructor &&
7076 !E->getAllocatedType()->isDependentType()) {
7077 QualType ElementType
7078 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7079 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7080 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7081 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
7082 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Destructor);
7083 }
7084 }
7085 }
7086
John McCallc3007a22010-10-26 07:05:15 +00007087 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007088 }
Mike Stump11289f42009-09-09 15:08:12 +00007089
Douglas Gregor0744ef62010-09-07 21:49:58 +00007090 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007091 if (!ArraySize.get()) {
7092 // If no array size was specified, but the new expression was
7093 // instantiated with an array type (e.g., "new T" where T is
7094 // instantiated with "int[4]"), extract the outer bound from the
7095 // array type as our array size. We do this with constant and
7096 // dependently-sized array types.
7097 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7098 if (!ArrayT) {
7099 // Do nothing
7100 } else if (const ConstantArrayType *ConsArrayT
7101 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007102 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007103 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7104 ConsArrayT->getSize(),
7105 SemaRef.Context.getSizeType(),
7106 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007107 AllocType = ConsArrayT->getElementType();
7108 } else if (const DependentSizedArrayType *DepArrayT
7109 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7110 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00007111 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007112 AllocType = DepArrayT->getElementType();
7113 }
7114 }
7115 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00007116
Douglas Gregora16548e2009-08-11 05:31:07 +00007117 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7118 E->isGlobalNew(),
7119 /*FIXME:*/E->getLocStart(),
7120 move_arg(PlacementArgs),
7121 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007122 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007123 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007124 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007125 ArraySize.get(),
Douglas Gregorf333f8c2011-10-18 02:43:19 +00007126 E->getConstructorLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007127 move_arg(ConstructorArgs),
Douglas Gregorf333f8c2011-10-18 02:43:19 +00007128 E->getConstructorRParen());
Douglas Gregora16548e2009-08-11 05:31:07 +00007129}
Mike Stump11289f42009-09-09 15:08:12 +00007130
Douglas Gregora16548e2009-08-11 05:31:07 +00007131template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007132ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007133TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007134 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007135 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007136 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007137
Douglas Gregord2d9da02010-02-26 00:38:10 +00007138 // Transform the delete operator, if known.
7139 FunctionDecl *OperatorDelete = 0;
7140 if (E->getOperatorDelete()) {
7141 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007142 getDerived().TransformDecl(E->getLocStart(),
7143 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007144 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007145 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007146 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007147
Douglas Gregora16548e2009-08-11 05:31:07 +00007148 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007149 Operand.get() == E->getArgument() &&
7150 OperatorDelete == E->getOperatorDelete()) {
7151 // Mark any declarations we need as referenced.
7152 // FIXME: instantiation-specific.
7153 if (OperatorDelete)
7154 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007155
7156 if (!E->getArgument()->isTypeDependent()) {
7157 QualType Destroyed = SemaRef.Context.getBaseElementType(
7158 E->getDestroyedType());
7159 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7160 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
7161 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
7162 SemaRef.LookupDestructor(Record));
7163 }
7164 }
7165
John McCallc3007a22010-10-26 07:05:15 +00007166 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007167 }
Mike Stump11289f42009-09-09 15:08:12 +00007168
Douglas Gregora16548e2009-08-11 05:31:07 +00007169 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7170 E->isGlobalDelete(),
7171 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007172 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007173}
Mike Stump11289f42009-09-09 15:08:12 +00007174
Douglas Gregora16548e2009-08-11 05:31:07 +00007175template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007176ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007177TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007178 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007179 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007180 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007181 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007182
John McCallba7bf592010-08-24 05:47:05 +00007183 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007184 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007185 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007186 E->getOperatorLoc(),
7187 E->isArrow()? tok::arrow : tok::period,
7188 ObjectTypePtr,
7189 MayBePseudoDestructor);
7190 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007191 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007192
John McCallba7bf592010-08-24 05:47:05 +00007193 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007194 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7195 if (QualifierLoc) {
7196 QualifierLoc
7197 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7198 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007199 return ExprError();
7200 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007201 CXXScopeSpec SS;
7202 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007203
Douglas Gregor678f90d2010-02-25 01:56:36 +00007204 PseudoDestructorTypeStorage Destroyed;
7205 if (E->getDestroyedTypeInfo()) {
7206 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007207 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00007208 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007209 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007210 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007211 Destroyed = DestroyedTypeInfo;
7212 } else if (ObjectType->isDependentType()) {
7213 // We aren't likely to be able to resolve the identifier down to a type
7214 // now anyway, so just retain the identifier.
7215 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7216 E->getDestroyedTypeLoc());
7217 } else {
7218 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007219 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007220 *E->getDestroyedTypeIdentifier(),
7221 E->getDestroyedTypeLoc(),
7222 /*Scope=*/0,
7223 SS, ObjectTypePtr,
7224 false);
7225 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007226 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007227
Douglas Gregor678f90d2010-02-25 01:56:36 +00007228 Destroyed
7229 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7230 E->getDestroyedTypeLoc());
7231 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007232
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007233 TypeSourceInfo *ScopeTypeInfo = 0;
7234 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00007235 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007236 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007237 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007238 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007239
John McCallb268a282010-08-23 23:25:46 +00007240 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007241 E->getOperatorLoc(),
7242 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007243 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007244 ScopeTypeInfo,
7245 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007246 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007247 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007248}
Mike Stump11289f42009-09-09 15:08:12 +00007249
Douglas Gregorad8a3362009-09-04 17:36:40 +00007250template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007251ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007252TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007253 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007254 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7255 Sema::LookupOrdinaryName);
7256
7257 // Transform all the decls.
7258 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7259 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007260 NamedDecl *InstD = static_cast<NamedDecl*>(
7261 getDerived().TransformDecl(Old->getNameLoc(),
7262 *I));
John McCall84d87672009-12-10 09:41:52 +00007263 if (!InstD) {
7264 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7265 // This can happen because of dependent hiding.
7266 if (isa<UsingShadowDecl>(*I))
7267 continue;
7268 else
John McCallfaf5fb42010-08-26 23:41:50 +00007269 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00007270 }
John McCalle66edc12009-11-24 19:00:30 +00007271
7272 // Expand using declarations.
7273 if (isa<UsingDecl>(InstD)) {
7274 UsingDecl *UD = cast<UsingDecl>(InstD);
7275 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7276 E = UD->shadow_end(); I != E; ++I)
7277 R.addDecl(*I);
7278 continue;
7279 }
7280
7281 R.addDecl(InstD);
7282 }
7283
7284 // Resolve a kind, but don't do any further analysis. If it's
7285 // ambiguous, the callee needs to deal with it.
7286 R.resolveKind();
7287
7288 // Rebuild the nested-name qualifier, if present.
7289 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007290 if (Old->getQualifierLoc()) {
7291 NestedNameSpecifierLoc QualifierLoc
7292 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7293 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007294 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007295
Douglas Gregor0da1d432011-02-28 20:01:57 +00007296 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007297 }
7298
Douglas Gregor9262f472010-04-27 18:19:34 +00007299 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007300 CXXRecordDecl *NamingClass
7301 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7302 Old->getNameLoc(),
7303 Old->getNamingClass()));
7304 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007305 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007306
Douglas Gregorda7be082010-04-27 16:10:10 +00007307 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007308 }
7309
7310 // If we have no template arguments, it's a normal declaration name.
7311 if (!Old->hasExplicitTemplateArgs())
7312 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7313
7314 // If we have template arguments, rebuild them, then rebuild the
7315 // templateid expression.
7316 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007317 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7318 Old->getNumTemplateArgs(),
7319 TransArgs))
7320 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00007321
7322 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7323 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007324}
Mike Stump11289f42009-09-09 15:08:12 +00007325
Douglas Gregora16548e2009-08-11 05:31:07 +00007326template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007327ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007328TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00007329 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7330 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007331 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007332
Douglas Gregora16548e2009-08-11 05:31:07 +00007333 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00007334 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007335 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007336
Mike Stump11289f42009-09-09 15:08:12 +00007337 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007338 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007339 T,
7340 E->getLocEnd());
7341}
Mike Stump11289f42009-09-09 15:08:12 +00007342
Douglas Gregora16548e2009-08-11 05:31:07 +00007343template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007344ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00007345TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7346 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7347 if (!LhsT)
7348 return ExprError();
7349
7350 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7351 if (!RhsT)
7352 return ExprError();
7353
7354 if (!getDerived().AlwaysRebuild() &&
7355 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7356 return SemaRef.Owned(E);
7357
7358 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7359 E->getLocStart(),
7360 LhsT, RhsT,
7361 E->getLocEnd());
7362}
7363
7364template<typename Derived>
7365ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00007366TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7367 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7368 if (!T)
7369 return ExprError();
7370
7371 if (!getDerived().AlwaysRebuild() &&
7372 T == E->getQueriedTypeSourceInfo())
7373 return SemaRef.Owned(E);
7374
7375 ExprResult SubExpr;
7376 {
7377 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7378 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7379 if (SubExpr.isInvalid())
7380 return ExprError();
7381
7382 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7383 return SemaRef.Owned(E);
7384 }
7385
7386 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7387 E->getLocStart(),
7388 T,
7389 SubExpr.get(),
7390 E->getLocEnd());
7391}
7392
7393template<typename Derived>
7394ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00007395TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7396 ExprResult SubExpr;
7397 {
7398 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7399 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7400 if (SubExpr.isInvalid())
7401 return ExprError();
7402
7403 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7404 return SemaRef.Owned(E);
7405 }
7406
7407 return getDerived().RebuildExpressionTrait(
7408 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7409}
7410
7411template<typename Derived>
7412ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007413TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007414 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007415 NestedNameSpecifierLoc QualifierLoc
7416 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7417 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007418 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007419
John McCall31f82722010-11-12 08:19:04 +00007420 // TODO: If this is a conversion-function-id, verify that the
7421 // destination type name (if present) resolves the same way after
7422 // instantiation as it did in the local scope.
7423
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007424 DeclarationNameInfo NameInfo
7425 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7426 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007427 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007428
John McCalle66edc12009-11-24 19:00:30 +00007429 if (!E->hasExplicitTemplateArgs()) {
7430 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007431 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007432 // Note: it is sufficient to compare the Name component of NameInfo:
7433 // if name has not changed, DNLoc has not changed either.
7434 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00007435 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007436
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007437 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007438 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007439 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00007440 }
John McCall6b51f282009-11-23 01:53:49 +00007441
7442 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007443 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7444 E->getNumTemplateArgs(),
7445 TransArgs))
7446 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007447
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007448 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007449 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007450 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007451}
7452
7453template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007454ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007455TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00007456 // CXXConstructExprs are always implicit, so when we have a
7457 // 1-argument construction we just transform that argument.
7458 if (E->getNumArgs() == 1 ||
7459 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7460 return getDerived().TransformExpr(E->getArg(0));
7461
Douglas Gregora16548e2009-08-11 05:31:07 +00007462 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7463
7464 QualType T = getDerived().TransformType(E->getType());
7465 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007466 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007467
7468 CXXConstructorDecl *Constructor
7469 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007470 getDerived().TransformDecl(E->getLocStart(),
7471 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007472 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007473 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007474
Douglas Gregora16548e2009-08-11 05:31:07 +00007475 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007476 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007477 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7478 &ArgumentChanged))
7479 return ExprError();
7480
Douglas Gregora16548e2009-08-11 05:31:07 +00007481 if (!getDerived().AlwaysRebuild() &&
7482 T == E->getType() &&
7483 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00007484 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00007485 // Mark the constructor as referenced.
7486 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00007487 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007488 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00007489 }
Mike Stump11289f42009-09-09 15:08:12 +00007490
Douglas Gregordb121ba2009-12-14 16:27:04 +00007491 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7492 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00007493 move_arg(Args),
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00007494 E->hadMultipleCandidates(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00007495 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00007496 E->getConstructionKind(),
7497 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007498}
Mike Stump11289f42009-09-09 15:08:12 +00007499
Douglas Gregora16548e2009-08-11 05:31:07 +00007500/// \brief Transform a C++ temporary-binding expression.
7501///
Douglas Gregor363b1512009-12-24 18:51:59 +00007502/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7503/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007504template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007505ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007506TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007507 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007508}
Mike Stump11289f42009-09-09 15:08:12 +00007509
John McCall5d413782010-12-06 08:20:24 +00007510/// \brief Transform a C++ expression that contains cleanups that should
7511/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00007512///
John McCall5d413782010-12-06 08:20:24 +00007513/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00007514/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007515template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007516ExprResult
John McCall5d413782010-12-06 08:20:24 +00007517TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007518 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007519}
Mike Stump11289f42009-09-09 15:08:12 +00007520
Douglas Gregora16548e2009-08-11 05:31:07 +00007521template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007522ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007523TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00007524 CXXTemporaryObjectExpr *E) {
7525 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7526 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007527 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007528
Douglas Gregora16548e2009-08-11 05:31:07 +00007529 CXXConstructorDecl *Constructor
7530 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00007531 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007532 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007533 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007534 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007535
Douglas Gregora16548e2009-08-11 05:31:07 +00007536 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007537 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00007538 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00007539 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7540 &ArgumentChanged))
7541 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007542
Douglas Gregora16548e2009-08-11 05:31:07 +00007543 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007544 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007545 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007546 !ArgumentChanged) {
7547 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00007548 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007549 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007550 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00007551
7552 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7553 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007554 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007555 E->getLocEnd());
7556}
Mike Stump11289f42009-09-09 15:08:12 +00007557
Douglas Gregora16548e2009-08-11 05:31:07 +00007558template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007559ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007560TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007561 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00007562 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7563 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007564 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007565
Douglas Gregora16548e2009-08-11 05:31:07 +00007566 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007567 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007568 Args.reserve(E->arg_size());
7569 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7570 &ArgumentChanged))
7571 return ExprError();
7572
Douglas Gregora16548e2009-08-11 05:31:07 +00007573 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007574 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007575 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007576 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007577
Douglas Gregora16548e2009-08-11 05:31:07 +00007578 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00007579 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00007580 E->getLParenLoc(),
7581 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007582 E->getRParenLoc());
7583}
Mike Stump11289f42009-09-09 15:08:12 +00007584
Douglas Gregora16548e2009-08-11 05:31:07 +00007585template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007586ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007587TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007588 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007589 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007590 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007591 Expr *OldBase;
7592 QualType BaseType;
7593 QualType ObjectType;
7594 if (!E->isImplicitAccess()) {
7595 OldBase = E->getBase();
7596 Base = getDerived().TransformExpr(OldBase);
7597 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007598 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007599
John McCall2d74de92009-12-01 22:10:20 +00007600 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00007601 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00007602 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007603 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007604 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007605 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00007606 ObjectTy,
7607 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00007608 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007609 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007610
John McCallba7bf592010-08-24 05:47:05 +00007611 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00007612 BaseType = ((Expr*) Base.get())->getType();
7613 } else {
7614 OldBase = 0;
7615 BaseType = getDerived().TransformType(E->getBaseType());
7616 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7617 }
Mike Stump11289f42009-09-09 15:08:12 +00007618
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007619 // Transform the first part of the nested-name-specifier that qualifies
7620 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007621 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007622 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00007623 E->getFirstQualifierFoundInScope(),
7624 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00007625
Douglas Gregore16af532011-02-28 18:50:33 +00007626 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007627 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00007628 QualifierLoc
7629 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7630 ObjectType,
7631 FirstQualifierInScope);
7632 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007633 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007634 }
Mike Stump11289f42009-09-09 15:08:12 +00007635
John McCall31f82722010-11-12 08:19:04 +00007636 // TODO: If this is a conversion-function-id, verify that the
7637 // destination type name (if present) resolves the same way after
7638 // instantiation as it did in the local scope.
7639
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007640 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007641 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007642 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007643 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007644
John McCall2d74de92009-12-01 22:10:20 +00007645 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007646 // This is a reference to a member without an explicitly-specified
7647 // template argument list. Optimize for this common case.
7648 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007649 Base.get() == OldBase &&
7650 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007651 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007652 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007653 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007654 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007655
John McCallb268a282010-08-23 23:25:46 +00007656 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007657 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007658 E->isArrow(),
7659 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007660 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007661 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007662 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007663 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007664 }
7665
John McCall6b51f282009-11-23 01:53:49 +00007666 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007667 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7668 E->getNumTemplateArgs(),
7669 TransArgs))
7670 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007671
John McCallb268a282010-08-23 23:25:46 +00007672 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007673 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007674 E->isArrow(),
7675 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007676 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007677 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007678 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007679 &TransArgs);
7680}
7681
7682template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007683ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007684TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007685 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007686 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007687 QualType BaseType;
7688 if (!Old->isImplicitAccess()) {
7689 Base = getDerived().TransformExpr(Old->getBase());
7690 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007691 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007692 BaseType = ((Expr*) Base.get())->getType();
7693 } else {
7694 BaseType = getDerived().TransformType(Old->getBaseType());
7695 }
John McCall10eae182009-11-30 22:42:35 +00007696
Douglas Gregor0da1d432011-02-28 20:01:57 +00007697 NestedNameSpecifierLoc QualifierLoc;
7698 if (Old->getQualifierLoc()) {
7699 QualifierLoc
7700 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7701 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007702 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007703 }
7704
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007705 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007706 Sema::LookupOrdinaryName);
7707
7708 // Transform all the decls.
7709 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7710 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007711 NamedDecl *InstD = static_cast<NamedDecl*>(
7712 getDerived().TransformDecl(Old->getMemberLoc(),
7713 *I));
John McCall84d87672009-12-10 09:41:52 +00007714 if (!InstD) {
7715 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7716 // This can happen because of dependent hiding.
7717 if (isa<UsingShadowDecl>(*I))
7718 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007719 else {
7720 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007721 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007722 }
John McCall84d87672009-12-10 09:41:52 +00007723 }
John McCall10eae182009-11-30 22:42:35 +00007724
7725 // Expand using declarations.
7726 if (isa<UsingDecl>(InstD)) {
7727 UsingDecl *UD = cast<UsingDecl>(InstD);
7728 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7729 E = UD->shadow_end(); I != E; ++I)
7730 R.addDecl(*I);
7731 continue;
7732 }
7733
7734 R.addDecl(InstD);
7735 }
7736
7737 R.resolveKind();
7738
Douglas Gregor9262f472010-04-27 18:19:34 +00007739 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007740 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007741 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007742 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007743 Old->getMemberLoc(),
7744 Old->getNamingClass()));
7745 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007746 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007747
Douglas Gregorda7be082010-04-27 16:10:10 +00007748 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007749 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007750
John McCall10eae182009-11-30 22:42:35 +00007751 TemplateArgumentListInfo TransArgs;
7752 if (Old->hasExplicitTemplateArgs()) {
7753 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7754 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007755 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7756 Old->getNumTemplateArgs(),
7757 TransArgs))
7758 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007759 }
John McCall38836f02010-01-15 08:34:02 +00007760
7761 // FIXME: to do this check properly, we will need to preserve the
7762 // first-qualifier-in-scope here, just in case we had a dependent
7763 // base (and therefore couldn't do the check) and a
7764 // nested-name-qualifier (and therefore could do the lookup).
7765 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007766
John McCallb268a282010-08-23 23:25:46 +00007767 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007768 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007769 Old->getOperatorLoc(),
7770 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007771 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007772 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007773 R,
7774 (Old->hasExplicitTemplateArgs()
7775 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007776}
7777
7778template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007779ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007780TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00007781 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007782 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7783 if (SubExpr.isInvalid())
7784 return ExprError();
7785
7786 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007787 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007788
7789 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7790}
7791
7792template<typename Derived>
7793ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007794TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007795 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7796 if (Pattern.isInvalid())
7797 return ExprError();
7798
7799 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7800 return SemaRef.Owned(E);
7801
Douglas Gregorb8840002011-01-14 21:20:45 +00007802 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7803 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007804}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007805
7806template<typename Derived>
7807ExprResult
7808TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7809 // If E is not value-dependent, then nothing will change when we transform it.
7810 // Note: This is an instantiation-centric view.
7811 if (!E->isValueDependent())
7812 return SemaRef.Owned(E);
7813
7814 // Note: None of the implementations of TryExpandParameterPacks can ever
7815 // produce a diagnostic when given only a single unexpanded parameter pack,
7816 // so
7817 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7818 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007819 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007820 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007821 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00007822 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007823 ShouldExpand, RetainExpansion,
7824 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007825 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007826
Douglas Gregorab96bcf2011-10-10 18:59:29 +00007827 if (RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007828 return SemaRef.Owned(E);
Douglas Gregorab96bcf2011-10-10 18:59:29 +00007829
7830 NamedDecl *Pack = E->getPack();
7831 if (!ShouldExpand) {
7832 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
7833 Pack));
7834 if (!Pack)
7835 return ExprError();
7836 }
7837
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007838
7839 // We now know the length of the parameter pack, so build a new expression
7840 // that stores that length.
Douglas Gregorab96bcf2011-10-10 18:59:29 +00007841 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007842 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00007843 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007844}
7845
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007846template<typename Derived>
7847ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007848TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7849 SubstNonTypeTemplateParmPackExpr *E) {
7850 // Default behavior is to do nothing with this transformation.
7851 return SemaRef.Owned(E);
7852}
7853
7854template<typename Derived>
7855ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00007856TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
7857 SubstNonTypeTemplateParmExpr *E) {
7858 // Default behavior is to do nothing with this transformation.
7859 return SemaRef.Owned(E);
7860}
7861
7862template<typename Derived>
7863ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00007864TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
7865 MaterializeTemporaryExpr *E) {
7866 return getDerived().TransformExpr(E->GetTemporaryExpr());
7867}
7868
7869template<typename Derived>
7870ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007871TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007872 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007873}
7874
Mike Stump11289f42009-09-09 15:08:12 +00007875template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007876ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007877TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007878 TypeSourceInfo *EncodedTypeInfo
7879 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7880 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007881 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007882
Douglas Gregora16548e2009-08-11 05:31:07 +00007883 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007884 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007885 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007886
7887 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007888 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007889 E->getRParenLoc());
7890}
Mike Stump11289f42009-09-09 15:08:12 +00007891
Douglas Gregora16548e2009-08-11 05:31:07 +00007892template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00007893ExprResult TreeTransform<Derived>::
7894TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7895 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7896 if (result.isInvalid()) return ExprError();
7897 Expr *subExpr = result.take();
7898
7899 if (!getDerived().AlwaysRebuild() &&
7900 subExpr == E->getSubExpr())
7901 return SemaRef.Owned(E);
7902
7903 return SemaRef.Owned(new(SemaRef.Context)
7904 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7905}
7906
7907template<typename Derived>
7908ExprResult TreeTransform<Derived>::
7909TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7910 TypeSourceInfo *TSInfo
7911 = getDerived().TransformType(E->getTypeInfoAsWritten());
7912 if (!TSInfo)
7913 return ExprError();
7914
7915 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7916 if (Result.isInvalid())
7917 return ExprError();
7918
7919 if (!getDerived().AlwaysRebuild() &&
7920 TSInfo == E->getTypeInfoAsWritten() &&
7921 Result.get() == E->getSubExpr())
7922 return SemaRef.Owned(E);
7923
7924 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
7925 E->getBridgeKeywordLoc(), TSInfo,
7926 Result.get());
7927}
7928
7929template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007930ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007931TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007932 // Transform arguments.
7933 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007934 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007935 Args.reserve(E->getNumArgs());
7936 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7937 &ArgChanged))
7938 return ExprError();
7939
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007940 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7941 // Class message: transform the receiver type.
7942 TypeSourceInfo *ReceiverTypeInfo
7943 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7944 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007945 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007946
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007947 // If nothing changed, just retain the existing message send.
7948 if (!getDerived().AlwaysRebuild() &&
7949 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007950 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007951
7952 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00007953 SmallVector<SourceLocation, 16> SelLocs;
7954 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007955 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7956 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00007957 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007958 E->getMethodDecl(),
7959 E->getLeftLoc(),
7960 move_arg(Args),
7961 E->getRightLoc());
7962 }
7963
7964 // Instance message: transform the receiver
7965 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7966 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007967 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007968 = getDerived().TransformExpr(E->getInstanceReceiver());
7969 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007970 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007971
7972 // If nothing changed, just retain the existing message send.
7973 if (!getDerived().AlwaysRebuild() &&
7974 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007975 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007976
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007977 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00007978 SmallVector<SourceLocation, 16> SelLocs;
7979 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00007980 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007981 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00007982 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007983 E->getMethodDecl(),
7984 E->getLeftLoc(),
7985 move_arg(Args),
7986 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007987}
7988
Mike Stump11289f42009-09-09 15:08:12 +00007989template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007990ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007991TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007992 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007993}
7994
Mike Stump11289f42009-09-09 15:08:12 +00007995template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007996ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007997TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007998 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007999}
8000
Mike Stump11289f42009-09-09 15:08:12 +00008001template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008002ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008003TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00008004 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00008005 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00008006 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008007 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00008008
8009 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00008010
Douglas Gregord51d90d2010-04-26 20:11:03 +00008011 // If nothing changed, just retain the existing expression.
8012 if (!getDerived().AlwaysRebuild() &&
8013 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00008014 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00008015
John McCallb268a282010-08-23 23:25:46 +00008016 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00008017 E->getLocation(),
8018 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00008019}
8020
Mike Stump11289f42009-09-09 15:08:12 +00008021template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008022ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008023TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00008024 // 'super' and types never change. Property never changes. Just
8025 // retain the existing expression.
8026 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00008027 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00008028
Douglas Gregor9faee212010-04-26 20:47:02 +00008029 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00008030 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00008031 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008032 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00008033
Douglas Gregor9faee212010-04-26 20:47:02 +00008034 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00008035
Douglas Gregor9faee212010-04-26 20:47:02 +00008036 // If nothing changed, just retain the existing expression.
8037 if (!getDerived().AlwaysRebuild() &&
8038 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00008039 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008040
John McCallb7bd14f2010-12-02 01:19:52 +00008041 if (E->isExplicitProperty())
8042 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8043 E->getExplicitProperty(),
8044 E->getLocation());
8045
8046 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8047 E->getType(),
8048 E->getImplicitPropertyGetter(),
8049 E->getImplicitPropertySetter(),
8050 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00008051}
8052
Mike Stump11289f42009-09-09 15:08:12 +00008053template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008054ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008055TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00008056 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00008057 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00008058 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008059 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00008060
Douglas Gregord51d90d2010-04-26 20:11:03 +00008061 // If nothing changed, just retain the existing expression.
8062 if (!getDerived().AlwaysRebuild() &&
8063 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00008064 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00008065
John McCallb268a282010-08-23 23:25:46 +00008066 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00008067 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00008068}
8069
Mike Stump11289f42009-09-09 15:08:12 +00008070template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008071ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008072TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008073 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00008074 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00008075 SubExprs.reserve(E->getNumSubExprs());
8076 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8077 SubExprs, &ArgumentChanged))
8078 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008079
Douglas Gregora16548e2009-08-11 05:31:07 +00008080 if (!getDerived().AlwaysRebuild() &&
8081 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00008082 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008083
Douglas Gregora16548e2009-08-11 05:31:07 +00008084 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8085 move_arg(SubExprs),
8086 E->getRParenLoc());
8087}
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>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00008092 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008093
John McCall490112f2011-02-04 18:33:18 +00008094 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8095 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8096
8097 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian4cc5df72011-05-05 17:18:12 +00008098 // We built a new blockScopeInfo in call to ActOnBlockStart
8099 // in above, CapturesCXXThis need be set here from the block
8100 // expression.
8101 blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
8102
Chris Lattner01cf8db2011-07-20 06:58:45 +00008103 SmallVector<ParmVarDecl*, 4> params;
8104 SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008105
8106 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00008107 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8108 oldBlock->param_begin(),
8109 oldBlock->param_size(),
8110 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00008111 return true;
John McCall490112f2011-02-04 18:33:18 +00008112
8113 const FunctionType *exprFunctionType = E->getFunctionType();
8114 QualType exprResultType = exprFunctionType->getResultType();
8115 if (!exprResultType.isNull()) {
8116 if (!exprResultType->isDependentType())
8117 blockScope->ReturnType = exprResultType;
8118 else if (exprResultType != getSema().Context.DependentTy)
8119 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008120 }
Douglas Gregor476e3022011-01-19 21:32:01 +00008121
8122 // If the return type has not been determined yet, leave it as a dependent
8123 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00008124 if (blockScope->ReturnType.isNull())
8125 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00008126
8127 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00008128 if (blockScope->ReturnType->isObjCObjectType()) {
8129 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00008130 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00008131 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00008132 return ExprError();
8133 }
John McCall3882ace2011-01-05 12:14:39 +00008134
John McCall490112f2011-02-04 18:33:18 +00008135 QualType functionType = getDerived().RebuildFunctionProtoType(
8136 blockScope->ReturnType,
8137 paramTypes.data(),
8138 paramTypes.size(),
8139 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00008140 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00008141 exprFunctionType->getExtInfo());
8142 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00008143
8144 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00008145 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00008146 blockScope->TheDecl->setParams(params);
Douglas Gregor476e3022011-01-19 21:32:01 +00008147
8148 // If the return type wasn't explicitly set, it will have been marked as a
8149 // dependent type (DependentTy); clear out the return type setting so
8150 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00008151 if (blockScope->ReturnType == getSema().Context.DependentTy)
8152 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00008153
John McCall3882ace2011-01-05 12:14:39 +00008154 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00008155 StmtResult body = getDerived().TransformStmt(E->getBody());
8156 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00008157 return ExprError();
8158
John McCall490112f2011-02-04 18:33:18 +00008159#ifndef NDEBUG
8160 // In builds with assertions, make sure that we captured everything we
8161 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00008162 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8163 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8164 e = oldBlock->capture_end(); i != e; ++i) {
8165 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00008166
Douglas Gregor4385d8b2011-05-20 15:32:55 +00008167 // Ignore parameter packs.
8168 if (isa<ParmVarDecl>(oldCapture) &&
8169 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8170 continue;
John McCall490112f2011-02-04 18:33:18 +00008171
Douglas Gregor4385d8b2011-05-20 15:32:55 +00008172 VarDecl *newCapture =
8173 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8174 oldCapture));
8175 assert(blockScope->CaptureMap.count(newCapture));
8176 }
John McCall490112f2011-02-04 18:33:18 +00008177 }
8178#endif
8179
8180 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8181 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00008182}
8183
Mike Stump11289f42009-09-09 15:08:12 +00008184template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008185ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008186TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008187 ValueDecl *ND
8188 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8189 E->getDecl()));
8190 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008191 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008192
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008193 if (!getDerived().AlwaysRebuild() &&
8194 ND == E->getDecl()) {
8195 // Mark it referenced in the new context regardless.
8196 // FIXME: this is a bit instantiation-specific.
8197 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
8198
John McCallc3007a22010-10-26 07:05:15 +00008199 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008200 }
8201
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008202 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00008203 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008204 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00008205}
Mike Stump11289f42009-09-09 15:08:12 +00008206
Tanya Lattner55808c12011-06-04 00:47:47 +00008207template<typename Derived>
8208ExprResult
8209TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00008210 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00008211}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00008212
8213template<typename Derived>
8214ExprResult
8215TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00008216 QualType RetTy = getDerived().TransformType(E->getType());
8217 bool ArgumentChanged = false;
8218 ASTOwningVector<Expr*> SubExprs(SemaRef);
8219 SubExprs.reserve(E->getNumSubExprs());
8220 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8221 SubExprs, &ArgumentChanged))
8222 return ExprError();
8223
8224 if (!getDerived().AlwaysRebuild() &&
8225 !ArgumentChanged)
8226 return SemaRef.Owned(E);
8227
8228 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8229 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00008230}
Tanya Lattner55808c12011-06-04 00:47:47 +00008231
Douglas Gregora16548e2009-08-11 05:31:07 +00008232//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008233// Type reconstruction
8234//===----------------------------------------------------------------------===//
8235
Mike Stump11289f42009-09-09 15:08:12 +00008236template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00008237QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8238 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00008239 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008240 getDerived().getBaseEntity());
8241}
8242
Mike Stump11289f42009-09-09 15:08:12 +00008243template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00008244QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8245 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00008246 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008247 getDerived().getBaseEntity());
8248}
8249
Mike Stump11289f42009-09-09 15:08:12 +00008250template<typename Derived>
8251QualType
John McCall70dd5f62009-10-30 00:06:24 +00008252TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8253 bool WrittenAsLValue,
8254 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00008255 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00008256 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008257}
8258
8259template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008260QualType
John McCall70dd5f62009-10-30 00:06:24 +00008261TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8262 QualType ClassType,
8263 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00008264 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00008265 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008266}
8267
8268template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008269QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00008270TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8271 ArrayType::ArraySizeModifier SizeMod,
8272 const llvm::APInt *Size,
8273 Expr *SizeExpr,
8274 unsigned IndexTypeQuals,
8275 SourceRange BracketsRange) {
8276 if (SizeExpr || !Size)
8277 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8278 IndexTypeQuals, BracketsRange,
8279 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00008280
8281 QualType Types[] = {
8282 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8283 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8284 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00008285 };
8286 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8287 QualType SizeType;
8288 for (unsigned I = 0; I != NumTypes; ++I)
8289 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8290 SizeType = Types[I];
8291 break;
8292 }
Mike Stump11289f42009-09-09 15:08:12 +00008293
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00008294 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
8295 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00008296 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008297 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00008298 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008299}
Mike Stump11289f42009-09-09 15:08:12 +00008300
Douglas Gregord6ff3322009-08-04 16:50:30 +00008301template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008302QualType
8303TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008304 ArrayType::ArraySizeModifier SizeMod,
8305 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00008306 unsigned IndexTypeQuals,
8307 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008308 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00008309 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008310}
8311
8312template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008313QualType
Mike Stump11289f42009-09-09 15:08:12 +00008314TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008315 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00008316 unsigned IndexTypeQuals,
8317 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008318 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00008319 IndexTypeQuals, BracketsRange);
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>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008325 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00008326 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008327 unsigned IndexTypeQuals,
8328 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008329 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00008330 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008331 IndexTypeQuals, BracketsRange);
8332}
8333
8334template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008335QualType
8336TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008337 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00008338 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008339 unsigned IndexTypeQuals,
8340 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008341 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00008342 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008343 IndexTypeQuals, BracketsRange);
8344}
8345
8346template<typename Derived>
8347QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00008348 unsigned NumElements,
8349 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00008350 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00008351 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008352}
Mike Stump11289f42009-09-09 15:08:12 +00008353
Douglas Gregord6ff3322009-08-04 16:50:30 +00008354template<typename Derived>
8355QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8356 unsigned NumElements,
8357 SourceLocation AttributeLoc) {
8358 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8359 NumElements, true);
8360 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00008361 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8362 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00008363 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008364}
Mike Stump11289f42009-09-09 15:08:12 +00008365
Douglas Gregord6ff3322009-08-04 16:50:30 +00008366template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008367QualType
8368TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00008369 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008370 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00008371 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008372}
Mike Stump11289f42009-09-09 15:08:12 +00008373
Douglas Gregord6ff3322009-08-04 16:50:30 +00008374template<typename Derived>
8375QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00008376 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008377 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00008378 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00008379 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00008380 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00008381 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00008382 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00008383 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008384 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00008385 getDerived().getBaseEntity(),
8386 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008387}
Mike Stump11289f42009-09-09 15:08:12 +00008388
Douglas Gregord6ff3322009-08-04 16:50:30 +00008389template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00008390QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8391 return SemaRef.Context.getFunctionNoProtoType(T);
8392}
8393
8394template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00008395QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8396 assert(D && "no decl found");
8397 if (D->isInvalidDecl()) return QualType();
8398
Douglas Gregorc298ffc2010-04-22 16:44:27 +00008399 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00008400 TypeDecl *Ty;
8401 if (isa<UsingDecl>(D)) {
8402 UsingDecl *Using = cast<UsingDecl>(D);
8403 assert(Using->isTypeName() &&
8404 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8405
8406 // A valid resolved using typename decl points to exactly one type decl.
8407 assert(++Using->shadow_begin() == Using->shadow_end());
8408 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00008409
John McCallb96ec562009-12-04 22:46:56 +00008410 } else {
8411 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8412 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8413 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8414 }
8415
8416 return SemaRef.Context.getTypeDeclType(Ty);
8417}
8418
8419template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008420QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8421 SourceLocation Loc) {
8422 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008423}
8424
8425template<typename Derived>
8426QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8427 return SemaRef.Context.getTypeOfType(Underlying);
8428}
8429
8430template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008431QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8432 SourceLocation Loc) {
8433 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008434}
8435
8436template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00008437QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8438 UnaryTransformType::UTTKind UKind,
8439 SourceLocation Loc) {
8440 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8441}
8442
8443template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00008444QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00008445 TemplateName Template,
8446 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00008447 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00008448 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008449}
Mike Stump11289f42009-09-09 15:08:12 +00008450
Douglas Gregor1135c352009-08-06 05:28:30 +00008451template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00008452QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
8453 SourceLocation KWLoc) {
8454 return SemaRef.BuildAtomicType(ValueType, KWLoc);
8455}
8456
8457template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008458TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008459TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008460 bool TemplateKW,
8461 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008462 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008463 Template);
8464}
8465
8466template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008467TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008468TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8469 const IdentifierInfo &Name,
8470 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00008471 QualType ObjectType,
8472 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008473 UnqualifiedId TemplateName;
8474 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00008475 Sema::TemplateTy Template;
8476 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008477 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008478 SS,
Douglas Gregor9db53502011-03-02 18:07:45 +00008479 TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00008480 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008481 /*EnteringContext=*/false,
8482 Template);
John McCall31f82722010-11-12 08:19:04 +00008483 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00008484}
Mike Stump11289f42009-09-09 15:08:12 +00008485
Douglas Gregora16548e2009-08-11 05:31:07 +00008486template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00008487TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008488TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008489 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00008490 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008491 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00008492 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00008493 // FIXME: Bogus location information.
8494 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8495 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
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,
8500 Name,
John McCallba7bf592010-08-24 05:47:05 +00008501 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008502 /*EnteringContext=*/false,
8503 Template);
8504 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00008505}
Alexis Hunta8136cc2010-05-05 15:23:54 +00008506
Douglas Gregor71395fa2009-11-04 00:56:37 +00008507template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008508ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008509TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8510 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008511 Expr *OrigCallee,
8512 Expr *First,
8513 Expr *Second) {
8514 Expr *Callee = OrigCallee->IgnoreParenCasts();
8515 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00008516
Douglas Gregora16548e2009-08-11 05:31:07 +00008517 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00008518 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00008519 if (!First->getType()->isOverloadableType() &&
8520 !Second->getType()->isOverloadableType())
8521 return getSema().CreateBuiltinArraySubscriptExpr(First,
8522 Callee->getLocStart(),
8523 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00008524 } else if (Op == OO_Arrow) {
8525 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00008526 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8527 } else if (Second == 0 || isPostIncDec) {
8528 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008529 // The argument is not of overloadable type, so try to create a
8530 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00008531 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008532 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00008533
John McCallb268a282010-08-23 23:25:46 +00008534 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008535 }
8536 } else {
John McCallb268a282010-08-23 23:25:46 +00008537 if (!First->getType()->isOverloadableType() &&
8538 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008539 // Neither of the arguments is an overloadable type, so try to
8540 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00008541 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008542 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00008543 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00008544 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008545 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008546
Douglas Gregora16548e2009-08-11 05:31:07 +00008547 return move(Result);
8548 }
8549 }
Mike Stump11289f42009-09-09 15:08:12 +00008550
8551 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00008552 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00008553 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00008554
John McCallb268a282010-08-23 23:25:46 +00008555 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00008556 assert(ULE->requiresADL());
8557
8558 // FIXME: Do we have to check
8559 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00008560 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00008561 } else {
John McCallb268a282010-08-23 23:25:46 +00008562 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00008563 }
Mike Stump11289f42009-09-09 15:08:12 +00008564
Douglas Gregora16548e2009-08-11 05:31:07 +00008565 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00008566 Expr *Args[2] = { First, Second };
8567 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00008568
Douglas Gregora16548e2009-08-11 05:31:07 +00008569 // Create the overloaded operator invocation for unary operators.
8570 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00008571 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008572 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00008573 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008574 }
Mike Stump11289f42009-09-09 15:08:12 +00008575
Douglas Gregore9d62932011-07-15 16:25:15 +00008576 if (Op == OO_Subscript) {
8577 SourceLocation LBrace;
8578 SourceLocation RBrace;
8579
8580 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
8581 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
8582 LBrace = SourceLocation::getFromRawEncoding(
8583 NameLoc.CXXOperatorName.BeginOpNameLoc);
8584 RBrace = SourceLocation::getFromRawEncoding(
8585 NameLoc.CXXOperatorName.EndOpNameLoc);
8586 } else {
8587 LBrace = Callee->getLocStart();
8588 RBrace = OpLoc;
8589 }
8590
8591 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
8592 First, Second);
8593 }
Sebastian Redladba46e2009-10-29 20:17:01 +00008594
Douglas Gregora16548e2009-08-11 05:31:07 +00008595 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00008596 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008597 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00008598 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8599 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008600 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008601
Mike Stump11289f42009-09-09 15:08:12 +00008602 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00008603}
Mike Stump11289f42009-09-09 15:08:12 +00008604
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008605template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008606ExprResult
John McCallb268a282010-08-23 23:25:46 +00008607TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008608 SourceLocation OperatorLoc,
8609 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00008610 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008611 TypeSourceInfo *ScopeType,
8612 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008613 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008614 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00008615 QualType BaseType = Base->getType();
8616 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008617 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00008618 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00008619 !BaseType->getAs<PointerType>()->getPointeeType()
8620 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008621 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00008622 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008623 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008624 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008625 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008626 /*FIXME?*/true);
8627 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008628
Douglas Gregor678f90d2010-02-25 01:56:36 +00008629 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008630 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8631 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8632 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8633 NameInfo.setNamedTypeInfo(DestroyedType);
8634
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008635 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008636
John McCallb268a282010-08-23 23:25:46 +00008637 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008638 OperatorLoc, isArrow,
8639 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008640 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008641 /*TemplateArgs*/ 0);
8642}
8643
Douglas Gregord6ff3322009-08-04 16:50:30 +00008644} // end namespace clang
8645
8646#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H