blob: 6514b2e65e2978241039eb0d711e97a1bba55131 [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"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000024#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000025#include "clang/AST/ExprCXX.h"
26#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000027#include "clang/AST/Stmt.h"
28#include "clang/AST/StmtCXX.h"
29#include "clang/AST/StmtObjC.h"
John McCall8b0666c2010-08-20 18:27:03 +000030#include "clang/Sema/Ownership.h"
31#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000032#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000033#include "llvm/Support/ErrorHandling.h"
Douglas Gregor451d1b12010-12-02 00:05:49 +000034#include "TypeLocBuilder.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000035#include <algorithm>
36
37namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000038using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000039
Douglas Gregord6ff3322009-08-04 16:50:30 +000040/// \brief A semantic tree transformation that allows one to transform one
41/// abstract syntax tree into another.
42///
Mike Stump11289f42009-09-09 15:08:12 +000043/// A new tree transformation is defined by creating a new subclass \c X of
44/// \c TreeTransform<X> and then overriding certain operations to provide
45/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000046/// instantiation is implemented as a tree transformation where the
47/// transformation of TemplateTypeParmType nodes involves substituting the
48/// template arguments for their corresponding template parameters; a similar
49/// transformation is performed for non-type template parameters and
50/// template template parameters.
51///
52/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000053/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000054/// override any of the transformation or rebuild operators by providing an
55/// operation with the same signature as the default implementation. The
56/// overridding function should not be virtual.
57///
58/// Semantic tree transformations are split into two stages, either of which
59/// can be replaced by a subclass. The "transform" step transforms an AST node
60/// or the parts of an AST node using the various transformation functions,
61/// then passes the pieces on to the "rebuild" step, which constructs a new AST
62/// node of the appropriate kind from the pieces. The default transformation
63/// routines recursively transform the operands to composite AST nodes (e.g.,
64/// the pointee type of a PointerType node) and, if any of those operand nodes
65/// were changed by the transformation, invokes the rebuild operation to create
66/// a new AST node.
67///
Mike Stump11289f42009-09-09 15:08:12 +000068/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000069/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000070/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
71/// TransformTemplateName(), or TransformTemplateArgument() with entirely
72/// new implementations.
73///
74/// For more fine-grained transformations, subclasses can replace any of the
75/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000076/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000077/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000078/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// parameters. Additionally, subclasses can override the \c RebuildXXX
80/// functions to control how AST nodes are rebuilt when their operands change.
81/// By default, \c TreeTransform will invoke semantic analysis to rebuild
82/// AST nodes. However, certain other tree transformations (e.g, cloning) may
83/// be able to use more efficient rebuild steps.
84///
85/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000086/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000087/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
88/// operands have not changed (\c AlwaysRebuild()), and customize the
89/// default locations and entity names used for type-checking
90/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000091template<typename Derived>
92class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000093 /// \brief Private RAII object that helps us forget and then re-remember
94 /// the template argument corresponding to a partially-substituted parameter
95 /// pack.
96 class ForgetPartiallySubstitutedPackRAII {
97 Derived &Self;
98 TemplateArgument Old;
99
100 public:
101 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
102 Old = Self.ForgetPartiallySubstitutedPack();
103 }
104
105 ~ForgetPartiallySubstitutedPackRAII() {
106 Self.RememberPartiallySubstitutedPack(Old);
107 }
108 };
109
Douglas Gregord6ff3322009-08-04 16:50:30 +0000110protected:
111 Sema &SemaRef;
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000112
Mike Stump11289f42009-09-09 15:08:12 +0000113public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000114 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000115 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000116
Douglas Gregord6ff3322009-08-04 16:50:30 +0000117 /// \brief Retrieves a reference to the derived class.
118 Derived &getDerived() { return static_cast<Derived&>(*this); }
119
120 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000121 const Derived &getDerived() const {
122 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000123 }
124
John McCalldadc5752010-08-24 06:29:42 +0000125 static inline ExprResult Owned(Expr *E) { return E; }
126 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000127
Douglas Gregord6ff3322009-08-04 16:50:30 +0000128 /// \brief Retrieves a reference to the semantic analysis object used for
129 /// this tree transform.
130 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000131
Douglas Gregord6ff3322009-08-04 16:50:30 +0000132 /// \brief Whether the transformation should always rebuild AST nodes, even
133 /// if none of the children have changed.
134 ///
135 /// Subclasses may override this function to specify when the transformation
136 /// should rebuild all AST nodes.
137 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000138
Douglas Gregord6ff3322009-08-04 16:50:30 +0000139 /// \brief Returns the location of the entity being transformed, if that
140 /// information was not available elsewhere in the AST.
141 ///
Mike Stump11289f42009-09-09 15:08:12 +0000142 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000143 /// provide an alternative implementation that provides better location
144 /// information.
145 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000146
Douglas Gregord6ff3322009-08-04 16:50:30 +0000147 /// \brief Returns the name of the entity being transformed, if that
148 /// information was not available elsewhere in the AST.
149 ///
150 /// By default, returns an empty name. Subclasses can provide an alternative
151 /// implementation with a more precise name.
152 DeclarationName getBaseEntity() { return DeclarationName(); }
153
Douglas Gregora16548e2009-08-11 05:31:07 +0000154 /// \brief Sets the "base" location and entity when that
155 /// information is known based on another transformation.
156 ///
157 /// By default, the source location and entity are ignored. Subclasses can
158 /// override this function to provide a customized implementation.
159 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000160
Douglas Gregora16548e2009-08-11 05:31:07 +0000161 /// \brief RAII object that temporarily sets the base location and entity
162 /// used for reporting diagnostics in types.
163 class TemporaryBase {
164 TreeTransform &Self;
165 SourceLocation OldLocation;
166 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000167
Douglas Gregora16548e2009-08-11 05:31:07 +0000168 public:
169 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000170 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000171 OldLocation = Self.getDerived().getBaseLocation();
172 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregora518d5b2011-01-25 17:51:48 +0000173
174 if (Location.isValid())
175 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000176 }
Mike Stump11289f42009-09-09 15:08:12 +0000177
Douglas Gregora16548e2009-08-11 05:31:07 +0000178 ~TemporaryBase() {
179 Self.getDerived().setBase(OldLocation, OldEntity);
180 }
181 };
Mike Stump11289f42009-09-09 15:08:12 +0000182
183 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000184 /// transformed.
185 ///
186 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000187 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000188 /// not change. For example, template instantiation need not traverse
189 /// non-dependent types.
190 bool AlreadyTransformed(QualType T) {
191 return T.isNull();
192 }
193
Douglas Gregord196a582009-12-14 19:27:10 +0000194 /// \brief Determine whether the given call argument should be dropped, e.g.,
195 /// because it is a default argument.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine to
198 /// determine which kinds of call arguments get dropped. By default,
199 /// CXXDefaultArgument nodes are dropped (prior to transformation).
200 bool DropCallArgument(Expr *E) {
201 return E->isDefaultArgument();
202 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000203
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000204 /// \brief Determine whether we should expand a pack expansion with the
205 /// given set of parameter packs into separate arguments by repeatedly
206 /// transforming the pattern.
207 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000208 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000209 /// Subclasses can override this routine to provide different behavior.
210 ///
211 /// \param EllipsisLoc The location of the ellipsis that identifies the
212 /// pack expansion.
213 ///
214 /// \param PatternRange The source range that covers the entire pattern of
215 /// the pack expansion.
216 ///
217 /// \param Unexpanded The set of unexpanded parameter packs within the
218 /// pattern.
219 ///
220 /// \param NumUnexpanded The number of unexpanded parameter packs in
221 /// \p Unexpanded.
222 ///
223 /// \param ShouldExpand Will be set to \c true if the transformer should
224 /// expand the corresponding pack expansions into separate arguments. When
225 /// set, \c NumExpansions must also be set.
226 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000227 /// \param RetainExpansion Whether the caller should add an unexpanded
228 /// pack expansion after all of the expanded arguments. This is used
229 /// when extending explicitly-specified template argument packs per
230 /// C++0x [temp.arg.explicit]p9.
231 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000232 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000233 /// the expanded form of the corresponding pack expansion. This is both an
234 /// input and an output parameter, which can be set by the caller if the
235 /// number of expansions is known a priori (e.g., due to a prior substitution)
236 /// and will be set by the callee when the number of expansions is known.
237 /// The callee must set this value when \c ShouldExpand is \c true; it may
238 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000239 ///
240 /// \returns true if an error occurred (e.g., because the parameter packs
241 /// are to be instantiated with arguments of different lengths), false
242 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
243 /// must be set.
244 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
245 SourceRange PatternRange,
246 const UnexpandedParameterPack *Unexpanded,
247 unsigned NumUnexpanded,
248 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000249 bool &RetainExpansion,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000250 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000251 ShouldExpand = false;
252 return false;
253 }
254
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000255 /// \brief "Forget" about the partially-substituted pack template argument,
256 /// when performing an instantiation that must preserve the parameter pack
257 /// use.
258 ///
259 /// This routine is meant to be overridden by the template instantiator.
260 TemplateArgument ForgetPartiallySubstitutedPack() {
261 return TemplateArgument();
262 }
263
264 /// \brief "Remember" the partially-substituted pack template argument
265 /// after performing an instantiation that must preserve the parameter pack
266 /// use.
267 ///
268 /// This routine is meant to be overridden by the template instantiator.
269 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
270
Douglas Gregorf3010112011-01-07 16:43:16 +0000271 /// \brief Note to the derived class when a function parameter pack is
272 /// being expanded.
273 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
274
Douglas Gregord6ff3322009-08-04 16:50:30 +0000275 /// \brief Transforms the given type into another type.
276 ///
John McCall550e0c22009-10-21 00:40:46 +0000277 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000278 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000279 /// function. This is expensive, but we don't mind, because
280 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000281 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 ///
283 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000284 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000285
John McCall550e0c22009-10-21 00:40:46 +0000286 /// \brief Transforms the given type-with-location into a new
287 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000288 ///
John McCall550e0c22009-10-21 00:40:46 +0000289 /// By default, this routine transforms a type by delegating to the
290 /// appropriate TransformXXXType to build a new type. Subclasses
291 /// may override this function (to take over all type
292 /// transformations) or some set of the TransformXXXType functions
293 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000294 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000295
296 /// \brief Transform the given type-with-location into a new
297 /// type, collecting location information in the given builder
298 /// as necessary.
299 ///
John McCall31f82722010-11-12 08:19:04 +0000300 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000301
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000302 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000303 ///
Mike Stump11289f42009-09-09 15:08:12 +0000304 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000305 /// appropriate TransformXXXStmt function to transform a specific kind of
306 /// statement or the TransformExpr() function to transform an expression.
307 /// Subclasses may override this function to transform statements using some
308 /// other mechanism.
309 ///
310 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000311 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000312
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000313 /// \brief Transform the given expression.
314 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000315 /// By default, this routine transforms an expression by delegating to the
316 /// appropriate TransformXXXExpr function to build a new expression.
317 /// Subclasses may override this function to transform expressions using some
318 /// other mechanism.
319 ///
320 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000321 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000322
Douglas Gregora3efea12011-01-03 19:04:46 +0000323 /// \brief Transform the given list of expressions.
324 ///
325 /// This routine transforms a list of expressions by invoking
326 /// \c TransformExpr() for each subexpression. However, it also provides
327 /// support for variadic templates by expanding any pack expansions (if the
328 /// derived class permits such expansion) along the way. When pack expansions
329 /// are present, the number of outputs may not equal the number of inputs.
330 ///
331 /// \param Inputs The set of expressions to be transformed.
332 ///
333 /// \param NumInputs The number of expressions in \c Inputs.
334 ///
335 /// \param IsCall If \c true, then this transform is being performed on
336 /// function-call arguments, and any arguments that should be dropped, will
337 /// be.
338 ///
339 /// \param Outputs The transformed input expressions will be added to this
340 /// vector.
341 ///
342 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
343 /// due to transformation.
344 ///
345 /// \returns true if an error occurred, false otherwise.
346 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
347 llvm::SmallVectorImpl<Expr *> &Outputs,
348 bool *ArgChanged = 0);
349
Douglas Gregord6ff3322009-08-04 16:50:30 +0000350 /// \brief Transform the given declaration, which is referenced from a type
351 /// or expression.
352 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000353 /// By default, acts as the identity function on declarations. Subclasses
354 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000355 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000356
357 /// \brief Transform the definition of the given declaration.
358 ///
Mike Stump11289f42009-09-09 15:08:12 +0000359 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000360 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000361 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
362 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000363 }
Mike Stump11289f42009-09-09 15:08:12 +0000364
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000365 /// \brief Transform the given declaration, which was the first part of a
366 /// nested-name-specifier in a member access expression.
367 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000368 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000369 /// identifier in a nested-name-specifier of a member access expression, e.g.,
370 /// the \c T in \c x->T::member
371 ///
372 /// By default, invokes TransformDecl() to transform the declaration.
373 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000374 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
375 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000376 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000377
Douglas Gregord6ff3322009-08-04 16:50:30 +0000378 /// \brief Transform the given nested-name-specifier.
379 ///
Mike Stump11289f42009-09-09 15:08:12 +0000380 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000381 /// nested-name-specifier. Subclasses may override this function to provide
382 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000383 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000384 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000385 QualType ObjectType = QualType(),
386 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000387
Douglas Gregor14454802011-02-25 02:25:35 +0000388 /// \brief Transform the given nested-name-specifier with source-location
389 /// information.
390 ///
391 /// By default, transforms all of the types and declarations within the
392 /// nested-name-specifier. Subclasses may override this function to provide
393 /// alternate behavior.
394 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
395 NestedNameSpecifierLoc NNS,
396 QualType ObjectType = QualType(),
397 NamedDecl *FirstQualifierInScope = 0);
398
Douglas Gregorf816bd72009-09-03 22:13:48 +0000399 /// \brief Transform the given declaration name.
400 ///
401 /// By default, transforms the types of conversion function, constructor,
402 /// and destructor names and then (if needed) rebuilds the declaration name.
403 /// Identifiers and selectors are returned unmodified. Sublcasses may
404 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000405 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000406 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000407
Douglas Gregord6ff3322009-08-04 16:50:30 +0000408 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000409 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000410 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000411 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000412 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000413 TemplateName TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +0000414 QualType ObjectType = QualType(),
415 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000416
Douglas Gregord6ff3322009-08-04 16:50:30 +0000417 /// \brief Transform the given template argument.
418 ///
Mike Stump11289f42009-09-09 15:08:12 +0000419 /// By default, this operation transforms the type, expression, or
420 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000421 /// new template argument from the transformed result. Subclasses may
422 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000423 ///
424 /// Returns true if there was an error.
425 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
426 TemplateArgumentLoc &Output);
427
Douglas Gregor62e06f22010-12-20 17:31:10 +0000428 /// \brief Transform the given set of template arguments.
429 ///
430 /// By default, this operation transforms all of the template arguments
431 /// in the input set using \c TransformTemplateArgument(), and appends
432 /// the transformed arguments to the output list.
433 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000434 /// Note that this overload of \c TransformTemplateArguments() is merely
435 /// a convenience function. Subclasses that wish to override this behavior
436 /// should override the iterator-based member template version.
437 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000438 /// \param Inputs The set of template arguments to be transformed.
439 ///
440 /// \param NumInputs The number of template arguments in \p Inputs.
441 ///
442 /// \param Outputs The set of transformed template arguments output by this
443 /// routine.
444 ///
445 /// Returns true if an error occurred.
446 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
447 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000448 TemplateArgumentListInfo &Outputs) {
449 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
450 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000451
452 /// \brief Transform the given set of template arguments.
453 ///
454 /// By default, this operation transforms all of the template arguments
455 /// in the input set using \c TransformTemplateArgument(), and appends
456 /// the transformed arguments to the output list.
457 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000458 /// \param First An iterator to the first template argument.
459 ///
460 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000461 ///
462 /// \param Outputs The set of transformed template arguments output by this
463 /// routine.
464 ///
465 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000466 template<typename InputIterator>
467 bool TransformTemplateArguments(InputIterator First,
468 InputIterator Last,
469 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000470
John McCall0ad16662009-10-29 08:12:44 +0000471 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
472 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
473 TemplateArgumentLoc &ArgLoc);
474
John McCallbcd03502009-12-07 02:54:59 +0000475 /// \brief Fakes up a TypeSourceInfo for a type.
476 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
477 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000478 getDerived().getBaseLocation());
479 }
Mike Stump11289f42009-09-09 15:08:12 +0000480
John McCall550e0c22009-10-21 00:40:46 +0000481#define ABSTRACT_TYPELOC(CLASS, PARENT)
482#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000483 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000484#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000485
John McCall31f82722010-11-12 08:19:04 +0000486 QualType
487 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
488 TemplateSpecializationTypeLoc TL,
489 TemplateName Template);
490
491 QualType
492 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
493 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor5a064722011-02-28 17:23:35 +0000494 TemplateName Template);
495
496 QualType
497 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
498 DependentTemplateSpecializationTypeLoc TL,
John McCall31f82722010-11-12 08:19:04 +0000499 NestedNameSpecifier *Prefix);
500
John McCall58f10c32010-03-11 09:03:00 +0000501 /// \brief Transforms the parameters of a function type into the
502 /// given vectors.
503 ///
504 /// The result vectors should be kept in sync; null entries in the
505 /// variables vector are acceptable.
506 ///
507 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000508 bool TransformFunctionTypeParams(SourceLocation Loc,
509 ParmVarDecl **Params, unsigned NumParams,
510 const QualType *ParamTypes,
John McCall58f10c32010-03-11 09:03:00 +0000511 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregordd472162011-01-07 00:20:55 +0000512 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000513
514 /// \brief Transforms a single function-type parameter. Return null
515 /// on error.
Douglas Gregor715e4612011-01-14 22:40:04 +0000516 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
517 llvm::Optional<unsigned> NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +0000518
John McCall31f82722010-11-12 08:19:04 +0000519 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000520
John McCalldadc5752010-08-24 06:29:42 +0000521 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
522 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000523
Douglas Gregorebe10102009-08-20 07:17:43 +0000524#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000525 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000526#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000527 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000528#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000529#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000530
Douglas Gregord6ff3322009-08-04 16:50:30 +0000531 /// \brief Build a new pointer type given its pointee type.
532 ///
533 /// By default, performs semantic analysis when building the pointer type.
534 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000535 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000536
537 /// \brief Build a new block pointer type given its pointee type.
538 ///
Mike Stump11289f42009-09-09 15:08:12 +0000539 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000540 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000541 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000542
John McCall70dd5f62009-10-30 00:06:24 +0000543 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000544 ///
John McCall70dd5f62009-10-30 00:06:24 +0000545 /// By default, performs semantic analysis when building the
546 /// reference type. Subclasses may override this routine to provide
547 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000548 ///
John McCall70dd5f62009-10-30 00:06:24 +0000549 /// \param LValue whether the type was written with an lvalue sigil
550 /// or an rvalue sigil.
551 QualType RebuildReferenceType(QualType ReferentType,
552 bool LValue,
553 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000554
Douglas Gregord6ff3322009-08-04 16:50:30 +0000555 /// \brief Build a new member pointer type given the pointee type and the
556 /// class type it refers into.
557 ///
558 /// By default, performs semantic analysis when building the member pointer
559 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000560 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
561 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000562
Douglas Gregord6ff3322009-08-04 16:50:30 +0000563 /// \brief Build a new array type given the element type, size
564 /// modifier, size of the array (if known), size expression, and index type
565 /// qualifiers.
566 ///
567 /// By default, performs semantic analysis when building the array type.
568 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000569 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000570 QualType RebuildArrayType(QualType ElementType,
571 ArrayType::ArraySizeModifier SizeMod,
572 const llvm::APInt *Size,
573 Expr *SizeExpr,
574 unsigned IndexTypeQuals,
575 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000576
Douglas Gregord6ff3322009-08-04 16:50:30 +0000577 /// \brief Build a new constant array type given the element type, size
578 /// modifier, (known) size of the array, and index type qualifiers.
579 ///
580 /// By default, performs semantic analysis when building the array type.
581 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000582 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000583 ArrayType::ArraySizeModifier SizeMod,
584 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000585 unsigned IndexTypeQuals,
586 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000587
Douglas Gregord6ff3322009-08-04 16:50:30 +0000588 /// \brief Build a new incomplete array type given the element type, size
589 /// modifier, and index type qualifiers.
590 ///
591 /// By default, performs semantic analysis when building the array type.
592 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000593 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000594 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000595 unsigned IndexTypeQuals,
596 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000597
Mike Stump11289f42009-09-09 15:08:12 +0000598 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000599 /// size modifier, size expression, and index type qualifiers.
600 ///
601 /// By default, performs semantic analysis when building the array type.
602 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000603 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000604 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000605 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000606 unsigned IndexTypeQuals,
607 SourceRange BracketsRange);
608
Mike Stump11289f42009-09-09 15:08:12 +0000609 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000610 /// size modifier, size expression, and index type qualifiers.
611 ///
612 /// By default, performs semantic analysis when building the array type.
613 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000614 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000615 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000616 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000617 unsigned IndexTypeQuals,
618 SourceRange BracketsRange);
619
620 /// \brief Build a new vector type given the element type and
621 /// number of elements.
622 ///
623 /// By default, performs semantic analysis when building the vector type.
624 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000625 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000626 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000627
Douglas Gregord6ff3322009-08-04 16:50:30 +0000628 /// \brief Build a new extended vector type given the element type and
629 /// number of elements.
630 ///
631 /// By default, performs semantic analysis when building the vector type.
632 /// Subclasses may override this routine to provide different behavior.
633 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
634 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000635
636 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000637 /// given the element type and 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.
Mike Stump11289f42009-09-09 15:08:12 +0000641 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000642 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000643 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000644
Douglas Gregord6ff3322009-08-04 16:50:30 +0000645 /// \brief Build a new function type.
646 ///
647 /// By default, performs semantic analysis when building the function type.
648 /// Subclasses may override this routine to provide different behavior.
649 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000650 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000651 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000652 bool Variadic, unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +0000653 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +0000654 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000655
John McCall550e0c22009-10-21 00:40:46 +0000656 /// \brief Build a new unprototyped function type.
657 QualType RebuildFunctionNoProtoType(QualType ResultType);
658
John McCallb96ec562009-12-04 22:46:56 +0000659 /// \brief Rebuild an unresolved typename type, given the decl that
660 /// the UnresolvedUsingTypenameDecl was transformed to.
661 QualType RebuildUnresolvedUsingType(Decl *D);
662
Douglas Gregord6ff3322009-08-04 16:50:30 +0000663 /// \brief Build a new typedef type.
664 QualType RebuildTypedefType(TypedefDecl *Typedef) {
665 return SemaRef.Context.getTypeDeclType(Typedef);
666 }
667
668 /// \brief Build a new class/struct/union type.
669 QualType RebuildRecordType(RecordDecl *Record) {
670 return SemaRef.Context.getTypeDeclType(Record);
671 }
672
673 /// \brief Build a new Enum type.
674 QualType RebuildEnumType(EnumDecl *Enum) {
675 return SemaRef.Context.getTypeDeclType(Enum);
676 }
John McCallfcc33b02009-09-05 00:15:47 +0000677
Mike Stump11289f42009-09-09 15:08:12 +0000678 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000679 ///
680 /// By default, performs semantic analysis when building the typeof type.
681 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000682 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000683
Mike Stump11289f42009-09-09 15:08:12 +0000684 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000685 ///
686 /// By default, builds a new TypeOfType with the given underlying type.
687 QualType RebuildTypeOfType(QualType Underlying);
688
Mike Stump11289f42009-09-09 15:08:12 +0000689 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000690 ///
691 /// By default, performs semantic analysis when building the decltype type.
692 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000693 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000694
Richard Smith30482bc2011-02-20 03:19:35 +0000695 /// \brief Build a new C++0x auto type.
696 ///
697 /// By default, builds a new AutoType with the given deduced type.
698 QualType RebuildAutoType(QualType Deduced) {
699 return SemaRef.Context.getAutoType(Deduced);
700 }
701
Douglas Gregord6ff3322009-08-04 16:50:30 +0000702 /// \brief Build a new template specialization type.
703 ///
704 /// By default, performs semantic analysis when building the template
705 /// specialization type. Subclasses may override this routine to provide
706 /// different behavior.
707 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000708 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000709 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000710
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000711 /// \brief Build a new parenthesized type.
712 ///
713 /// By default, builds a new ParenType type from the inner type.
714 /// Subclasses may override this routine to provide different behavior.
715 QualType RebuildParenType(QualType InnerType) {
716 return SemaRef.Context.getParenType(InnerType);
717 }
718
Douglas Gregord6ff3322009-08-04 16:50:30 +0000719 /// \brief Build a new qualified name type.
720 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000721 /// By default, builds a new ElaboratedType type from the keyword,
722 /// the nested-name-specifier and the named type.
723 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000724 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
725 ElaboratedTypeKeyword Keyword,
Abramo Bagnara6150c882010-05-11 21:36:43 +0000726 NestedNameSpecifier *NNS, QualType Named) {
727 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000728 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000729
730 /// \brief Build a new typename type that refers to a template-id.
731 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000732 /// By default, builds a new DependentNameType type from the
733 /// nested-name-specifier and the given type. Subclasses may override
734 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000735 QualType RebuildDependentTemplateSpecializationType(
736 ElaboratedTypeKeyword Keyword,
Douglas Gregora5614c52010-09-08 23:56:00 +0000737 NestedNameSpecifier *Qualifier,
738 SourceRange QualifierRange,
John McCallc392f372010-06-11 00:33:02 +0000739 const IdentifierInfo *Name,
740 SourceLocation NameLoc,
741 const TemplateArgumentListInfo &Args) {
742 // Rebuild the template name.
743 // TODO: avoid TemplateName abstraction
744 TemplateName InstName =
Douglas Gregora5614c52010-09-08 23:56:00 +0000745 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall31f82722010-11-12 08:19:04 +0000746 QualType(), 0);
John McCallc392f372010-06-11 00:33:02 +0000747
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000748 if (InstName.isNull())
749 return QualType();
750
John McCallc392f372010-06-11 00:33:02 +0000751 // If it's still dependent, make a dependent specialization.
752 if (InstName.getAsDependentTemplateName())
753 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregora5614c52010-09-08 23:56:00 +0000754 Keyword, Qualifier, Name, Args);
John McCallc392f372010-06-11 00:33:02 +0000755
756 // Otherwise, make an elaborated type wrapping a non-dependent
757 // specialization.
758 QualType T =
759 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
760 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000761
Douglas Gregor5a064722011-02-28 17:23:35 +0000762 if (Keyword == ETK_None && Qualifier == 0)
Douglas Gregor6e068012011-02-28 00:04:36 +0000763 return T;
764
Douglas Gregor5a064722011-02-28 17:23:35 +0000765 return SemaRef.Context.getElaboratedType(Keyword, Qualifier, T);
Mike Stump11289f42009-09-09 15:08:12 +0000766 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000767
768 /// \brief Build a new typename type that refers to an identifier.
769 ///
770 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000771 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000772 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000773 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000774 NestedNameSpecifier *NNS,
775 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000776 SourceLocation KeywordLoc,
777 SourceRange NNSRange,
778 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000779 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +0000780 SS.MakeTrivial(SemaRef.Context, NNS, NNSRange);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000781
Douglas Gregore677daf2010-03-31 22:19:08 +0000782 if (NNS->isDependent()) {
783 // If the name is still dependent, just build a new dependent name type.
784 if (!SemaRef.computeDeclContext(SS))
785 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
786 }
787
Abramo Bagnara6150c882010-05-11 21:36:43 +0000788 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000789 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
790 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000791
792 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
793
Abramo Bagnarad7548482010-05-19 21:37:53 +0000794 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000795 // into a non-dependent elaborated-type-specifier. Find the tag we're
796 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000797 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000798 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
799 if (!DC)
800 return QualType();
801
John McCallbf8c5192010-05-27 06:40:31 +0000802 if (SemaRef.RequireCompleteDeclContext(SS, DC))
803 return QualType();
804
Douglas Gregore677daf2010-03-31 22:19:08 +0000805 TagDecl *Tag = 0;
806 SemaRef.LookupQualifiedName(Result, DC);
807 switch (Result.getResultKind()) {
808 case LookupResult::NotFound:
809 case LookupResult::NotFoundInCurrentInstantiation:
810 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000811
Douglas Gregore677daf2010-03-31 22:19:08 +0000812 case LookupResult::Found:
813 Tag = Result.getAsSingle<TagDecl>();
814 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000815
Douglas Gregore677daf2010-03-31 22:19:08 +0000816 case LookupResult::FoundOverloaded:
817 case LookupResult::FoundUnresolvedValue:
818 llvm_unreachable("Tag lookup cannot find non-tags");
819 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000820
Douglas Gregore677daf2010-03-31 22:19:08 +0000821 case LookupResult::Ambiguous:
822 // Let the LookupResult structure handle ambiguities.
823 return QualType();
824 }
825
826 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000827 // Check where the name exists but isn't a tag type and use that to emit
828 // better diagnostics.
829 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
830 SemaRef.LookupQualifiedName(Result, DC);
831 switch (Result.getResultKind()) {
832 case LookupResult::Found:
833 case LookupResult::FoundOverloaded:
834 case LookupResult::FoundUnresolvedValue: {
835 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
836 unsigned Kind = 0;
837 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
838 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2;
839 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
840 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
841 break;
842 }
843 default:
844 // FIXME: Would be nice to highlight just the source range.
845 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
846 << Kind << Id << DC;
847 break;
848 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000849 return QualType();
850 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000851
Abramo Bagnarad7548482010-05-19 21:37:53 +0000852 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
853 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000854 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
855 return QualType();
856 }
857
858 // Build the elaborated-type-specifier type.
859 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000860 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000861 }
Mike Stump11289f42009-09-09 15:08:12 +0000862
Douglas Gregor822d0302011-01-12 17:07:58 +0000863 /// \brief Build a new pack expansion type.
864 ///
865 /// By default, builds a new PackExpansionType type from the given pattern.
866 /// Subclasses may override this routine to provide different behavior.
867 QualType RebuildPackExpansionType(QualType Pattern,
868 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000869 SourceLocation EllipsisLoc,
870 llvm::Optional<unsigned> NumExpansions) {
871 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
872 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000873 }
874
Douglas Gregor1135c352009-08-06 05:28:30 +0000875 /// \brief Build a new nested-name-specifier given the prefix and an
876 /// identifier that names the next step in the nested-name-specifier.
877 ///
878 /// By default, performs semantic analysis when building the new
879 /// nested-name-specifier. Subclasses may override this routine to provide
880 /// different behavior.
881 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
882 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000883 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000884 QualType ObjectType,
885 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000886
887 /// \brief Build a new nested-name-specifier given the prefix and the
888 /// namespace named in the next step in the nested-name-specifier.
889 ///
890 /// By default, performs semantic analysis when building the new
891 /// nested-name-specifier. Subclasses may override this routine to provide
892 /// different behavior.
893 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
894 SourceRange Range,
895 NamespaceDecl *NS);
896
897 /// \brief Build a new nested-name-specifier given the prefix and the
Douglas Gregor7b26ff92011-02-24 02:36:08 +0000898 /// namespace alias named in the next step in the nested-name-specifier.
899 ///
900 /// By default, performs semantic analysis when building the new
901 /// nested-name-specifier. Subclasses may override this routine to provide
902 /// different behavior.
903 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
904 SourceRange Range,
905 NamespaceAliasDecl *Alias);
906
907 /// \brief Build a new nested-name-specifier given the prefix and the
Douglas Gregor1135c352009-08-06 05:28:30 +0000908 /// type named in the next step in the nested-name-specifier.
909 ///
910 /// By default, performs semantic analysis when building the new
911 /// nested-name-specifier. Subclasses may override this routine to provide
912 /// different behavior.
913 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
914 SourceRange Range,
915 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000916 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000917
918 /// \brief Build a new template name given a nested name specifier, a flag
919 /// indicating whether the "template" keyword was provided, and the template
920 /// that the template name refers to.
921 ///
922 /// By default, builds the new template name directly. Subclasses may override
923 /// this routine to provide different behavior.
924 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
925 bool TemplateKW,
926 TemplateDecl *Template);
927
Douglas Gregor71dc5092009-08-06 06:41:21 +0000928 /// \brief Build a new template name given a nested name specifier and the
929 /// name that is referred to as a template.
930 ///
931 /// By default, performs semantic analysis to determine whether the name can
932 /// be resolved to a specific template, then builds the appropriate kind of
933 /// template name. Subclasses may override this routine to provide different
934 /// behavior.
935 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +0000936 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +0000937 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +0000938 QualType ObjectType,
939 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000940
Douglas Gregor71395fa2009-11-04 00:56:37 +0000941 /// \brief Build a new template name given a nested name specifier and the
942 /// overloaded operator name that is referred to as a template.
943 ///
944 /// By default, performs semantic analysis to determine whether the name can
945 /// be resolved to a specific template, then builds the appropriate kind of
946 /// template name. Subclasses may override this routine to provide different
947 /// behavior.
948 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
949 OverloadedOperatorKind Operator,
950 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000951
952 /// \brief Build a new template name given a template template parameter pack
953 /// and the
954 ///
955 /// By default, performs semantic analysis to determine whether the name can
956 /// be resolved to a specific template, then builds the appropriate kind of
957 /// template name. Subclasses may override this routine to provide different
958 /// behavior.
959 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
960 const TemplateArgument &ArgPack) {
961 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
962 }
963
Douglas Gregorebe10102009-08-20 07:17:43 +0000964 /// \brief Build a new compound statement.
965 ///
966 /// By default, performs semantic analysis to build the new statement.
967 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000968 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000969 MultiStmtArg Statements,
970 SourceLocation RBraceLoc,
971 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000972 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000973 IsStmtExpr);
974 }
975
976 /// \brief Build a new case statement.
977 ///
978 /// By default, performs semantic analysis to build the new statement.
979 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000980 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000981 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000982 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000983 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000984 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000985 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000986 ColonLoc);
987 }
Mike Stump11289f42009-09-09 15:08:12 +0000988
Douglas Gregorebe10102009-08-20 07:17:43 +0000989 /// \brief Attach the body to a new case statement.
990 ///
991 /// By default, performs semantic analysis to build the new statement.
992 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000993 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000994 getSema().ActOnCaseStmtBody(S, Body);
995 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000996 }
Mike Stump11289f42009-09-09 15:08:12 +0000997
Douglas Gregorebe10102009-08-20 07:17:43 +0000998 /// \brief Build a new default statement.
999 ///
1000 /// By default, performs semantic analysis to build the new statement.
1001 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001002 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001003 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001004 Stmt *SubStmt) {
1005 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +00001006 /*CurScope=*/0);
1007 }
Mike Stump11289f42009-09-09 15:08:12 +00001008
Douglas Gregorebe10102009-08-20 07:17:43 +00001009 /// \brief Build a new label statement.
1010 ///
1011 /// By default, performs semantic analysis to build the new statement.
1012 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001013 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1014 SourceLocation ColonLoc, Stmt *SubStmt) {
1015 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001016 }
Mike Stump11289f42009-09-09 15:08:12 +00001017
Douglas Gregorebe10102009-08-20 07:17:43 +00001018 /// \brief Build a new "if" statement.
1019 ///
1020 /// By default, performs semantic analysis to build the new statement.
1021 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001022 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattnercab02a62011-02-17 20:34:02 +00001023 VarDecl *CondVar, Stmt *Then,
1024 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001025 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001026 }
Mike Stump11289f42009-09-09 15:08:12 +00001027
Douglas Gregorebe10102009-08-20 07:17:43 +00001028 /// \brief Start building a new switch statement.
1029 ///
1030 /// By default, performs semantic analysis to build the new statement.
1031 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001032 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001033 Expr *Cond, VarDecl *CondVar) {
John McCallb268a282010-08-23 23:25:46 +00001034 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001035 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001036 }
Mike Stump11289f42009-09-09 15:08:12 +00001037
Douglas Gregorebe10102009-08-20 07:17:43 +00001038 /// \brief Attach the body to the switch statement.
1039 ///
1040 /// By default, performs semantic analysis to build the new statement.
1041 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001042 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001043 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001044 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001045 }
1046
1047 /// \brief Build a new while statement.
1048 ///
1049 /// By default, performs semantic analysis to build the new statement.
1050 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001051 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1052 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001053 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001054 }
Mike Stump11289f42009-09-09 15:08:12 +00001055
Douglas Gregorebe10102009-08-20 07:17:43 +00001056 /// \brief Build a new do-while statement.
1057 ///
1058 /// By default, performs semantic analysis to build the new statement.
1059 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001060 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001061 SourceLocation WhileLoc, SourceLocation LParenLoc,
1062 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001063 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1064 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001065 }
1066
1067 /// \brief Build a new for statement.
1068 ///
1069 /// By default, performs semantic analysis to build the new statement.
1070 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001071 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1072 Stmt *Init, Sema::FullExprArg Cond,
1073 VarDecl *CondVar, Sema::FullExprArg Inc,
1074 SourceLocation RParenLoc, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001075 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001076 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001077 }
Mike Stump11289f42009-09-09 15:08:12 +00001078
Douglas Gregorebe10102009-08-20 07:17:43 +00001079 /// \brief Build a new goto statement.
1080 ///
1081 /// By default, performs semantic analysis to build the new statement.
1082 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001083 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1084 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001085 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001086 }
1087
1088 /// \brief Build a new indirect goto statement.
1089 ///
1090 /// By default, performs semantic analysis to build the new statement.
1091 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001092 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001093 SourceLocation StarLoc,
1094 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001095 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001096 }
Mike Stump11289f42009-09-09 15:08:12 +00001097
Douglas Gregorebe10102009-08-20 07:17:43 +00001098 /// \brief Build a new return statement.
1099 ///
1100 /// By default, performs semantic analysis to build the new statement.
1101 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001102 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001103 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001104 }
Mike Stump11289f42009-09-09 15:08:12 +00001105
Douglas Gregorebe10102009-08-20 07:17:43 +00001106 /// \brief Build a new declaration statement.
1107 ///
1108 /// By default, performs semantic analysis to build the new statement.
1109 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001110 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001111 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001112 SourceLocation EndLoc) {
Richard Smith2abf6762011-02-23 00:37:57 +00001113 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1114 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001115 }
Mike Stump11289f42009-09-09 15:08:12 +00001116
Anders Carlssonaaeef072010-01-24 05:50:09 +00001117 /// \brief Build a new inline asm statement.
1118 ///
1119 /// By default, performs semantic analysis to build the new statement.
1120 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001121 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001122 bool IsSimple,
1123 bool IsVolatile,
1124 unsigned NumOutputs,
1125 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001126 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001127 MultiExprArg Constraints,
1128 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001129 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001130 MultiExprArg Clobbers,
1131 SourceLocation RParenLoc,
1132 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001133 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001134 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001135 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001136 RParenLoc, MSAsm);
1137 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001138
1139 /// \brief Build a new Objective-C @try statement.
1140 ///
1141 /// By default, performs semantic analysis to build the new statement.
1142 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001143 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001144 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001145 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001146 Stmt *Finally) {
1147 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1148 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001149 }
1150
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001151 /// \brief Rebuild an Objective-C exception declaration.
1152 ///
1153 /// By default, performs semantic analysis to build the new declaration.
1154 /// Subclasses may override this routine to provide different behavior.
1155 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1156 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001157 return getSema().BuildObjCExceptionDecl(TInfo, T,
1158 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001159 ExceptionDecl->getLocation());
1160 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001161
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001162 /// \brief Build a new Objective-C @catch statement.
1163 ///
1164 /// By default, performs semantic analysis to build the new statement.
1165 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001166 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001167 SourceLocation RParenLoc,
1168 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001169 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001170 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001171 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001172 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001173
Douglas Gregor306de2f2010-04-22 23:59:56 +00001174 /// \brief Build a new Objective-C @finally statement.
1175 ///
1176 /// By default, performs semantic analysis to build the new statement.
1177 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001178 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001179 Stmt *Body) {
1180 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001181 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001182
Douglas Gregor6148de72010-04-22 22:01:21 +00001183 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001184 ///
1185 /// By default, performs semantic analysis to build the new statement.
1186 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001187 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001188 Expr *Operand) {
1189 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001190 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001191
Douglas Gregor6148de72010-04-22 22:01:21 +00001192 /// \brief Build a new Objective-C @synchronized statement.
1193 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001196 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001197 Expr *Object,
1198 Stmt *Body) {
1199 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1200 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001201 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001202
1203 /// \brief Build a new Objective-C fast enumeration statement.
1204 ///
1205 /// By default, performs semantic analysis to build the new statement.
1206 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001207 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001208 SourceLocation LParenLoc,
1209 Stmt *Element,
1210 Expr *Collection,
1211 SourceLocation RParenLoc,
1212 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001213 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001214 Element,
1215 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001216 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001217 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001218 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001219
Douglas Gregorebe10102009-08-20 07:17:43 +00001220 /// \brief Build a new C++ exception declaration.
1221 ///
1222 /// By default, performs semantic analysis to build the new decaration.
1223 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001224 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001225 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +00001226 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001227 SourceLocation Loc) {
1228 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001229 }
1230
1231 /// \brief Build a new C++ catch statement.
1232 ///
1233 /// By default, performs semantic analysis to build the new statement.
1234 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001235 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001236 VarDecl *ExceptionDecl,
1237 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001238 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1239 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001240 }
Mike Stump11289f42009-09-09 15:08:12 +00001241
Douglas Gregorebe10102009-08-20 07:17:43 +00001242 /// \brief Build a new C++ try statement.
1243 ///
1244 /// By default, performs semantic analysis to build the new statement.
1245 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001246 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001247 Stmt *TryBlock,
1248 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001249 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001250 }
Mike Stump11289f42009-09-09 15:08:12 +00001251
Douglas Gregora16548e2009-08-11 05:31:07 +00001252 /// \brief Build a new expression that references a declaration.
1253 ///
1254 /// By default, performs semantic analysis to build the new expression.
1255 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001256 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001257 LookupResult &R,
1258 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001259 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1260 }
1261
1262
1263 /// \brief Build a new expression that references a declaration.
1264 ///
1265 /// By default, performs semantic analysis to build the new expression.
1266 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001267 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallfaf5fb42010-08-26 23:41:50 +00001268 SourceRange QualifierRange,
1269 ValueDecl *VD,
1270 const DeclarationNameInfo &NameInfo,
1271 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001272 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +00001273 SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001274
1275 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001276
1277 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001278 }
Mike Stump11289f42009-09-09 15:08:12 +00001279
Douglas Gregora16548e2009-08-11 05:31:07 +00001280 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001281 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001282 /// By default, performs semantic analysis to build the new expression.
1283 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001284 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001285 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001286 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001287 }
1288
Douglas Gregorad8a3362009-09-04 17:36:40 +00001289 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001290 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001291 /// By default, performs semantic analysis to build the new expression.
1292 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001293 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001294 SourceLocation OperatorLoc,
1295 bool isArrow,
1296 CXXScopeSpec &SS,
1297 TypeSourceInfo *ScopeType,
1298 SourceLocation CCLoc,
1299 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001300 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001301
Douglas Gregora16548e2009-08-11 05:31:07 +00001302 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001303 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001304 /// By default, performs semantic analysis to build the new expression.
1305 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001306 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001307 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001308 Expr *SubExpr) {
1309 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001310 }
Mike Stump11289f42009-09-09 15:08:12 +00001311
Douglas Gregor882211c2010-04-28 22:16:22 +00001312 /// \brief Build a new builtin offsetof expression.
1313 ///
1314 /// By default, performs semantic analysis to build the new expression.
1315 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001316 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001317 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001318 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001319 unsigned NumComponents,
1320 SourceLocation RParenLoc) {
1321 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1322 NumComponents, RParenLoc);
1323 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001324
Douglas Gregora16548e2009-08-11 05:31:07 +00001325 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001326 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001327 /// By default, performs semantic analysis to build the new expression.
1328 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001329 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001330 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001331 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001332 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 }
1334
Mike Stump11289f42009-09-09 15:08:12 +00001335 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001336 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001337 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001338 /// By default, performs semantic analysis to build the new expression.
1339 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001340 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001341 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001342 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001343 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001344 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001345 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001346
Douglas Gregora16548e2009-08-11 05:31:07 +00001347 return move(Result);
1348 }
Mike Stump11289f42009-09-09 15:08:12 +00001349
Douglas Gregora16548e2009-08-11 05:31:07 +00001350 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001351 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001352 /// By default, performs semantic analysis to build the new expression.
1353 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001354 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001356 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001357 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001358 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1359 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001360 RBracketLoc);
1361 }
1362
1363 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001364 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001365 /// By default, performs semantic analysis to build the new expression.
1366 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001367 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001368 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001369 SourceLocation RParenLoc,
1370 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001371 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001372 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001373 }
1374
1375 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001376 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001377 /// By default, performs semantic analysis to build the new expression.
1378 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001379 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001380 bool isArrow,
1381 NestedNameSpecifier *Qualifier,
1382 SourceRange QualifierRange,
1383 const DeclarationNameInfo &MemberNameInfo,
1384 ValueDecl *Member,
1385 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001386 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001387 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001388 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001389 // We have a reference to an unnamed field. This is always the
1390 // base of an anonymous struct/union member access, i.e. the
1391 // field is always of record type.
Anders Carlsson5da84842009-09-01 04:26:58 +00001392 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001393 assert(Member->getType()->isRecordType() &&
1394 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001395
John McCallb268a282010-08-23 23:25:46 +00001396 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001397 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001398 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001399
John McCall7decc9e2010-11-18 06:31:45 +00001400 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001401 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001402 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001403 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001404 cast<FieldDecl>(Member)->getType(),
1405 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001406 return getSema().Owned(ME);
1407 }
Mike Stump11289f42009-09-09 15:08:12 +00001408
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001409 CXXScopeSpec SS;
1410 if (Qualifier) {
Douglas Gregor869ad452011-02-24 17:54:50 +00001411 SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001412 }
1413
John McCallb268a282010-08-23 23:25:46 +00001414 getSema().DefaultFunctionArrayConversion(Base);
1415 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001416
John McCall16df1e52010-03-30 21:47:33 +00001417 // FIXME: this involves duplicating earlier analysis in a lot of
1418 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001419 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001420 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001421 R.resolveKind();
1422
John McCallb268a282010-08-23 23:25:46 +00001423 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001424 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001425 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001426 }
Mike Stump11289f42009-09-09 15:08:12 +00001427
Douglas Gregora16548e2009-08-11 05:31:07 +00001428 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001429 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001430 /// By default, performs semantic analysis to build the new expression.
1431 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001432 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001433 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001434 Expr *LHS, Expr *RHS) {
1435 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001436 }
1437
1438 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001439 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001440 /// By default, performs semantic analysis to build the new expression.
1441 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001442 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001443 SourceLocation QuestionLoc,
1444 Expr *LHS,
1445 SourceLocation ColonLoc,
1446 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001447 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1448 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001449 }
1450
Douglas Gregora16548e2009-08-11 05:31:07 +00001451 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001452 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001453 /// By default, performs semantic analysis to build the new expression.
1454 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001455 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001456 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001457 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001458 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001459 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001460 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001461 }
Mike Stump11289f42009-09-09 15:08:12 +00001462
Douglas Gregora16548e2009-08-11 05:31:07 +00001463 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001464 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001465 /// By default, performs semantic analysis to build the new expression.
1466 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001467 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001468 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001469 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001470 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001471 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001472 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001473 }
Mike Stump11289f42009-09-09 15:08:12 +00001474
Douglas Gregora16548e2009-08-11 05:31:07 +00001475 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001476 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001477 /// By default, performs semantic analysis to build the new expression.
1478 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001479 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001480 SourceLocation OpLoc,
1481 SourceLocation AccessorLoc,
1482 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001483
John McCall10eae182009-11-30 22:42:35 +00001484 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001485 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001486 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001487 OpLoc, /*IsArrow*/ false,
1488 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001489 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001490 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001491 }
Mike Stump11289f42009-09-09 15:08:12 +00001492
Douglas Gregora16548e2009-08-11 05:31:07 +00001493 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001494 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001495 /// By default, performs semantic analysis to build the new expression.
1496 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001497 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001498 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001499 SourceLocation RBraceLoc,
1500 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001501 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001502 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1503 if (Result.isInvalid() || ResultTy->isDependentType())
1504 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001505
Douglas Gregord3d93062009-11-09 17:16:50 +00001506 // Patch in the result type we were given, which may have been computed
1507 // when the initial InitListExpr was built.
1508 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1509 ILE->setType(ResultTy);
1510 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 }
Mike Stump11289f42009-09-09 15:08:12 +00001512
Douglas Gregora16548e2009-08-11 05:31:07 +00001513 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001514 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001515 /// By default, performs semantic analysis to build the new expression.
1516 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001517 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001518 MultiExprArg ArrayExprs,
1519 SourceLocation EqualOrColonLoc,
1520 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001521 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001522 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001523 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001524 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001525 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001526 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001527
Douglas Gregora16548e2009-08-11 05:31:07 +00001528 ArrayExprs.release();
1529 return move(Result);
1530 }
Mike Stump11289f42009-09-09 15:08:12 +00001531
Douglas Gregora16548e2009-08-11 05:31:07 +00001532 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001533 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001534 /// By default, builds the implicit value initialization without performing
1535 /// any semantic analysis. Subclasses may override this routine to provide
1536 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001537 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001538 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1539 }
Mike Stump11289f42009-09-09 15:08:12 +00001540
Douglas Gregora16548e2009-08-11 05:31:07 +00001541 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001542 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 /// By default, performs semantic analysis to build the new expression.
1544 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001545 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001546 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001547 SourceLocation RParenLoc) {
1548 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001549 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001550 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001551 }
1552
1553 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001554 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001555 /// By default, performs semantic analysis to build the new expression.
1556 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001557 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001558 MultiExprArg SubExprs,
1559 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001560 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001561 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001562 }
Mike Stump11289f42009-09-09 15:08:12 +00001563
Douglas Gregora16548e2009-08-11 05:31:07 +00001564 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001565 ///
1566 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001567 /// rather than attempting to map the label statement itself.
1568 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001569 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001570 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001571 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001572 }
Mike Stump11289f42009-09-09 15:08:12 +00001573
Douglas Gregora16548e2009-08-11 05:31:07 +00001574 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001575 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001576 /// By default, performs semantic analysis to build the new expression.
1577 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001578 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001579 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001580 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001581 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001582 }
Mike Stump11289f42009-09-09 15:08:12 +00001583
Douglas Gregora16548e2009-08-11 05:31:07 +00001584 /// \brief Build a new __builtin_choose_expr expression.
1585 ///
1586 /// By default, performs semantic analysis to build the new expression.
1587 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001588 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001589 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001590 SourceLocation RParenLoc) {
1591 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001592 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001593 RParenLoc);
1594 }
Mike Stump11289f42009-09-09 15:08:12 +00001595
Douglas Gregora16548e2009-08-11 05:31:07 +00001596 /// \brief Build a new overloaded operator call expression.
1597 ///
1598 /// By default, performs semantic analysis to build the new expression.
1599 /// The semantic analysis provides the behavior of template instantiation,
1600 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001601 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001602 /// argument-dependent lookup, etc. Subclasses may override this routine to
1603 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001604 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001605 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001606 Expr *Callee,
1607 Expr *First,
1608 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001609
1610 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001611 /// reinterpret_cast.
1612 ///
1613 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001614 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001615 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001616 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001617 Stmt::StmtClass Class,
1618 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001619 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001620 SourceLocation RAngleLoc,
1621 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001622 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001623 SourceLocation RParenLoc) {
1624 switch (Class) {
1625 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001626 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001627 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001628 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001629
1630 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001631 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001632 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001633 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001634
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001636 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001637 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001638 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001639 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001640
Douglas Gregora16548e2009-08-11 05:31:07 +00001641 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001642 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001643 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001644 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001645
Douglas Gregora16548e2009-08-11 05:31:07 +00001646 default:
1647 assert(false && "Invalid C++ named cast");
1648 break;
1649 }
Mike Stump11289f42009-09-09 15:08:12 +00001650
John McCallfaf5fb42010-08-26 23:41:50 +00001651 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001652 }
Mike Stump11289f42009-09-09 15:08:12 +00001653
Douglas Gregora16548e2009-08-11 05:31:07 +00001654 /// \brief Build a new C++ static_cast expression.
1655 ///
1656 /// By default, performs semantic analysis to build the new expression.
1657 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001658 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001659 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001660 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001661 SourceLocation RAngleLoc,
1662 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001663 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001664 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001665 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001666 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001667 SourceRange(LAngleLoc, RAngleLoc),
1668 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001669 }
1670
1671 /// \brief Build a new C++ dynamic_cast expression.
1672 ///
1673 /// By default, performs semantic analysis to build the new expression.
1674 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001675 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001676 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001677 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001678 SourceLocation RAngleLoc,
1679 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001680 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001681 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001682 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001683 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001684 SourceRange(LAngleLoc, RAngleLoc),
1685 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001686 }
1687
1688 /// \brief Build a new C++ reinterpret_cast expression.
1689 ///
1690 /// By default, performs semantic analysis to build the new expression.
1691 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001692 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001693 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001694 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001695 SourceLocation RAngleLoc,
1696 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001697 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001698 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001699 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001700 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001701 SourceRange(LAngleLoc, RAngleLoc),
1702 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001703 }
1704
1705 /// \brief Build a new C++ const_cast expression.
1706 ///
1707 /// By default, performs semantic analysis to build the new expression.
1708 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001709 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001710 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001711 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001712 SourceLocation RAngleLoc,
1713 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001714 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001715 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001716 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001717 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001718 SourceRange(LAngleLoc, RAngleLoc),
1719 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001720 }
Mike Stump11289f42009-09-09 15:08:12 +00001721
Douglas Gregora16548e2009-08-11 05:31:07 +00001722 /// \brief Build a new C++ functional-style cast expression.
1723 ///
1724 /// By default, performs semantic analysis to build the new expression.
1725 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001726 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1727 SourceLocation LParenLoc,
1728 Expr *Sub,
1729 SourceLocation RParenLoc) {
1730 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001731 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001732 RParenLoc);
1733 }
Mike Stump11289f42009-09-09 15:08:12 +00001734
Douglas Gregora16548e2009-08-11 05:31:07 +00001735 /// \brief Build a new C++ typeid(type) expression.
1736 ///
1737 /// By default, performs semantic analysis to build the new expression.
1738 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001739 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001740 SourceLocation TypeidLoc,
1741 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001742 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001743 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001744 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001745 }
Mike Stump11289f42009-09-09 15:08:12 +00001746
Francois Pichet9f4f2072010-09-08 12:20:18 +00001747
Douglas Gregora16548e2009-08-11 05:31:07 +00001748 /// \brief Build a new C++ typeid(expr) expression.
1749 ///
1750 /// By default, performs semantic analysis to build the new expression.
1751 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001752 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001753 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001754 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001755 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001756 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001757 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001758 }
1759
Francois Pichet9f4f2072010-09-08 12:20:18 +00001760 /// \brief Build a new C++ __uuidof(type) expression.
1761 ///
1762 /// By default, performs semantic analysis to build the new expression.
1763 /// Subclasses may override this routine to provide different behavior.
1764 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1765 SourceLocation TypeidLoc,
1766 TypeSourceInfo *Operand,
1767 SourceLocation RParenLoc) {
1768 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1769 RParenLoc);
1770 }
1771
1772 /// \brief Build a new C++ __uuidof(expr) expression.
1773 ///
1774 /// By default, performs semantic analysis to build the new expression.
1775 /// Subclasses may override this routine to provide different behavior.
1776 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1777 SourceLocation TypeidLoc,
1778 Expr *Operand,
1779 SourceLocation RParenLoc) {
1780 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1781 RParenLoc);
1782 }
1783
Douglas Gregora16548e2009-08-11 05:31:07 +00001784 /// \brief Build a new C++ "this" expression.
1785 ///
1786 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001787 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001788 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001789 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001790 QualType ThisType,
1791 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001792 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001793 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1794 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001795 }
1796
1797 /// \brief Build a new C++ throw expression.
1798 ///
1799 /// By default, performs semantic analysis to build the new expression.
1800 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001801 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001802 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001803 }
1804
1805 /// \brief Build a new C++ default-argument expression.
1806 ///
1807 /// By default, builds a new default-argument expression, which does not
1808 /// require any semantic analysis. Subclasses may override this routine to
1809 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001810 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001811 ParmVarDecl *Param) {
1812 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1813 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001814 }
1815
1816 /// \brief Build a new C++ zero-initialization expression.
1817 ///
1818 /// By default, performs semantic analysis to build the new expression.
1819 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001820 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1821 SourceLocation LParenLoc,
1822 SourceLocation RParenLoc) {
1823 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001824 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001825 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001826 }
Mike Stump11289f42009-09-09 15:08:12 +00001827
Douglas Gregora16548e2009-08-11 05:31:07 +00001828 /// \brief Build a new C++ "new" expression.
1829 ///
1830 /// By default, performs semantic analysis to build the new expression.
1831 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001832 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001833 bool UseGlobal,
1834 SourceLocation PlacementLParen,
1835 MultiExprArg PlacementArgs,
1836 SourceLocation PlacementRParen,
1837 SourceRange TypeIdParens,
1838 QualType AllocatedType,
1839 TypeSourceInfo *AllocatedTypeInfo,
1840 Expr *ArraySize,
1841 SourceLocation ConstructorLParen,
1842 MultiExprArg ConstructorArgs,
1843 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001844 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001845 PlacementLParen,
1846 move(PlacementArgs),
1847 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001848 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001849 AllocatedType,
1850 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001851 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001852 ConstructorLParen,
1853 move(ConstructorArgs),
1854 ConstructorRParen);
1855 }
Mike Stump11289f42009-09-09 15:08:12 +00001856
Douglas Gregora16548e2009-08-11 05:31:07 +00001857 /// \brief Build a new C++ "delete" expression.
1858 ///
1859 /// By default, performs semantic analysis to build the new expression.
1860 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001861 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001862 bool IsGlobalDelete,
1863 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001864 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001865 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001866 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001867 }
Mike Stump11289f42009-09-09 15:08:12 +00001868
Douglas Gregora16548e2009-08-11 05:31:07 +00001869 /// \brief Build a new unary type trait expression.
1870 ///
1871 /// By default, performs semantic analysis to build the new expression.
1872 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001873 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001874 SourceLocation StartLoc,
1875 TypeSourceInfo *T,
1876 SourceLocation RParenLoc) {
1877 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001878 }
1879
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001880 /// \brief Build a new binary type trait expression.
1881 ///
1882 /// By default, performs semantic analysis to build the new expression.
1883 /// Subclasses may override this routine to provide different behavior.
1884 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1885 SourceLocation StartLoc,
1886 TypeSourceInfo *LhsT,
1887 TypeSourceInfo *RhsT,
1888 SourceLocation RParenLoc) {
1889 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1890 }
1891
Mike Stump11289f42009-09-09 15:08:12 +00001892 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001893 /// expression.
1894 ///
1895 /// By default, performs semantic analysis to build the new expression.
1896 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001897 ExprResult RebuildDependentScopeDeclRefExpr(
1898 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001899 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001900 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001901 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001902 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00001903
1904 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001905 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001906 *TemplateArgs);
1907
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001908 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001909 }
1910
1911 /// \brief Build a new template-id expression.
1912 ///
1913 /// By default, performs semantic analysis to build the new expression.
1914 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001915 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001916 LookupResult &R,
1917 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001918 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001919 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001920 }
1921
1922 /// \brief Build a new object-construction expression.
1923 ///
1924 /// By default, performs semantic analysis to build the new expression.
1925 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001926 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001927 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001928 CXXConstructorDecl *Constructor,
1929 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001930 MultiExprArg Args,
1931 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001932 CXXConstructExpr::ConstructionKind ConstructKind,
1933 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001934 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001935 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001936 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001937 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001938
Douglas Gregordb121ba2009-12-14 16:27:04 +00001939 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001940 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001941 RequiresZeroInit, ConstructKind,
1942 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 }
1944
1945 /// \brief Build a new object-construction expression.
1946 ///
1947 /// By default, performs semantic analysis to build the new expression.
1948 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001949 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1950 SourceLocation LParenLoc,
1951 MultiExprArg Args,
1952 SourceLocation RParenLoc) {
1953 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001954 LParenLoc,
1955 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001956 RParenLoc);
1957 }
1958
1959 /// \brief Build a new object-construction expression.
1960 ///
1961 /// By default, performs semantic analysis to build the new expression.
1962 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001963 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1964 SourceLocation LParenLoc,
1965 MultiExprArg Args,
1966 SourceLocation RParenLoc) {
1967 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001968 LParenLoc,
1969 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001970 RParenLoc);
1971 }
Mike Stump11289f42009-09-09 15:08:12 +00001972
Douglas Gregora16548e2009-08-11 05:31:07 +00001973 /// \brief Build a new member reference expression.
1974 ///
1975 /// By default, performs semantic analysis to build the new expression.
1976 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001977 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00001978 QualType BaseType,
1979 bool IsArrow,
1980 SourceLocation OperatorLoc,
1981 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00001982 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001983 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001984 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001985 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00001986 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001987
John McCallb268a282010-08-23 23:25:46 +00001988 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001989 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001990 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001991 MemberNameInfo,
1992 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001993 }
1994
John McCall10eae182009-11-30 22:42:35 +00001995 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001996 ///
1997 /// By default, performs semantic analysis to build the new expression.
1998 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001999 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00002000 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00002001 SourceLocation OperatorLoc,
2002 bool IsArrow,
Douglas Gregor0da1d432011-02-28 20:01:57 +00002003 NestedNameSpecifierLoc QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00002004 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00002005 LookupResult &R,
2006 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002007 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002008 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002009
John McCallb268a282010-08-23 23:25:46 +00002010 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002011 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00002012 SS, FirstQualifierInScope,
2013 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002014 }
Mike Stump11289f42009-09-09 15:08:12 +00002015
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002016 /// \brief Build a new noexcept expression.
2017 ///
2018 /// By default, performs semantic analysis to build the new expression.
2019 /// Subclasses may override this routine to provide different behavior.
2020 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2021 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2022 }
2023
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002024 /// \brief Build a new expression to compute the length of a parameter pack.
2025 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2026 SourceLocation PackLoc,
2027 SourceLocation RParenLoc,
2028 unsigned Length) {
2029 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2030 OperatorLoc, Pack, PackLoc,
2031 RParenLoc, Length);
2032 }
2033
Douglas Gregora16548e2009-08-11 05:31:07 +00002034 /// \brief Build a new Objective-C @encode expression.
2035 ///
2036 /// By default, performs semantic analysis to build the new expression.
2037 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002038 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002039 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002040 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002041 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002042 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002043 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002044
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002045 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002046 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002047 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002048 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002049 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002050 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002051 MultiExprArg Args,
2052 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002053 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2054 ReceiverTypeInfo->getType(),
2055 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002056 Sel, Method, LBracLoc, SelectorLoc,
2057 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002058 }
2059
2060 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002061 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002062 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002063 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002064 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002065 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002066 MultiExprArg Args,
2067 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002068 return SemaRef.BuildInstanceMessage(Receiver,
2069 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002070 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002071 Sel, Method, LBracLoc, SelectorLoc,
2072 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002073 }
2074
Douglas Gregord51d90d2010-04-26 20:11:03 +00002075 /// \brief Build a new Objective-C ivar reference expression.
2076 ///
2077 /// By default, performs semantic analysis to build the new expression.
2078 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002079 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002080 SourceLocation IvarLoc,
2081 bool IsArrow, bool IsFreeIvar) {
2082 // FIXME: We lose track of the IsFreeIvar bit.
2083 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002084 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002085 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2086 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002087 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002088 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002089 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002090 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002091 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002092 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002093
Douglas Gregord51d90d2010-04-26 20:11:03 +00002094 if (Result.get())
2095 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002096
John McCallb268a282010-08-23 23:25:46 +00002097 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002098 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002099 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002100 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002101 /*TemplateArgs=*/0);
2102 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002103
2104 /// \brief Build a new Objective-C property reference expression.
2105 ///
2106 /// By default, performs semantic analysis to build the new expression.
2107 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002108 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002109 ObjCPropertyDecl *Property,
2110 SourceLocation PropertyLoc) {
2111 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002112 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00002113 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2114 Sema::LookupMemberName);
2115 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002116 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002117 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002118 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00002119 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002120 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002121
Douglas Gregor9faee212010-04-26 20:47:02 +00002122 if (Result.get())
2123 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002124
John McCallb268a282010-08-23 23:25:46 +00002125 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002126 /*FIXME:*/PropertyLoc, IsArrow,
2127 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002128 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002129 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002130 /*TemplateArgs=*/0);
2131 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002132
John McCallb7bd14f2010-12-02 01:19:52 +00002133 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002134 ///
2135 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002136 /// Subclasses may override this routine to provide different behavior.
2137 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2138 ObjCMethodDecl *Getter,
2139 ObjCMethodDecl *Setter,
2140 SourceLocation PropertyLoc) {
2141 // Since these expressions can only be value-dependent, we do not
2142 // need to perform semantic analysis again.
2143 return Owned(
2144 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2145 VK_LValue, OK_ObjCProperty,
2146 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002147 }
2148
Douglas Gregord51d90d2010-04-26 20:11:03 +00002149 /// \brief Build a new Objective-C "isa" expression.
2150 ///
2151 /// By default, performs semantic analysis to build the new expression.
2152 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002153 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002154 bool IsArrow) {
2155 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002156 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002157 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2158 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002159 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002160 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002161 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002162 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002163 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002164
Douglas Gregord51d90d2010-04-26 20:11:03 +00002165 if (Result.get())
2166 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002167
John McCallb268a282010-08-23 23:25:46 +00002168 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002169 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002170 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002171 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002172 /*TemplateArgs=*/0);
2173 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002174
Douglas Gregora16548e2009-08-11 05:31:07 +00002175 /// \brief Build a new shuffle vector expression.
2176 ///
2177 /// By default, performs semantic analysis to build the new expression.
2178 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002179 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002180 MultiExprArg SubExprs,
2181 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002182 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002183 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2185 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2186 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2187 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002188
Douglas Gregora16548e2009-08-11 05:31:07 +00002189 // Build a reference to the __builtin_shufflevector builtin
2190 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00002191 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00002192 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00002193 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002194 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002195
2196 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002197 unsigned NumSubExprs = SubExprs.size();
2198 Expr **Subs = (Expr **)SubExprs.release();
2199 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2200 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002201 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002202 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002203 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002204 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002205
Douglas Gregora16548e2009-08-11 05:31:07 +00002206 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002207 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002208 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002209 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002210
Douglas Gregora16548e2009-08-11 05:31:07 +00002211 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002212 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002213 }
John McCall31f82722010-11-12 08:19:04 +00002214
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002215 /// \brief Build a new template argument pack expansion.
2216 ///
2217 /// By default, performs semantic analysis to build a new pack expansion
2218 /// for a template argument. Subclasses may override this routine to provide
2219 /// different behavior.
2220 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002221 SourceLocation EllipsisLoc,
2222 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002223 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002224 case TemplateArgument::Expression: {
2225 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002226 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2227 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002228 if (Result.isInvalid())
2229 return TemplateArgumentLoc();
2230
2231 return TemplateArgumentLoc(Result.get(), Result.get());
2232 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002233
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002234 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002235 return TemplateArgumentLoc(TemplateArgument(
2236 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002237 NumExpansions),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002238 Pattern.getTemplateQualifierRange(),
2239 Pattern.getTemplateNameLoc(),
2240 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002241
2242 case TemplateArgument::Null:
2243 case TemplateArgument::Integral:
2244 case TemplateArgument::Declaration:
2245 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002246 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002247 llvm_unreachable("Pack expansion pattern has no parameter packs");
2248
2249 case TemplateArgument::Type:
2250 if (TypeSourceInfo *Expansion
2251 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002252 EllipsisLoc,
2253 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002254 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2255 Expansion);
2256 break;
2257 }
2258
2259 return TemplateArgumentLoc();
2260 }
2261
Douglas Gregor968f23a2011-01-03 19:31:53 +00002262 /// \brief Build a new expression pack expansion.
2263 ///
2264 /// By default, performs semantic analysis to build a new pack expansion
2265 /// for an expression. Subclasses may override this routine to provide
2266 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002267 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2268 llvm::Optional<unsigned> NumExpansions) {
2269 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002270 }
2271
John McCall31f82722010-11-12 08:19:04 +00002272private:
2273 QualType TransformTypeInObjectScope(QualType T,
2274 QualType ObjectType,
2275 NamedDecl *FirstQualifierInScope,
2276 NestedNameSpecifier *Prefix);
2277
2278 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2279 QualType ObjectType,
2280 NamedDecl *FirstQualifierInScope,
2281 NestedNameSpecifier *Prefix);
Douglas Gregor14454802011-02-25 02:25:35 +00002282
2283 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2284 QualType ObjectType,
2285 NamedDecl *FirstQualifierInScope,
2286 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002287};
Douglas Gregora16548e2009-08-11 05:31:07 +00002288
Douglas Gregorebe10102009-08-20 07:17:43 +00002289template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002290StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002291 if (!S)
2292 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002293
Douglas Gregorebe10102009-08-20 07:17:43 +00002294 switch (S->getStmtClass()) {
2295 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002296
Douglas Gregorebe10102009-08-20 07:17:43 +00002297 // Transform individual statement nodes
2298#define STMT(Node, Parent) \
2299 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002300#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002301#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002302#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002303
Douglas Gregorebe10102009-08-20 07:17:43 +00002304 // Transform expressions by calling TransformExpr.
2305#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002306#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002307#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002308#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002309 {
John McCalldadc5752010-08-24 06:29:42 +00002310 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002311 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002312 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002313
John McCallb268a282010-08-23 23:25:46 +00002314 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002315 }
Mike Stump11289f42009-09-09 15:08:12 +00002316 }
2317
John McCallc3007a22010-10-26 07:05:15 +00002318 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002319}
Mike Stump11289f42009-09-09 15:08:12 +00002320
2321
Douglas Gregore922c772009-08-04 22:27:00 +00002322template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002323ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002324 if (!E)
2325 return SemaRef.Owned(E);
2326
2327 switch (E->getStmtClass()) {
2328 case Stmt::NoStmtClass: break;
2329#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002330#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002331#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002332 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002333#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002334 }
2335
John McCallc3007a22010-10-26 07:05:15 +00002336 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002337}
2338
2339template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002340bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2341 unsigned NumInputs,
2342 bool IsCall,
2343 llvm::SmallVectorImpl<Expr *> &Outputs,
2344 bool *ArgChanged) {
2345 for (unsigned I = 0; I != NumInputs; ++I) {
2346 // If requested, drop call arguments that need to be dropped.
2347 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2348 if (ArgChanged)
2349 *ArgChanged = true;
2350
2351 break;
2352 }
2353
Douglas Gregor968f23a2011-01-03 19:31:53 +00002354 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2355 Expr *Pattern = Expansion->getPattern();
2356
2357 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2358 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2359 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2360
2361 // Determine whether the set of unexpanded parameter packs can and should
2362 // be expanded.
2363 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002364 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002365 llvm::Optional<unsigned> OrigNumExpansions
2366 = Expansion->getNumExpansions();
2367 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002368 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2369 Pattern->getSourceRange(),
2370 Unexpanded.data(),
2371 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002372 Expand, RetainExpansion,
2373 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002374 return true;
2375
2376 if (!Expand) {
2377 // The transform has determined that we should perform a simple
2378 // transformation on the pack expansion, producing another pack
2379 // expansion.
2380 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2381 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2382 if (OutPattern.isInvalid())
2383 return true;
2384
2385 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002386 Expansion->getEllipsisLoc(),
2387 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002388 if (Out.isInvalid())
2389 return true;
2390
2391 if (ArgChanged)
2392 *ArgChanged = true;
2393 Outputs.push_back(Out.get());
2394 continue;
2395 }
2396
2397 // The transform has determined that we should perform an elementwise
2398 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002399 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002400 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2401 ExprResult Out = getDerived().TransformExpr(Pattern);
2402 if (Out.isInvalid())
2403 return true;
2404
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002405 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002406 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2407 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002408 if (Out.isInvalid())
2409 return true;
2410 }
2411
Douglas Gregor968f23a2011-01-03 19:31:53 +00002412 if (ArgChanged)
2413 *ArgChanged = true;
2414 Outputs.push_back(Out.get());
2415 }
2416
2417 continue;
2418 }
2419
Douglas Gregora3efea12011-01-03 19:04:46 +00002420 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2421 if (Result.isInvalid())
2422 return true;
2423
2424 if (Result.get() != Inputs[I] && ArgChanged)
2425 *ArgChanged = true;
2426
2427 Outputs.push_back(Result.get());
2428 }
2429
2430 return false;
2431}
2432
2433template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002434NestedNameSpecifier *
2435TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002436 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002437 QualType ObjectType,
2438 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002439 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002440
Douglas Gregorebe10102009-08-20 07:17:43 +00002441 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002442 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002443 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002444 ObjectType,
2445 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002446 if (!Prefix)
2447 return 0;
2448 }
Mike Stump11289f42009-09-09 15:08:12 +00002449
Douglas Gregor1135c352009-08-06 05:28:30 +00002450 switch (NNS->getKind()) {
2451 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002452 if (Prefix) {
2453 // The object type and qualifier-in-scope really apply to the
2454 // leftmost entity.
2455 ObjectType = QualType();
2456 FirstQualifierInScope = 0;
2457 }
2458
Mike Stump11289f42009-09-09 15:08:12 +00002459 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002460 "Identifier nested-name-specifier with no prefix or object type");
2461 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2462 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002463 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002464
2465 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002466 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002467 ObjectType,
2468 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002469
Douglas Gregor1135c352009-08-06 05:28:30 +00002470 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002471 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002472 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002473 getDerived().TransformDecl(Range.getBegin(),
2474 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002475 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002476 Prefix == NNS->getPrefix() &&
2477 NS == NNS->getAsNamespace())
2478 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002479
Douglas Gregor1135c352009-08-06 05:28:30 +00002480 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2481 }
Mike Stump11289f42009-09-09 15:08:12 +00002482
Douglas Gregor7b26ff92011-02-24 02:36:08 +00002483 case NestedNameSpecifier::NamespaceAlias: {
2484 NamespaceAliasDecl *Alias
2485 = cast_or_null<NamespaceAliasDecl>(
2486 getDerived().TransformDecl(Range.getBegin(),
2487 NNS->getAsNamespaceAlias()));
2488 if (!getDerived().AlwaysRebuild() &&
2489 Prefix == NNS->getPrefix() &&
2490 Alias == NNS->getAsNamespaceAlias())
2491 return NNS;
2492
2493 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, Alias);
2494 }
2495
Douglas Gregor1135c352009-08-06 05:28:30 +00002496 case NestedNameSpecifier::Global:
2497 // There is no meaningful transformation that one could perform on the
2498 // global scope.
2499 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002500
Douglas Gregor1135c352009-08-06 05:28:30 +00002501 case NestedNameSpecifier::TypeSpecWithTemplate:
2502 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002503 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002504 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2505 ObjectType,
2506 FirstQualifierInScope,
2507 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002508 if (T.isNull())
2509 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002510
Douglas Gregor1135c352009-08-06 05:28:30 +00002511 if (!getDerived().AlwaysRebuild() &&
2512 Prefix == NNS->getPrefix() &&
2513 T == QualType(NNS->getAsType(), 0))
2514 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002515
2516 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2517 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002518 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002519 }
2520 }
Mike Stump11289f42009-09-09 15:08:12 +00002521
Douglas Gregor1135c352009-08-06 05:28:30 +00002522 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002523 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002524}
2525
2526template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002527NestedNameSpecifierLoc
2528TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2529 NestedNameSpecifierLoc NNS,
2530 QualType ObjectType,
2531 NamedDecl *FirstQualifierInScope) {
2532 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2533 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2534 Qualifier = Qualifier.getPrefix())
2535 Qualifiers.push_back(Qualifier);
2536
2537 CXXScopeSpec SS;
2538 while (!Qualifiers.empty()) {
2539 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2540 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2541
2542 switch (QNNS->getKind()) {
2543 case NestedNameSpecifier::Identifier:
2544 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2545 *QNNS->getAsIdentifier(),
2546 Q.getLocalBeginLoc(),
2547 Q.getLocalEndLoc(),
2548 ObjectType, false, SS,
2549 FirstQualifierInScope, false))
2550 return NestedNameSpecifierLoc();
2551
2552 break;
2553
2554 case NestedNameSpecifier::Namespace: {
2555 NamespaceDecl *NS
2556 = cast_or_null<NamespaceDecl>(
2557 getDerived().TransformDecl(
2558 Q.getLocalBeginLoc(),
2559 QNNS->getAsNamespace()));
2560 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2561 break;
2562 }
2563
2564 case NestedNameSpecifier::NamespaceAlias: {
2565 NamespaceAliasDecl *Alias
2566 = cast_or_null<NamespaceAliasDecl>(
2567 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2568 QNNS->getAsNamespaceAlias()));
2569 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2570 Q.getLocalEndLoc());
2571 break;
2572 }
2573
2574 case NestedNameSpecifier::Global:
2575 // There is no meaningful transformation that one could perform on the
2576 // global scope.
2577 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2578 break;
2579
2580 case NestedNameSpecifier::TypeSpecWithTemplate:
2581 case NestedNameSpecifier::TypeSpec: {
2582 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2583 FirstQualifierInScope, SS);
2584
2585 if (!TL)
2586 return NestedNameSpecifierLoc();
2587
2588 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2589 (SemaRef.getLangOptions().CPlusPlus0x &&
2590 TL.getType()->isEnumeralType())) {
2591 assert(!TL.getType().hasLocalQualifiers() &&
2592 "Can't get cv-qualifiers here");
2593 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2594 Q.getLocalEndLoc());
2595 break;
2596 }
2597
2598 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2599 << TL.getType() << SS.getRange();
2600 return NestedNameSpecifierLoc();
2601 }
Douglas Gregore16af532011-02-28 18:50:33 +00002602 }
Douglas Gregor14454802011-02-25 02:25:35 +00002603
Douglas Gregore16af532011-02-28 18:50:33 +00002604 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002605 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002606 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002607 }
2608
2609 // Don't rebuild the nested-name-specifier if we don't have to.
2610 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2611 !getDerived().AlwaysRebuild())
2612 return NNS;
2613
2614 // If we can re-use the source-location data from the original
2615 // nested-name-specifier, do so.
2616 if (SS.location_size() == NNS.getDataLength() &&
2617 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2618 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2619
2620 // Allocate new nested-name-specifier location information.
2621 return SS.getWithLocInContext(SemaRef.Context);
2622}
2623
2624template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002625DeclarationNameInfo
2626TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002627::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002628 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002629 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002630 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002631
2632 switch (Name.getNameKind()) {
2633 case DeclarationName::Identifier:
2634 case DeclarationName::ObjCZeroArgSelector:
2635 case DeclarationName::ObjCOneArgSelector:
2636 case DeclarationName::ObjCMultiArgSelector:
2637 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002638 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002639 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002640 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002641
Douglas Gregorf816bd72009-09-03 22:13:48 +00002642 case DeclarationName::CXXConstructorName:
2643 case DeclarationName::CXXDestructorName:
2644 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002645 TypeSourceInfo *NewTInfo;
2646 CanQualType NewCanTy;
2647 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002648 NewTInfo = getDerived().TransformType(OldTInfo);
2649 if (!NewTInfo)
2650 return DeclarationNameInfo();
2651 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002652 }
2653 else {
2654 NewTInfo = 0;
2655 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002656 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002657 if (NewT.isNull())
2658 return DeclarationNameInfo();
2659 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2660 }
Mike Stump11289f42009-09-09 15:08:12 +00002661
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002662 DeclarationName NewName
2663 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2664 NewCanTy);
2665 DeclarationNameInfo NewNameInfo(NameInfo);
2666 NewNameInfo.setName(NewName);
2667 NewNameInfo.setNamedTypeInfo(NewTInfo);
2668 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002669 }
Mike Stump11289f42009-09-09 15:08:12 +00002670 }
2671
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002672 assert(0 && "Unknown name kind.");
2673 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002674}
2675
2676template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002677TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002678TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002679 QualType ObjectType,
2680 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002681 SourceLocation Loc = getDerived().getBaseLocation();
2682
Douglas Gregor71dc5092009-08-06 06:41:21 +00002683 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002684 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002685 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002686 /*FIXME*/ SourceRange(Loc),
2687 ObjectType,
2688 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002689 if (!NNS)
2690 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002691
Douglas Gregor71dc5092009-08-06 06:41:21 +00002692 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002693 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002694 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002695 if (!TransTemplate)
2696 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002697
Douglas Gregor71dc5092009-08-06 06:41:21 +00002698 if (!getDerived().AlwaysRebuild() &&
2699 NNS == QTN->getQualifier() &&
2700 TransTemplate == Template)
2701 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002702
Douglas Gregor71dc5092009-08-06 06:41:21 +00002703 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2704 TransTemplate);
2705 }
Mike Stump11289f42009-09-09 15:08:12 +00002706
John McCalle66edc12009-11-24 19:00:30 +00002707 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002708 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002709 }
Mike Stump11289f42009-09-09 15:08:12 +00002710
Douglas Gregor71dc5092009-08-06 06:41:21 +00002711 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002712 NestedNameSpecifier *NNS = DTN->getQualifier();
2713 if (NNS) {
2714 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2715 /*FIXME:*/SourceRange(Loc),
2716 ObjectType,
2717 FirstQualifierInScope);
2718 if (!NNS) return TemplateName();
2719
2720 // These apply to the scope specifier, not the template.
2721 ObjectType = QualType();
2722 FirstQualifierInScope = 0;
2723 }
Mike Stump11289f42009-09-09 15:08:12 +00002724
Douglas Gregor71dc5092009-08-06 06:41:21 +00002725 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002726 NNS == DTN->getQualifier() &&
2727 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002728 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002729
Douglas Gregora5614c52010-09-08 23:56:00 +00002730 if (DTN->isIdentifier()) {
2731 // FIXME: Bad range
2732 SourceRange QualifierRange(getDerived().getBaseLocation());
2733 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2734 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002735 ObjectType,
2736 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002737 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002738
2739 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002740 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002741 }
Mike Stump11289f42009-09-09 15:08:12 +00002742
Douglas Gregor71dc5092009-08-06 06:41:21 +00002743 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002744 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002745 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002746 if (!TransTemplate)
2747 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002748
Douglas Gregor71dc5092009-08-06 06:41:21 +00002749 if (!getDerived().AlwaysRebuild() &&
2750 TransTemplate == Template)
2751 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002752
Douglas Gregor71dc5092009-08-06 06:41:21 +00002753 return TemplateName(TransTemplate);
2754 }
Mike Stump11289f42009-09-09 15:08:12 +00002755
Douglas Gregor5590be02011-01-15 06:45:20 +00002756 if (SubstTemplateTemplateParmPackStorage *SubstPack
2757 = Name.getAsSubstTemplateTemplateParmPack()) {
2758 TemplateTemplateParmDecl *TransParam
2759 = cast_or_null<TemplateTemplateParmDecl>(
2760 getDerived().TransformDecl(Loc, SubstPack->getParameterPack()));
2761 if (!TransParam)
2762 return TemplateName();
2763
2764 if (!getDerived().AlwaysRebuild() &&
2765 TransParam == SubstPack->getParameterPack())
2766 return Name;
2767
2768 return getDerived().RebuildTemplateName(TransParam,
2769 SubstPack->getArgumentPack());
2770 }
2771
John McCalle66edc12009-11-24 19:00:30 +00002772 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002773 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002774 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002775}
2776
2777template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002778void TreeTransform<Derived>::InventTemplateArgumentLoc(
2779 const TemplateArgument &Arg,
2780 TemplateArgumentLoc &Output) {
2781 SourceLocation Loc = getDerived().getBaseLocation();
2782 switch (Arg.getKind()) {
2783 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002784 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002785 break;
2786
2787 case TemplateArgument::Type:
2788 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002789 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002790
John McCall0ad16662009-10-29 08:12:44 +00002791 break;
2792
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002793 case TemplateArgument::Template:
2794 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2795 break;
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002796
2797 case TemplateArgument::TemplateExpansion:
2798 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2799 break;
2800
John McCall0ad16662009-10-29 08:12:44 +00002801 case TemplateArgument::Expression:
2802 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2803 break;
2804
2805 case TemplateArgument::Declaration:
2806 case TemplateArgument::Integral:
2807 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002808 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002809 break;
2810 }
2811}
2812
2813template<typename Derived>
2814bool TreeTransform<Derived>::TransformTemplateArgument(
2815 const TemplateArgumentLoc &Input,
2816 TemplateArgumentLoc &Output) {
2817 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002818 switch (Arg.getKind()) {
2819 case TemplateArgument::Null:
2820 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002821 Output = Input;
2822 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002823
Douglas Gregore922c772009-08-04 22:27:00 +00002824 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002825 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002826 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002827 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002828
2829 DI = getDerived().TransformType(DI);
2830 if (!DI) return true;
2831
2832 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2833 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002834 }
Mike Stump11289f42009-09-09 15:08:12 +00002835
Douglas Gregore922c772009-08-04 22:27:00 +00002836 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002837 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002838 DeclarationName Name;
2839 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2840 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002841 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002842 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002843 if (!D) return true;
2844
John McCall0d07eb32009-10-29 18:45:58 +00002845 Expr *SourceExpr = Input.getSourceDeclExpression();
2846 if (SourceExpr) {
2847 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002848 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002849 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002850 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002851 }
2852
2853 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002854 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002855 }
Mike Stump11289f42009-09-09 15:08:12 +00002856
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002857 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002858 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002859 TemplateName Template
2860 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2861 if (Template.isNull())
2862 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002863
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002864 Output = TemplateArgumentLoc(TemplateArgument(Template),
2865 Input.getTemplateQualifierRange(),
2866 Input.getTemplateNameLoc());
2867 return false;
2868 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002869
2870 case TemplateArgument::TemplateExpansion:
2871 llvm_unreachable("Caller should expand pack expansions");
2872
Douglas Gregore922c772009-08-04 22:27:00 +00002873 case TemplateArgument::Expression: {
2874 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002875 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002876 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002877
John McCall0ad16662009-10-29 08:12:44 +00002878 Expr *InputExpr = Input.getSourceExpression();
2879 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2880
John McCalldadc5752010-08-24 06:29:42 +00002881 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002882 = getDerived().TransformExpr(InputExpr);
2883 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002884 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002885 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002886 }
Mike Stump11289f42009-09-09 15:08:12 +00002887
Douglas Gregore922c772009-08-04 22:27:00 +00002888 case TemplateArgument::Pack: {
2889 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2890 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002891 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002892 AEnd = Arg.pack_end();
2893 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002894
John McCall0ad16662009-10-29 08:12:44 +00002895 // FIXME: preserve source information here when we start
2896 // caring about parameter packs.
2897
John McCall0d07eb32009-10-29 18:45:58 +00002898 TemplateArgumentLoc InputArg;
2899 TemplateArgumentLoc OutputArg;
2900 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2901 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002902 return true;
2903
John McCall0d07eb32009-10-29 18:45:58 +00002904 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002905 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002906
2907 TemplateArgument *TransformedArgsPtr
2908 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2909 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2910 TransformedArgsPtr);
2911 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2912 TransformedArgs.size()),
2913 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002914 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002915 }
2916 }
Mike Stump11289f42009-09-09 15:08:12 +00002917
Douglas Gregore922c772009-08-04 22:27:00 +00002918 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002919 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002920}
2921
Douglas Gregorfe921a72010-12-20 23:36:19 +00002922/// \brief Iterator adaptor that invents template argument location information
2923/// for each of the template arguments in its underlying iterator.
2924template<typename Derived, typename InputIterator>
2925class TemplateArgumentLocInventIterator {
2926 TreeTransform<Derived> &Self;
2927 InputIterator Iter;
2928
2929public:
2930 typedef TemplateArgumentLoc value_type;
2931 typedef TemplateArgumentLoc reference;
2932 typedef typename std::iterator_traits<InputIterator>::difference_type
2933 difference_type;
2934 typedef std::input_iterator_tag iterator_category;
2935
2936 class pointer {
2937 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002938
Douglas Gregorfe921a72010-12-20 23:36:19 +00002939 public:
2940 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2941
2942 const TemplateArgumentLoc *operator->() const { return &Arg; }
2943 };
2944
2945 TemplateArgumentLocInventIterator() { }
2946
2947 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2948 InputIterator Iter)
2949 : Self(Self), Iter(Iter) { }
2950
2951 TemplateArgumentLocInventIterator &operator++() {
2952 ++Iter;
2953 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002954 }
2955
Douglas Gregorfe921a72010-12-20 23:36:19 +00002956 TemplateArgumentLocInventIterator operator++(int) {
2957 TemplateArgumentLocInventIterator Old(*this);
2958 ++(*this);
2959 return Old;
2960 }
2961
2962 reference operator*() const {
2963 TemplateArgumentLoc Result;
2964 Self.InventTemplateArgumentLoc(*Iter, Result);
2965 return Result;
2966 }
2967
2968 pointer operator->() const { return pointer(**this); }
2969
2970 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2971 const TemplateArgumentLocInventIterator &Y) {
2972 return X.Iter == Y.Iter;
2973 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002974
Douglas Gregorfe921a72010-12-20 23:36:19 +00002975 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2976 const TemplateArgumentLocInventIterator &Y) {
2977 return X.Iter != Y.Iter;
2978 }
2979};
2980
Douglas Gregor42cafa82010-12-20 17:42:22 +00002981template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002982template<typename InputIterator>
2983bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2984 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002985 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002986 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002987 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002988 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002989
2990 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2991 // Unpack argument packs, which we translate them into separate
2992 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002993 // FIXME: We could do much better if we could guarantee that the
2994 // TemplateArgumentLocInfo for the pack expansion would be usable for
2995 // all of the template arguments in the argument pack.
2996 typedef TemplateArgumentLocInventIterator<Derived,
2997 TemplateArgument::pack_iterator>
2998 PackLocIterator;
2999 if (TransformTemplateArguments(PackLocIterator(*this,
3000 In.getArgument().pack_begin()),
3001 PackLocIterator(*this,
3002 In.getArgument().pack_end()),
3003 Outputs))
3004 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003005
3006 continue;
3007 }
3008
3009 if (In.getArgument().isPackExpansion()) {
3010 // We have a pack expansion, for which we will be substituting into
3011 // the pattern.
3012 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003013 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003014 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003015 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3016 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003017
3018 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3019 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3020 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3021
3022 // Determine whether the set of unexpanded parameter packs can and should
3023 // be expanded.
3024 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003025 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003026 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003027 if (getDerived().TryExpandParameterPacks(Ellipsis,
3028 Pattern.getSourceRange(),
3029 Unexpanded.data(),
3030 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003031 Expand,
3032 RetainExpansion,
3033 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003034 return true;
3035
3036 if (!Expand) {
3037 // The transform has determined that we should perform a simple
3038 // transformation on the pack expansion, producing another pack
3039 // expansion.
3040 TemplateArgumentLoc OutPattern;
3041 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3042 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3043 return true;
3044
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003045 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3046 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003047 if (Out.getArgument().isNull())
3048 return true;
3049
3050 Outputs.addArgument(Out);
3051 continue;
3052 }
3053
3054 // The transform has determined that we should perform an elementwise
3055 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003056 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003057 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3058
3059 if (getDerived().TransformTemplateArgument(Pattern, Out))
3060 return true;
3061
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003062 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003063 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3064 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003065 if (Out.getArgument().isNull())
3066 return true;
3067 }
3068
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003069 Outputs.addArgument(Out);
3070 }
3071
Douglas Gregor48d24112011-01-10 20:53:55 +00003072 // If we're supposed to retain a pack expansion, do so by temporarily
3073 // forgetting the partially-substituted parameter pack.
3074 if (RetainExpansion) {
3075 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3076
3077 if (getDerived().TransformTemplateArgument(Pattern, Out))
3078 return true;
3079
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003080 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3081 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003082 if (Out.getArgument().isNull())
3083 return true;
3084
3085 Outputs.addArgument(Out);
3086 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003087
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003088 continue;
3089 }
3090
3091 // The simple case:
3092 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003093 return true;
3094
3095 Outputs.addArgument(Out);
3096 }
3097
3098 return false;
3099
3100}
3101
Douglas Gregord6ff3322009-08-04 16:50:30 +00003102//===----------------------------------------------------------------------===//
3103// Type transformation
3104//===----------------------------------------------------------------------===//
3105
3106template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003107QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003108 if (getDerived().AlreadyTransformed(T))
3109 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003110
John McCall550e0c22009-10-21 00:40:46 +00003111 // Temporary workaround. All of these transformations should
3112 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003113 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3114 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003115
John McCall31f82722010-11-12 08:19:04 +00003116 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003117
John McCall550e0c22009-10-21 00:40:46 +00003118 if (!NewDI)
3119 return QualType();
3120
3121 return NewDI->getType();
3122}
3123
3124template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003125TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003126 if (getDerived().AlreadyTransformed(DI->getType()))
3127 return DI;
3128
3129 TypeLocBuilder TLB;
3130
3131 TypeLoc TL = DI->getTypeLoc();
3132 TLB.reserve(TL.getFullDataSize());
3133
John McCall31f82722010-11-12 08:19:04 +00003134 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003135 if (Result.isNull())
3136 return 0;
3137
John McCallbcd03502009-12-07 02:54:59 +00003138 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003139}
3140
3141template<typename Derived>
3142QualType
John McCall31f82722010-11-12 08:19:04 +00003143TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003144 switch (T.getTypeLocClass()) {
3145#define ABSTRACT_TYPELOC(CLASS, PARENT)
3146#define TYPELOC(CLASS, PARENT) \
3147 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003148 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003149#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003150 }
Mike Stump11289f42009-09-09 15:08:12 +00003151
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003152 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003153 return QualType();
3154}
3155
3156/// FIXME: By default, this routine adds type qualifiers only to types
3157/// that can have qualifiers, and silently suppresses those qualifiers
3158/// that are not permitted (e.g., qualifiers on reference or function
3159/// types). This is the right thing for template instantiation, but
3160/// probably not for other clients.
3161template<typename Derived>
3162QualType
3163TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003164 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003165 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003166
John McCall31f82722010-11-12 08:19:04 +00003167 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003168 if (Result.isNull())
3169 return QualType();
3170
3171 // Silently suppress qualifiers if the result type can't be qualified.
3172 // FIXME: this is the right thing for template instantiation, but
3173 // probably not for other clients.
3174 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003175 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003176
John McCallcb0f89a2010-06-05 06:41:15 +00003177 if (!Quals.empty()) {
3178 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3179 TLB.push<QualifiedTypeLoc>(Result);
3180 // No location information to preserve.
3181 }
John McCall550e0c22009-10-21 00:40:46 +00003182
3183 return Result;
3184}
3185
John McCall31f82722010-11-12 08:19:04 +00003186/// \brief Transforms a type that was written in a scope specifier,
3187/// given an object type, the results of unqualified lookup, and
3188/// an already-instantiated prefix.
3189///
3190/// The object type is provided iff the scope specifier qualifies the
3191/// member of a dependent member-access expression. The prefix is
3192/// provided iff the the scope specifier in which this appears has a
3193/// prefix.
3194///
3195/// This is private to TreeTransform.
3196template<typename Derived>
3197QualType
3198TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
3199 QualType ObjectType,
3200 NamedDecl *UnqualLookup,
3201 NestedNameSpecifier *Prefix) {
3202 if (getDerived().AlreadyTransformed(T))
3203 return T;
3204
3205 TypeSourceInfo *TSI =
Douglas Gregor2d525f02011-01-25 19:13:18 +00003206 SemaRef.Context.getTrivialTypeSourceInfo(T, getDerived().getBaseLocation());
John McCall31f82722010-11-12 08:19:04 +00003207
3208 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
3209 UnqualLookup, Prefix);
3210 if (!TSI) return QualType();
3211 return TSI->getType();
3212}
3213
3214template<typename Derived>
3215TypeSourceInfo *
3216TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
3217 QualType ObjectType,
3218 NamedDecl *UnqualLookup,
3219 NestedNameSpecifier *Prefix) {
Douglas Gregor14454802011-02-25 02:25:35 +00003220 // TODO: in some cases, we might have some verification to do here.
John McCall31f82722010-11-12 08:19:04 +00003221 if (ObjectType.isNull())
3222 return getDerived().TransformType(TSI);
3223
3224 QualType T = TSI->getType();
3225 if (getDerived().AlreadyTransformed(T))
3226 return TSI;
3227
3228 TypeLocBuilder TLB;
3229 QualType Result;
3230
3231 if (isa<TemplateSpecializationType>(T)) {
3232 TemplateSpecializationTypeLoc TL
3233 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3234
3235 TemplateName Template =
3236 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
3237 ObjectType, UnqualLookup);
3238 if (Template.isNull()) return 0;
3239
3240 Result = getDerived()
3241 .TransformTemplateSpecializationType(TLB, TL, Template);
3242 } else if (isa<DependentTemplateSpecializationType>(T)) {
3243 DependentTemplateSpecializationTypeLoc TL
3244 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3245
Douglas Gregor5a064722011-02-28 17:23:35 +00003246 TemplateName Template
3247 = SemaRef.Context.getDependentTemplateName(
3248 TL.getTypePtr()->getQualifier(),
3249 TL.getTypePtr()->getIdentifier());
3250
3251 Template = getDerived().TransformTemplateName(Template, ObjectType,
3252 UnqualLookup);
3253 if (Template.isNull())
3254 return 0;
3255
3256 Result = getDerived().TransformDependentTemplateSpecializationType(TLB, TL,
3257 Template);
John McCall31f82722010-11-12 08:19:04 +00003258 } else {
3259 // Nothing special needs to be done for these.
3260 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
3261 }
3262
3263 if (Result.isNull()) return 0;
3264 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3265}
3266
Douglas Gregor14454802011-02-25 02:25:35 +00003267template<typename Derived>
3268TypeLoc
3269TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3270 QualType ObjectType,
3271 NamedDecl *UnqualLookup,
3272 CXXScopeSpec &SS) {
3273 // FIXME: Painfully copy-paste from the above!
3274
Douglas Gregor14454802011-02-25 02:25:35 +00003275 QualType T = TL.getType();
3276 if (getDerived().AlreadyTransformed(T))
3277 return TL;
3278
3279 TypeLocBuilder TLB;
3280 QualType Result;
3281
3282 if (isa<TemplateSpecializationType>(T)) {
3283 TemplateSpecializationTypeLoc SpecTL
3284 = cast<TemplateSpecializationTypeLoc>(TL);
3285
3286 TemplateName Template =
3287 getDerived().TransformTemplateName(SpecTL.getTypePtr()->getTemplateName(),
3288 ObjectType, UnqualLookup);
3289 if (Template.isNull())
3290 return TypeLoc();
3291
3292 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3293 Template);
3294 } else if (isa<DependentTemplateSpecializationType>(T)) {
3295 DependentTemplateSpecializationTypeLoc SpecTL
3296 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3297
Douglas Gregor5a064722011-02-28 17:23:35 +00003298 TemplateName Template
Douglas Gregore16af532011-02-28 18:50:33 +00003299 = getDerived().RebuildTemplateName(SS.getScopeRep(), SS.getRange(),
3300 *SpecTL.getTypePtr()->getIdentifier(),
3301 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003302 if (Template.isNull())
3303 return TypeLoc();
3304
Douglas Gregor14454802011-02-25 02:25:35 +00003305 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003306 SpecTL,
3307 Template);
Douglas Gregor14454802011-02-25 02:25:35 +00003308 } else {
3309 // Nothing special needs to be done for these.
3310 Result = getDerived().TransformType(TLB, TL);
3311 }
3312
3313 if (Result.isNull())
3314 return TypeLoc();
3315
3316 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3317}
3318
John McCall550e0c22009-10-21 00:40:46 +00003319template <class TyLoc> static inline
3320QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3321 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3322 NewT.setNameLoc(T.getNameLoc());
3323 return T.getType();
3324}
3325
John McCall550e0c22009-10-21 00:40:46 +00003326template<typename Derived>
3327QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003328 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003329 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3330 NewT.setBuiltinLoc(T.getBuiltinLoc());
3331 if (T.needsExtraLocalData())
3332 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3333 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003334}
Mike Stump11289f42009-09-09 15:08:12 +00003335
Douglas Gregord6ff3322009-08-04 16:50:30 +00003336template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003337QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003338 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003339 // FIXME: recurse?
3340 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003341}
Mike Stump11289f42009-09-09 15:08:12 +00003342
Douglas Gregord6ff3322009-08-04 16:50:30 +00003343template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003344QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003345 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003346 QualType PointeeType
3347 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003348 if (PointeeType.isNull())
3349 return QualType();
3350
3351 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003352 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003353 // A dependent pointer type 'T *' has is being transformed such
3354 // that an Objective-C class type is being replaced for 'T'. The
3355 // resulting pointer type is an ObjCObjectPointerType, not a
3356 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003357 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003358
John McCall8b07ec22010-05-15 11:32:37 +00003359 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3360 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003361 return Result;
3362 }
John McCall31f82722010-11-12 08:19:04 +00003363
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003364 if (getDerived().AlwaysRebuild() ||
3365 PointeeType != TL.getPointeeLoc().getType()) {
3366 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3367 if (Result.isNull())
3368 return QualType();
3369 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003370
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003371 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3372 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003373 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003374}
Mike Stump11289f42009-09-09 15:08:12 +00003375
3376template<typename Derived>
3377QualType
John McCall550e0c22009-10-21 00:40:46 +00003378TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003379 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003380 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003381 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3382 if (PointeeType.isNull())
3383 return QualType();
3384
3385 QualType Result = TL.getType();
3386 if (getDerived().AlwaysRebuild() ||
3387 PointeeType != TL.getPointeeLoc().getType()) {
3388 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003389 TL.getSigilLoc());
3390 if (Result.isNull())
3391 return QualType();
3392 }
3393
Douglas Gregor049211a2010-04-22 16:50:51 +00003394 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003395 NewT.setSigilLoc(TL.getSigilLoc());
3396 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003397}
3398
John McCall70dd5f62009-10-30 00:06:24 +00003399/// Transforms a reference type. Note that somewhat paradoxically we
3400/// don't care whether the type itself is an l-value type or an r-value
3401/// type; we only care if the type was *written* as an l-value type
3402/// or an r-value type.
3403template<typename Derived>
3404QualType
3405TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003406 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003407 const ReferenceType *T = TL.getTypePtr();
3408
3409 // Note that this works with the pointee-as-written.
3410 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3411 if (PointeeType.isNull())
3412 return QualType();
3413
3414 QualType Result = TL.getType();
3415 if (getDerived().AlwaysRebuild() ||
3416 PointeeType != T->getPointeeTypeAsWritten()) {
3417 Result = getDerived().RebuildReferenceType(PointeeType,
3418 T->isSpelledAsLValue(),
3419 TL.getSigilLoc());
3420 if (Result.isNull())
3421 return QualType();
3422 }
3423
3424 // r-value references can be rebuilt as l-value references.
3425 ReferenceTypeLoc NewTL;
3426 if (isa<LValueReferenceType>(Result))
3427 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3428 else
3429 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3430 NewTL.setSigilLoc(TL.getSigilLoc());
3431
3432 return Result;
3433}
3434
Mike Stump11289f42009-09-09 15:08:12 +00003435template<typename Derived>
3436QualType
John McCall550e0c22009-10-21 00:40:46 +00003437TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003438 LValueReferenceTypeLoc TL) {
3439 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003440}
3441
Mike Stump11289f42009-09-09 15:08:12 +00003442template<typename Derived>
3443QualType
John McCall550e0c22009-10-21 00:40:46 +00003444TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003445 RValueReferenceTypeLoc TL) {
3446 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003447}
Mike Stump11289f42009-09-09 15:08:12 +00003448
Douglas Gregord6ff3322009-08-04 16:50:30 +00003449template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003450QualType
John McCall550e0c22009-10-21 00:40:46 +00003451TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003452 MemberPointerTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003453 const MemberPointerType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003454
3455 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003456 if (PointeeType.isNull())
3457 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003458
John McCall550e0c22009-10-21 00:40:46 +00003459 // TODO: preserve source information for this.
3460 QualType ClassType
3461 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003462 if (ClassType.isNull())
3463 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003464
John McCall550e0c22009-10-21 00:40:46 +00003465 QualType Result = TL.getType();
3466 if (getDerived().AlwaysRebuild() ||
3467 PointeeType != T->getPointeeType() ||
3468 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00003469 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3470 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003471 if (Result.isNull())
3472 return QualType();
3473 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003474
John McCall550e0c22009-10-21 00:40:46 +00003475 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3476 NewTL.setSigilLoc(TL.getSigilLoc());
3477
3478 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003479}
3480
Mike Stump11289f42009-09-09 15:08:12 +00003481template<typename Derived>
3482QualType
John McCall550e0c22009-10-21 00:40:46 +00003483TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003484 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003485 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003486 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003487 if (ElementType.isNull())
3488 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003489
John McCall550e0c22009-10-21 00:40:46 +00003490 QualType Result = TL.getType();
3491 if (getDerived().AlwaysRebuild() ||
3492 ElementType != T->getElementType()) {
3493 Result = getDerived().RebuildConstantArrayType(ElementType,
3494 T->getSizeModifier(),
3495 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003496 T->getIndexTypeCVRQualifiers(),
3497 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003498 if (Result.isNull())
3499 return QualType();
3500 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003501
John McCall550e0c22009-10-21 00:40:46 +00003502 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3503 NewTL.setLBracketLoc(TL.getLBracketLoc());
3504 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003505
John McCall550e0c22009-10-21 00:40:46 +00003506 Expr *Size = TL.getSizeExpr();
3507 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003508 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003509 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3510 }
3511 NewTL.setSizeExpr(Size);
3512
3513 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003514}
Mike Stump11289f42009-09-09 15:08:12 +00003515
Douglas Gregord6ff3322009-08-04 16:50:30 +00003516template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003517QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003518 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003519 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003520 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003521 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003522 if (ElementType.isNull())
3523 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003524
John McCall550e0c22009-10-21 00:40:46 +00003525 QualType Result = TL.getType();
3526 if (getDerived().AlwaysRebuild() ||
3527 ElementType != T->getElementType()) {
3528 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003529 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003530 T->getIndexTypeCVRQualifiers(),
3531 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003532 if (Result.isNull())
3533 return QualType();
3534 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003535
John McCall550e0c22009-10-21 00:40:46 +00003536 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3537 NewTL.setLBracketLoc(TL.getLBracketLoc());
3538 NewTL.setRBracketLoc(TL.getRBracketLoc());
3539 NewTL.setSizeExpr(0);
3540
3541 return Result;
3542}
3543
3544template<typename Derived>
3545QualType
3546TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003547 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003548 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003549 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3550 if (ElementType.isNull())
3551 return QualType();
3552
3553 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003554 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003555
John McCalldadc5752010-08-24 06:29:42 +00003556 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003557 = getDerived().TransformExpr(T->getSizeExpr());
3558 if (SizeResult.isInvalid())
3559 return QualType();
3560
John McCallb268a282010-08-23 23:25:46 +00003561 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003562
3563 QualType Result = TL.getType();
3564 if (getDerived().AlwaysRebuild() ||
3565 ElementType != T->getElementType() ||
3566 Size != T->getSizeExpr()) {
3567 Result = getDerived().RebuildVariableArrayType(ElementType,
3568 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003569 Size,
John McCall550e0c22009-10-21 00:40:46 +00003570 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003571 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003572 if (Result.isNull())
3573 return QualType();
3574 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003575
John McCall550e0c22009-10-21 00:40:46 +00003576 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3577 NewTL.setLBracketLoc(TL.getLBracketLoc());
3578 NewTL.setRBracketLoc(TL.getRBracketLoc());
3579 NewTL.setSizeExpr(Size);
3580
3581 return Result;
3582}
3583
3584template<typename Derived>
3585QualType
3586TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003587 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003588 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003589 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3590 if (ElementType.isNull())
3591 return QualType();
3592
3593 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003594 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003595
John McCall33ddac02011-01-19 10:06:00 +00003596 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3597 Expr *origSize = TL.getSizeExpr();
3598 if (!origSize) origSize = T->getSizeExpr();
3599
3600 ExprResult sizeResult
3601 = getDerived().TransformExpr(origSize);
3602 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003603 return QualType();
3604
John McCall33ddac02011-01-19 10:06:00 +00003605 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003606
3607 QualType Result = TL.getType();
3608 if (getDerived().AlwaysRebuild() ||
3609 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003610 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003611 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3612 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003613 size,
John McCall550e0c22009-10-21 00:40:46 +00003614 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003615 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003616 if (Result.isNull())
3617 return QualType();
3618 }
John McCall550e0c22009-10-21 00:40:46 +00003619
3620 // We might have any sort of array type now, but fortunately they
3621 // all have the same location layout.
3622 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3623 NewTL.setLBracketLoc(TL.getLBracketLoc());
3624 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003625 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003626
3627 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003628}
Mike Stump11289f42009-09-09 15:08:12 +00003629
3630template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003631QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003632 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003633 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003634 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003635
3636 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003637 QualType ElementType = getDerived().TransformType(T->getElementType());
3638 if (ElementType.isNull())
3639 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003640
Douglas Gregore922c772009-08-04 22:27:00 +00003641 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003642 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003643
John McCalldadc5752010-08-24 06:29:42 +00003644 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003645 if (Size.isInvalid())
3646 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003647
John McCall550e0c22009-10-21 00:40:46 +00003648 QualType Result = TL.getType();
3649 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003650 ElementType != T->getElementType() ||
3651 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003652 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003653 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003654 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003655 if (Result.isNull())
3656 return QualType();
3657 }
John McCall550e0c22009-10-21 00:40:46 +00003658
3659 // Result might be dependent or not.
3660 if (isa<DependentSizedExtVectorType>(Result)) {
3661 DependentSizedExtVectorTypeLoc NewTL
3662 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3663 NewTL.setNameLoc(TL.getNameLoc());
3664 } else {
3665 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3666 NewTL.setNameLoc(TL.getNameLoc());
3667 }
3668
3669 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003670}
Mike Stump11289f42009-09-09 15:08:12 +00003671
3672template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003673QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003674 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003675 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003676 QualType ElementType = getDerived().TransformType(T->getElementType());
3677 if (ElementType.isNull())
3678 return QualType();
3679
John McCall550e0c22009-10-21 00:40:46 +00003680 QualType Result = TL.getType();
3681 if (getDerived().AlwaysRebuild() ||
3682 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003683 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003684 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003685 if (Result.isNull())
3686 return QualType();
3687 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003688
John McCall550e0c22009-10-21 00:40:46 +00003689 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3690 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003691
John McCall550e0c22009-10-21 00:40:46 +00003692 return Result;
3693}
3694
3695template<typename Derived>
3696QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003697 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003698 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003699 QualType ElementType = getDerived().TransformType(T->getElementType());
3700 if (ElementType.isNull())
3701 return QualType();
3702
3703 QualType Result = TL.getType();
3704 if (getDerived().AlwaysRebuild() ||
3705 ElementType != T->getElementType()) {
3706 Result = getDerived().RebuildExtVectorType(ElementType,
3707 T->getNumElements(),
3708 /*FIXME*/ SourceLocation());
3709 if (Result.isNull())
3710 return QualType();
3711 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003712
John McCall550e0c22009-10-21 00:40:46 +00003713 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3714 NewTL.setNameLoc(TL.getNameLoc());
3715
3716 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003717}
Mike Stump11289f42009-09-09 15:08:12 +00003718
3719template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003720ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003721TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3722 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003723 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003724 TypeSourceInfo *NewDI = 0;
3725
3726 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3727 // If we're substituting into a pack expansion type and we know the
3728 TypeLoc OldTL = OldDI->getTypeLoc();
3729 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3730
3731 TypeLocBuilder TLB;
3732 TypeLoc NewTL = OldDI->getTypeLoc();
3733 TLB.reserve(NewTL.getFullDataSize());
3734
3735 QualType Result = getDerived().TransformType(TLB,
3736 OldExpansionTL.getPatternLoc());
3737 if (Result.isNull())
3738 return 0;
3739
3740 Result = RebuildPackExpansionType(Result,
3741 OldExpansionTL.getPatternLoc().getSourceRange(),
3742 OldExpansionTL.getEllipsisLoc(),
3743 NumExpansions);
3744 if (Result.isNull())
3745 return 0;
3746
3747 PackExpansionTypeLoc NewExpansionTL
3748 = TLB.push<PackExpansionTypeLoc>(Result);
3749 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3750 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3751 } else
3752 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003753 if (!NewDI)
3754 return 0;
3755
3756 if (NewDI == OldDI)
3757 return OldParm;
3758 else
3759 return ParmVarDecl::Create(SemaRef.Context,
3760 OldParm->getDeclContext(),
3761 OldParm->getLocation(),
3762 OldParm->getIdentifier(),
3763 NewDI->getType(),
3764 NewDI,
3765 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003766 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003767 /* DefArg */ NULL);
3768}
3769
3770template<typename Derived>
3771bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003772 TransformFunctionTypeParams(SourceLocation Loc,
3773 ParmVarDecl **Params, unsigned NumParams,
3774 const QualType *ParamTypes,
3775 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3776 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3777 for (unsigned i = 0; i != NumParams; ++i) {
3778 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor715e4612011-01-14 22:40:04 +00003779 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003780 if (OldParm->isParameterPack()) {
3781 // We have a function parameter pack that may need to be expanded.
3782 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003783
Douglas Gregor5499af42011-01-05 23:12:31 +00003784 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003785 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3786 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3787 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3788 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor5499af42011-01-05 23:12:31 +00003789
3790 // Determine whether we should expand the parameter packs.
3791 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003792 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003793 llvm::Optional<unsigned> OrigNumExpansions
3794 = ExpansionTL.getTypePtr()->getNumExpansions();
3795 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003796 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3797 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003798 Unexpanded.data(),
3799 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003800 ShouldExpand,
3801 RetainExpansion,
3802 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003803 return true;
3804 }
3805
3806 if (ShouldExpand) {
3807 // Expand the function parameter pack into multiple, separate
3808 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003809 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003810 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003811 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3812 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003813 = getDerived().TransformFunctionTypeParam(OldParm,
3814 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003815 if (!NewParm)
3816 return true;
3817
Douglas Gregordd472162011-01-07 00:20:55 +00003818 OutParamTypes.push_back(NewParm->getType());
3819 if (PVars)
3820 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003821 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003822
3823 // If we're supposed to retain a pack expansion, do so by temporarily
3824 // forgetting the partially-substituted parameter pack.
3825 if (RetainExpansion) {
3826 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3827 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003828 = getDerived().TransformFunctionTypeParam(OldParm,
3829 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003830 if (!NewParm)
3831 return true;
3832
3833 OutParamTypes.push_back(NewParm->getType());
3834 if (PVars)
3835 PVars->push_back(NewParm);
3836 }
3837
Douglas Gregor5499af42011-01-05 23:12:31 +00003838 // We're done with the pack expansion.
3839 continue;
3840 }
3841
3842 // We'll substitute the parameter now without expanding the pack
3843 // expansion.
3844 }
3845
3846 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Douglas Gregor715e4612011-01-14 22:40:04 +00003847 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3848 NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +00003849 if (!NewParm)
3850 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003851
Douglas Gregordd472162011-01-07 00:20:55 +00003852 OutParamTypes.push_back(NewParm->getType());
3853 if (PVars)
3854 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003855 continue;
3856 }
John McCall58f10c32010-03-11 09:03:00 +00003857
3858 // Deal with the possibility that we don't have a parameter
3859 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003860 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003861 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003862 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003863 if (const PackExpansionType *Expansion
3864 = dyn_cast<PackExpansionType>(OldType)) {
3865 // We have a function parameter pack that may need to be expanded.
3866 QualType Pattern = Expansion->getPattern();
3867 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3868 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3869
3870 // Determine whether we should expand the parameter packs.
3871 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003872 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003873 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003874 Unexpanded.data(),
3875 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003876 ShouldExpand,
3877 RetainExpansion,
3878 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003879 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003880 }
3881
3882 if (ShouldExpand) {
3883 // Expand the function parameter pack into multiple, separate
3884 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003885 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003886 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3887 QualType NewType = getDerived().TransformType(Pattern);
3888 if (NewType.isNull())
3889 return true;
John McCall58f10c32010-03-11 09:03:00 +00003890
Douglas Gregordd472162011-01-07 00:20:55 +00003891 OutParamTypes.push_back(NewType);
3892 if (PVars)
3893 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003894 }
3895
3896 // We're done with the pack expansion.
3897 continue;
3898 }
3899
Douglas Gregor48d24112011-01-10 20:53:55 +00003900 // If we're supposed to retain a pack expansion, do so by temporarily
3901 // forgetting the partially-substituted parameter pack.
3902 if (RetainExpansion) {
3903 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3904 QualType NewType = getDerived().TransformType(Pattern);
3905 if (NewType.isNull())
3906 return true;
3907
3908 OutParamTypes.push_back(NewType);
3909 if (PVars)
3910 PVars->push_back(0);
3911 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003912
Douglas Gregor5499af42011-01-05 23:12:31 +00003913 // We'll substitute the parameter now without expanding the pack
3914 // expansion.
3915 OldType = Expansion->getPattern();
3916 IsPackExpansion = true;
3917 }
3918
3919 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3920 QualType NewType = getDerived().TransformType(OldType);
3921 if (NewType.isNull())
3922 return true;
3923
3924 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003925 NewType = getSema().Context.getPackExpansionType(NewType,
3926 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003927
Douglas Gregordd472162011-01-07 00:20:55 +00003928 OutParamTypes.push_back(NewType);
3929 if (PVars)
3930 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003931 }
3932
3933 return false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003934 }
John McCall58f10c32010-03-11 09:03:00 +00003935
3936template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003937QualType
John McCall550e0c22009-10-21 00:40:46 +00003938TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003939 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003940 // Transform the parameters and return type.
3941 //
3942 // We instantiate in source order, with the return type first followed by
3943 // the parameters, because users tend to expect this (even if they shouldn't
3944 // rely on it!).
3945 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003946 // When the function has a trailing return type, we instantiate the
3947 // parameters before the return type, since the return type can then refer
3948 // to the parameters themselves (via decltype, sizeof, etc.).
3949 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003950 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003951 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00003952 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003953
Douglas Gregor7fb25412010-10-01 18:44:50 +00003954 QualType ResultType;
3955
3956 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003957 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3958 TL.getParmArray(),
3959 TL.getNumArgs(),
3960 TL.getTypePtr()->arg_type_begin(),
3961 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003962 return QualType();
3963
3964 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3965 if (ResultType.isNull())
3966 return QualType();
3967 }
3968 else {
3969 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3970 if (ResultType.isNull())
3971 return QualType();
3972
Douglas Gregordd472162011-01-07 00:20:55 +00003973 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3974 TL.getParmArray(),
3975 TL.getNumArgs(),
3976 TL.getTypePtr()->arg_type_begin(),
3977 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003978 return QualType();
3979 }
3980
John McCall550e0c22009-10-21 00:40:46 +00003981 QualType Result = TL.getType();
3982 if (getDerived().AlwaysRebuild() ||
3983 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003984 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003985 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3986 Result = getDerived().RebuildFunctionProtoType(ResultType,
3987 ParamTypes.data(),
3988 ParamTypes.size(),
3989 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003990 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00003991 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003992 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003993 if (Result.isNull())
3994 return QualType();
3995 }
Mike Stump11289f42009-09-09 15:08:12 +00003996
John McCall550e0c22009-10-21 00:40:46 +00003997 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3998 NewTL.setLParenLoc(TL.getLParenLoc());
3999 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004000 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00004001 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4002 NewTL.setArg(i, ParamDecls[i]);
4003
4004 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004005}
Mike Stump11289f42009-09-09 15:08:12 +00004006
Douglas Gregord6ff3322009-08-04 16:50:30 +00004007template<typename Derived>
4008QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004009 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004010 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004011 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004012 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4013 if (ResultType.isNull())
4014 return QualType();
4015
4016 QualType Result = TL.getType();
4017 if (getDerived().AlwaysRebuild() ||
4018 ResultType != T->getResultType())
4019 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4020
4021 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
4022 NewTL.setLParenLoc(TL.getLParenLoc());
4023 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004024 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00004025
4026 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004027}
Mike Stump11289f42009-09-09 15:08:12 +00004028
John McCallb96ec562009-12-04 22:46:56 +00004029template<typename Derived> QualType
4030TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004031 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004032 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004033 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004034 if (!D)
4035 return QualType();
4036
4037 QualType Result = TL.getType();
4038 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4039 Result = getDerived().RebuildUnresolvedUsingType(D);
4040 if (Result.isNull())
4041 return QualType();
4042 }
4043
4044 // We might get an arbitrary type spec type back. We should at
4045 // least always get a type spec type, though.
4046 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4047 NewTL.setNameLoc(TL.getNameLoc());
4048
4049 return Result;
4050}
4051
Douglas Gregord6ff3322009-08-04 16:50:30 +00004052template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004053QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004054 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004055 const TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004056 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004057 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4058 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004059 if (!Typedef)
4060 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004061
John McCall550e0c22009-10-21 00:40:46 +00004062 QualType Result = TL.getType();
4063 if (getDerived().AlwaysRebuild() ||
4064 Typedef != T->getDecl()) {
4065 Result = getDerived().RebuildTypedefType(Typedef);
4066 if (Result.isNull())
4067 return QualType();
4068 }
Mike Stump11289f42009-09-09 15:08:12 +00004069
John McCall550e0c22009-10-21 00:40:46 +00004070 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4071 NewTL.setNameLoc(TL.getNameLoc());
4072
4073 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004074}
Mike Stump11289f42009-09-09 15:08:12 +00004075
Douglas Gregord6ff3322009-08-04 16:50:30 +00004076template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004077QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004078 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004079 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004080 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004081
John McCalldadc5752010-08-24 06:29:42 +00004082 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004083 if (E.isInvalid())
4084 return QualType();
4085
John McCall550e0c22009-10-21 00:40:46 +00004086 QualType Result = TL.getType();
4087 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004088 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004089 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004090 if (Result.isNull())
4091 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004092 }
John McCall550e0c22009-10-21 00:40:46 +00004093 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004094
John McCall550e0c22009-10-21 00:40:46 +00004095 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004096 NewTL.setTypeofLoc(TL.getTypeofLoc());
4097 NewTL.setLParenLoc(TL.getLParenLoc());
4098 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004099
4100 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004101}
Mike Stump11289f42009-09-09 15:08:12 +00004102
4103template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004104QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004105 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004106 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4107 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4108 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004109 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004110
John McCall550e0c22009-10-21 00:40:46 +00004111 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004112 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4113 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004114 if (Result.isNull())
4115 return QualType();
4116 }
Mike Stump11289f42009-09-09 15:08:12 +00004117
John McCall550e0c22009-10-21 00:40:46 +00004118 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004119 NewTL.setTypeofLoc(TL.getTypeofLoc());
4120 NewTL.setLParenLoc(TL.getLParenLoc());
4121 NewTL.setRParenLoc(TL.getRParenLoc());
4122 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004123
4124 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004125}
Mike Stump11289f42009-09-09 15:08:12 +00004126
4127template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004128QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004129 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004130 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004131
Douglas Gregore922c772009-08-04 22:27:00 +00004132 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004133 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004134
John McCalldadc5752010-08-24 06:29:42 +00004135 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004136 if (E.isInvalid())
4137 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004138
John McCall550e0c22009-10-21 00:40:46 +00004139 QualType Result = TL.getType();
4140 if (getDerived().AlwaysRebuild() ||
4141 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004142 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004143 if (Result.isNull())
4144 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004145 }
John McCall550e0c22009-10-21 00:40:46 +00004146 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004147
John McCall550e0c22009-10-21 00:40:46 +00004148 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4149 NewTL.setNameLoc(TL.getNameLoc());
4150
4151 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004152}
4153
4154template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004155QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4156 AutoTypeLoc TL) {
4157 const AutoType *T = TL.getTypePtr();
4158 QualType OldDeduced = T->getDeducedType();
4159 QualType NewDeduced;
4160 if (!OldDeduced.isNull()) {
4161 NewDeduced = getDerived().TransformType(OldDeduced);
4162 if (NewDeduced.isNull())
4163 return QualType();
4164 }
4165
4166 QualType Result = TL.getType();
4167 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4168 Result = getDerived().RebuildAutoType(NewDeduced);
4169 if (Result.isNull())
4170 return QualType();
4171 }
4172
4173 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4174 NewTL.setNameLoc(TL.getNameLoc());
4175
4176 return Result;
4177}
4178
4179template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004180QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004181 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004182 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004183 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004184 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4185 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004186 if (!Record)
4187 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004188
John McCall550e0c22009-10-21 00:40:46 +00004189 QualType Result = TL.getType();
4190 if (getDerived().AlwaysRebuild() ||
4191 Record != T->getDecl()) {
4192 Result = getDerived().RebuildRecordType(Record);
4193 if (Result.isNull())
4194 return QualType();
4195 }
Mike Stump11289f42009-09-09 15:08:12 +00004196
John McCall550e0c22009-10-21 00:40:46 +00004197 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4198 NewTL.setNameLoc(TL.getNameLoc());
4199
4200 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004201}
Mike Stump11289f42009-09-09 15:08:12 +00004202
4203template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004204QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004205 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004206 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004207 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004208 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4209 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004210 if (!Enum)
4211 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004212
John McCall550e0c22009-10-21 00:40:46 +00004213 QualType Result = TL.getType();
4214 if (getDerived().AlwaysRebuild() ||
4215 Enum != T->getDecl()) {
4216 Result = getDerived().RebuildEnumType(Enum);
4217 if (Result.isNull())
4218 return QualType();
4219 }
Mike Stump11289f42009-09-09 15:08:12 +00004220
John McCall550e0c22009-10-21 00:40:46 +00004221 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4222 NewTL.setNameLoc(TL.getNameLoc());
4223
4224 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004225}
John McCallfcc33b02009-09-05 00:15:47 +00004226
John McCalle78aac42010-03-10 03:28:59 +00004227template<typename Derived>
4228QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4229 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004230 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004231 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4232 TL.getTypePtr()->getDecl());
4233 if (!D) return QualType();
4234
4235 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4236 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4237 return T;
4238}
4239
Douglas Gregord6ff3322009-08-04 16:50:30 +00004240template<typename Derived>
4241QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004242 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004243 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004244 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004245}
4246
Mike Stump11289f42009-09-09 15:08:12 +00004247template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004248QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004249 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004250 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004251 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00004252}
4253
4254template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004255QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4256 TypeLocBuilder &TLB,
4257 SubstTemplateTypeParmPackTypeLoc TL) {
4258 return TransformTypeSpecType(TLB, TL);
4259}
4260
4261template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004262QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004263 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004264 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004265 const TemplateSpecializationType *T = TL.getTypePtr();
4266
Mike Stump11289f42009-09-09 15:08:12 +00004267 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00004268 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004269 if (Template.isNull())
4270 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004271
John McCall31f82722010-11-12 08:19:04 +00004272 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4273}
4274
Douglas Gregorfe921a72010-12-20 23:36:19 +00004275namespace {
4276 /// \brief Simple iterator that traverses the template arguments in a
4277 /// container that provides a \c getArgLoc() member function.
4278 ///
4279 /// This iterator is intended to be used with the iterator form of
4280 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4281 template<typename ArgLocContainer>
4282 class TemplateArgumentLocContainerIterator {
4283 ArgLocContainer *Container;
4284 unsigned Index;
4285
4286 public:
4287 typedef TemplateArgumentLoc value_type;
4288 typedef TemplateArgumentLoc reference;
4289 typedef int difference_type;
4290 typedef std::input_iterator_tag iterator_category;
4291
4292 class pointer {
4293 TemplateArgumentLoc Arg;
4294
4295 public:
4296 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4297
4298 const TemplateArgumentLoc *operator->() const {
4299 return &Arg;
4300 }
4301 };
4302
4303
4304 TemplateArgumentLocContainerIterator() {}
4305
4306 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4307 unsigned Index)
4308 : Container(&Container), Index(Index) { }
4309
4310 TemplateArgumentLocContainerIterator &operator++() {
4311 ++Index;
4312 return *this;
4313 }
4314
4315 TemplateArgumentLocContainerIterator operator++(int) {
4316 TemplateArgumentLocContainerIterator Old(*this);
4317 ++(*this);
4318 return Old;
4319 }
4320
4321 TemplateArgumentLoc operator*() const {
4322 return Container->getArgLoc(Index);
4323 }
4324
4325 pointer operator->() const {
4326 return pointer(Container->getArgLoc(Index));
4327 }
4328
4329 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004330 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004331 return X.Container == Y.Container && X.Index == Y.Index;
4332 }
4333
4334 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004335 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004336 return !(X == Y);
4337 }
4338 };
4339}
4340
4341
John McCall31f82722010-11-12 08:19:04 +00004342template <typename Derived>
4343QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4344 TypeLocBuilder &TLB,
4345 TemplateSpecializationTypeLoc TL,
4346 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004347 TemplateArgumentListInfo NewTemplateArgs;
4348 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4349 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004350 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4351 ArgIterator;
4352 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4353 ArgIterator(TL, TL.getNumArgs()),
4354 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004355 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004356
John McCall0ad16662009-10-29 08:12:44 +00004357 // FIXME: maybe don't rebuild if all the template arguments are the same.
4358
4359 QualType Result =
4360 getDerived().RebuildTemplateSpecializationType(Template,
4361 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004362 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004363
4364 if (!Result.isNull()) {
4365 TemplateSpecializationTypeLoc NewTL
4366 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4367 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4368 NewTL.setLAngleLoc(TL.getLAngleLoc());
4369 NewTL.setRAngleLoc(TL.getRAngleLoc());
4370 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4371 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004372 }
Mike Stump11289f42009-09-09 15:08:12 +00004373
John McCall0ad16662009-10-29 08:12:44 +00004374 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004375}
Mike Stump11289f42009-09-09 15:08:12 +00004376
Douglas Gregor5a064722011-02-28 17:23:35 +00004377template <typename Derived>
4378QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4379 TypeLocBuilder &TLB,
4380 DependentTemplateSpecializationTypeLoc TL,
4381 TemplateName Template) {
4382 TemplateArgumentListInfo NewTemplateArgs;
4383 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4384 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4385 typedef TemplateArgumentLocContainerIterator<
4386 DependentTemplateSpecializationTypeLoc> ArgIterator;
4387 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4388 ArgIterator(TL, TL.getNumArgs()),
4389 NewTemplateArgs))
4390 return QualType();
4391
4392 // FIXME: maybe don't rebuild if all the template arguments are the same.
4393
4394 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4395 QualType Result
4396 = getSema().Context.getDependentTemplateSpecializationType(
4397 TL.getTypePtr()->getKeyword(),
4398 DTN->getQualifier(),
4399 DTN->getIdentifier(),
4400 NewTemplateArgs);
4401
4402 DependentTemplateSpecializationTypeLoc NewTL
4403 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4404 NewTL.setKeywordLoc(TL.getKeywordLoc());
4405 NewTL.setQualifierRange(TL.getQualifierRange());
4406 NewTL.setNameLoc(TL.getNameLoc());
4407 NewTL.setLAngleLoc(TL.getLAngleLoc());
4408 NewTL.setRAngleLoc(TL.getRAngleLoc());
4409 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4410 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4411 return Result;
4412 }
4413
4414 QualType Result
4415 = getDerived().RebuildTemplateSpecializationType(Template,
4416 TL.getNameLoc(),
4417 NewTemplateArgs);
4418
4419 if (!Result.isNull()) {
4420 /// FIXME: Wrap this in an elaborated-type-specifier?
4421 TemplateSpecializationTypeLoc NewTL
4422 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4423 NewTL.setTemplateNameLoc(TL.getNameLoc());
4424 NewTL.setLAngleLoc(TL.getLAngleLoc());
4425 NewTL.setRAngleLoc(TL.getRAngleLoc());
4426 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4427 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4428 }
4429
4430 return Result;
4431}
4432
Mike Stump11289f42009-09-09 15:08:12 +00004433template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004434QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004435TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004436 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004437 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004438
4439 NestedNameSpecifier *NNS = 0;
4440 // NOTE: the qualifier in an ElaboratedType is optional.
4441 if (T->getQualifier() != 0) {
4442 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004443 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00004444 if (!NNS)
4445 return QualType();
4446 }
Mike Stump11289f42009-09-09 15:08:12 +00004447
John McCall31f82722010-11-12 08:19:04 +00004448 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4449 if (NamedT.isNull())
4450 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004451
John McCall550e0c22009-10-21 00:40:46 +00004452 QualType Result = TL.getType();
4453 if (getDerived().AlwaysRebuild() ||
4454 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004455 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004456 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
4457 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004458 if (Result.isNull())
4459 return QualType();
4460 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004461
Abramo Bagnara6150c882010-05-11 21:36:43 +00004462 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004463 NewTL.setKeywordLoc(TL.getKeywordLoc());
4464 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00004465
4466 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004467}
Mike Stump11289f42009-09-09 15:08:12 +00004468
4469template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004470QualType TreeTransform<Derived>::TransformAttributedType(
4471 TypeLocBuilder &TLB,
4472 AttributedTypeLoc TL) {
4473 const AttributedType *oldType = TL.getTypePtr();
4474 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4475 if (modifiedType.isNull())
4476 return QualType();
4477
4478 QualType result = TL.getType();
4479
4480 // FIXME: dependent operand expressions?
4481 if (getDerived().AlwaysRebuild() ||
4482 modifiedType != oldType->getModifiedType()) {
4483 // TODO: this is really lame; we should really be rebuilding the
4484 // equivalent type from first principles.
4485 QualType equivalentType
4486 = getDerived().TransformType(oldType->getEquivalentType());
4487 if (equivalentType.isNull())
4488 return QualType();
4489 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4490 modifiedType,
4491 equivalentType);
4492 }
4493
4494 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4495 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4496 if (TL.hasAttrOperand())
4497 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4498 if (TL.hasAttrExprOperand())
4499 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4500 else if (TL.hasAttrEnumOperand())
4501 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4502
4503 return result;
4504}
4505
4506template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004507QualType
4508TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4509 ParenTypeLoc TL) {
4510 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4511 if (Inner.isNull())
4512 return QualType();
4513
4514 QualType Result = TL.getType();
4515 if (getDerived().AlwaysRebuild() ||
4516 Inner != TL.getInnerLoc().getType()) {
4517 Result = getDerived().RebuildParenType(Inner);
4518 if (Result.isNull())
4519 return QualType();
4520 }
4521
4522 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4523 NewTL.setLParenLoc(TL.getLParenLoc());
4524 NewTL.setRParenLoc(TL.getRParenLoc());
4525 return Result;
4526}
4527
4528template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004529QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004530 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004531 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004532
Douglas Gregord6ff3322009-08-04 16:50:30 +00004533 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00004534 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004535 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004536 if (!NNS)
4537 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004538
John McCallc392f372010-06-11 00:33:02 +00004539 QualType Result
4540 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
4541 T->getIdentifier(),
4542 TL.getKeywordLoc(),
4543 TL.getQualifierRange(),
4544 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004545 if (Result.isNull())
4546 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004547
Abramo Bagnarad7548482010-05-19 21:37:53 +00004548 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4549 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004550 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4551
Abramo Bagnarad7548482010-05-19 21:37:53 +00004552 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4553 NewTL.setKeywordLoc(TL.getKeywordLoc());
4554 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004555 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004556 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4557 NewTL.setKeywordLoc(TL.getKeywordLoc());
4558 NewTL.setQualifierRange(TL.getQualifierRange());
4559 NewTL.setNameLoc(TL.getNameLoc());
4560 }
John McCall550e0c22009-10-21 00:40:46 +00004561 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004562}
Mike Stump11289f42009-09-09 15:08:12 +00004563
Douglas Gregord6ff3322009-08-04 16:50:30 +00004564template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004565QualType TreeTransform<Derived>::
4566 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004567 DependentTemplateSpecializationTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004568 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCallc392f372010-06-11 00:33:02 +00004569
Douglas Gregor5a064722011-02-28 17:23:35 +00004570 NestedNameSpecifier *NNS = 0;
4571 if (T->getQualifier()) {
4572 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
4573 TL.getQualifierRange());
4574 if (!NNS)
4575 return QualType();
4576 }
4577
John McCall31f82722010-11-12 08:19:04 +00004578 return getDerived()
4579 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
4580}
4581
4582template<typename Derived>
4583QualType TreeTransform<Derived>::
4584 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4585 DependentTemplateSpecializationTypeLoc TL,
4586 NestedNameSpecifier *NNS) {
John McCall424cec92011-01-19 06:33:43 +00004587 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCall31f82722010-11-12 08:19:04 +00004588
John McCallc392f372010-06-11 00:33:02 +00004589 TemplateArgumentListInfo NewTemplateArgs;
4590 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4591 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor14454802011-02-25 02:25:35 +00004592
4593 // FIXME: Nested-name-specifier source location info!
Douglas Gregorfe921a72010-12-20 23:36:19 +00004594 typedef TemplateArgumentLocContainerIterator<
4595 DependentTemplateSpecializationTypeLoc> ArgIterator;
4596 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4597 ArgIterator(TL, TL.getNumArgs()),
4598 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004599 return QualType();
John McCallc392f372010-06-11 00:33:02 +00004600
Douglas Gregora5614c52010-09-08 23:56:00 +00004601 QualType Result
4602 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4603 NNS,
4604 TL.getQualifierRange(),
4605 T->getIdentifier(),
4606 TL.getNameLoc(),
4607 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00004608 if (Result.isNull())
4609 return QualType();
4610
4611 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4612 QualType NamedT = ElabT->getNamedType();
4613
4614 // Copy information relevant to the template specialization.
4615 TemplateSpecializationTypeLoc NamedTL
4616 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4617 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4618 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4619 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4620 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4621
4622 // Copy information relevant to the elaborated type.
4623 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4624 NewTL.setKeywordLoc(TL.getKeywordLoc());
4625 NewTL.setQualifierRange(TL.getQualifierRange());
4626 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00004627 TypeLoc NewTL(Result, TL.getOpaqueData());
4628 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00004629 }
4630 return Result;
4631}
4632
4633template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004634QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4635 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004636 QualType Pattern
4637 = getDerived().TransformType(TLB, TL.getPatternLoc());
4638 if (Pattern.isNull())
4639 return QualType();
4640
4641 QualType Result = TL.getType();
4642 if (getDerived().AlwaysRebuild() ||
4643 Pattern != TL.getPatternLoc().getType()) {
4644 Result = getDerived().RebuildPackExpansionType(Pattern,
4645 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004646 TL.getEllipsisLoc(),
4647 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004648 if (Result.isNull())
4649 return QualType();
4650 }
4651
4652 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4653 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4654 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004655}
4656
4657template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004658QualType
4659TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004660 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004661 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004662 TLB.pushFullCopy(TL);
4663 return TL.getType();
4664}
4665
4666template<typename Derived>
4667QualType
4668TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004669 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004670 // ObjCObjectType is never dependent.
4671 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004672 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004673}
Mike Stump11289f42009-09-09 15:08:12 +00004674
4675template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004676QualType
4677TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004678 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004679 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004680 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004681 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004682}
4683
Douglas Gregord6ff3322009-08-04 16:50:30 +00004684//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004685// Statement transformation
4686//===----------------------------------------------------------------------===//
4687template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004688StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004689TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004690 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004691}
4692
4693template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004694StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004695TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4696 return getDerived().TransformCompoundStmt(S, false);
4697}
4698
4699template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004700StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004701TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004702 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004703 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004704 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004705 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004706 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4707 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004708 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004709 if (Result.isInvalid()) {
4710 // Immediately fail if this was a DeclStmt, since it's very
4711 // likely that this will cause problems for future statements.
4712 if (isa<DeclStmt>(*B))
4713 return StmtError();
4714
4715 // Otherwise, just keep processing substatements and fail later.
4716 SubStmtInvalid = true;
4717 continue;
4718 }
Mike Stump11289f42009-09-09 15:08:12 +00004719
Douglas Gregorebe10102009-08-20 07:17:43 +00004720 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4721 Statements.push_back(Result.takeAs<Stmt>());
4722 }
Mike Stump11289f42009-09-09 15:08:12 +00004723
John McCall1ababa62010-08-27 19:56:05 +00004724 if (SubStmtInvalid)
4725 return StmtError();
4726
Douglas Gregorebe10102009-08-20 07:17:43 +00004727 if (!getDerived().AlwaysRebuild() &&
4728 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004729 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004730
4731 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4732 move_arg(Statements),
4733 S->getRBracLoc(),
4734 IsStmtExpr);
4735}
Mike Stump11289f42009-09-09 15:08:12 +00004736
Douglas Gregorebe10102009-08-20 07:17:43 +00004737template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004738StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004739TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004740 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004741 {
4742 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004743 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004744
Eli Friedman06577382009-11-19 03:14:00 +00004745 // Transform the left-hand case value.
4746 LHS = getDerived().TransformExpr(S->getLHS());
4747 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004748 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004749
Eli Friedman06577382009-11-19 03:14:00 +00004750 // Transform the right-hand case value (for the GNU case-range extension).
4751 RHS = getDerived().TransformExpr(S->getRHS());
4752 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004753 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004754 }
Mike Stump11289f42009-09-09 15:08:12 +00004755
Douglas Gregorebe10102009-08-20 07:17:43 +00004756 // Build the case statement.
4757 // Case statements are always rebuilt so that they will attached to their
4758 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004759 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004760 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004761 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004762 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004763 S->getColonLoc());
4764 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004765 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004766
Douglas Gregorebe10102009-08-20 07:17:43 +00004767 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004768 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004769 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004770 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004771
Douglas Gregorebe10102009-08-20 07:17:43 +00004772 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004773 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004774}
4775
4776template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004777StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004778TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004779 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004780 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004781 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004782 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004783
Douglas Gregorebe10102009-08-20 07:17:43 +00004784 // Default statements are always rebuilt
4785 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004786 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004787}
Mike Stump11289f42009-09-09 15:08:12 +00004788
Douglas Gregorebe10102009-08-20 07:17:43 +00004789template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004790StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004791TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004792 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004793 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004794 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004795
Chris Lattnercab02a62011-02-17 20:34:02 +00004796 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4797 S->getDecl());
4798 if (!LD)
4799 return StmtError();
4800
4801
Douglas Gregorebe10102009-08-20 07:17:43 +00004802 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004803 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004804 cast<LabelDecl>(LD), SourceLocation(),
4805 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004806}
Mike Stump11289f42009-09-09 15:08:12 +00004807
Douglas Gregorebe10102009-08-20 07:17:43 +00004808template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004809StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004810TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004811 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004812 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004813 VarDecl *ConditionVar = 0;
4814 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004815 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004816 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004817 getDerived().TransformDefinition(
4818 S->getConditionVariable()->getLocation(),
4819 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004820 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004821 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004822 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004823 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004824
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004825 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004826 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004827
4828 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004829 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004830 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4831 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004832 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004833 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004834
John McCallb268a282010-08-23 23:25:46 +00004835 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004836 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004837 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004838
John McCallb268a282010-08-23 23:25:46 +00004839 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4840 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004841 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004842
Douglas Gregorebe10102009-08-20 07:17:43 +00004843 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004844 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004845 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004846 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004847
Douglas Gregorebe10102009-08-20 07:17:43 +00004848 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004849 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004850 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004851 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004852
Douglas Gregorebe10102009-08-20 07:17:43 +00004853 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004854 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004855 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004856 Then.get() == S->getThen() &&
4857 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004858 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004859
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004860 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004861 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004862 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004863}
4864
4865template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004866StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004867TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004868 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004869 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004870 VarDecl *ConditionVar = 0;
4871 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004872 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004873 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004874 getDerived().TransformDefinition(
4875 S->getConditionVariable()->getLocation(),
4876 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004877 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004878 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004879 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004880 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004881
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004882 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004883 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004884 }
Mike Stump11289f42009-09-09 15:08:12 +00004885
Douglas Gregorebe10102009-08-20 07:17:43 +00004886 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004887 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004888 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004889 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004890 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004891 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004892
Douglas Gregorebe10102009-08-20 07:17:43 +00004893 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004894 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004895 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004896 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004897
Douglas Gregorebe10102009-08-20 07:17:43 +00004898 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004899 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4900 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004901}
Mike Stump11289f42009-09-09 15:08:12 +00004902
Douglas Gregorebe10102009-08-20 07:17:43 +00004903template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004904StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004905TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004906 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004907 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004908 VarDecl *ConditionVar = 0;
4909 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004910 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004911 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004912 getDerived().TransformDefinition(
4913 S->getConditionVariable()->getLocation(),
4914 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004915 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004916 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004917 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004918 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004919
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004920 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004921 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004922
4923 if (S->getCond()) {
4924 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004925 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4926 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004927 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004928 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004929 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004930 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004931 }
Mike Stump11289f42009-09-09 15:08:12 +00004932
John McCallb268a282010-08-23 23:25:46 +00004933 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4934 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004935 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004936
Douglas Gregorebe10102009-08-20 07:17:43 +00004937 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004938 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004939 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004940 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004941
Douglas Gregorebe10102009-08-20 07:17:43 +00004942 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004943 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004944 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004945 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004946 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004947
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004948 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004949 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004950}
Mike Stump11289f42009-09-09 15:08:12 +00004951
Douglas Gregorebe10102009-08-20 07:17:43 +00004952template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004953StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004954TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004955 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004956 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004957 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004958 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004959
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004960 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004961 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004962 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004963 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004964
Douglas Gregorebe10102009-08-20 07:17:43 +00004965 if (!getDerived().AlwaysRebuild() &&
4966 Cond.get() == S->getCond() &&
4967 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004968 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004969
John McCallb268a282010-08-23 23:25:46 +00004970 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4971 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004972 S->getRParenLoc());
4973}
Mike Stump11289f42009-09-09 15:08:12 +00004974
Douglas Gregorebe10102009-08-20 07:17:43 +00004975template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004976StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004977TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004978 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004979 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004980 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004981 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004982
Douglas Gregorebe10102009-08-20 07:17:43 +00004983 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004984 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004985 VarDecl *ConditionVar = 0;
4986 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004987 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004988 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004989 getDerived().TransformDefinition(
4990 S->getConditionVariable()->getLocation(),
4991 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004992 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004993 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004994 } else {
4995 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004996
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004997 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004998 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004999
5000 if (S->getCond()) {
5001 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005002 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5003 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005004 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005005 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005006
John McCallb268a282010-08-23 23:25:46 +00005007 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005008 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005009 }
Mike Stump11289f42009-09-09 15:08:12 +00005010
John McCallb268a282010-08-23 23:25:46 +00005011 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5012 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005013 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005014
Douglas Gregorebe10102009-08-20 07:17:43 +00005015 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005016 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005017 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005018 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005019
John McCallb268a282010-08-23 23:25:46 +00005020 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5021 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005022 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005023
Douglas Gregorebe10102009-08-20 07:17:43 +00005024 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005025 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005026 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005027 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005028
Douglas Gregorebe10102009-08-20 07:17:43 +00005029 if (!getDerived().AlwaysRebuild() &&
5030 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005031 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005032 Inc.get() == S->getInc() &&
5033 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005034 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005035
Douglas Gregorebe10102009-08-20 07:17:43 +00005036 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005037 Init.get(), FullCond, ConditionVar,
5038 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005039}
5040
5041template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005042StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005043TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005044 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5045 S->getLabel());
5046 if (!LD)
5047 return StmtError();
5048
Douglas Gregorebe10102009-08-20 07:17:43 +00005049 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005050 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005051 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005052}
5053
5054template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005055StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005056TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005057 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005058 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005059 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005060
Douglas Gregorebe10102009-08-20 07:17:43 +00005061 if (!getDerived().AlwaysRebuild() &&
5062 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005063 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005064
5065 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005066 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005067}
5068
5069template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005070StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005071TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005072 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005073}
Mike Stump11289f42009-09-09 15:08:12 +00005074
Douglas Gregorebe10102009-08-20 07:17:43 +00005075template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005076StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005077TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005078 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005079}
Mike Stump11289f42009-09-09 15:08:12 +00005080
Douglas Gregorebe10102009-08-20 07:17:43 +00005081template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005082StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005083TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005084 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005085 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005086 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005087
Mike Stump11289f42009-09-09 15:08:12 +00005088 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005089 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005090 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005091}
Mike Stump11289f42009-09-09 15:08:12 +00005092
Douglas Gregorebe10102009-08-20 07:17:43 +00005093template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005094StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005095TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005096 bool DeclChanged = false;
5097 llvm::SmallVector<Decl *, 4> Decls;
5098 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5099 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005100 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5101 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005102 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005103 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005104
Douglas Gregorebe10102009-08-20 07:17:43 +00005105 if (Transformed != *D)
5106 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005107
Douglas Gregorebe10102009-08-20 07:17:43 +00005108 Decls.push_back(Transformed);
5109 }
Mike Stump11289f42009-09-09 15:08:12 +00005110
Douglas Gregorebe10102009-08-20 07:17:43 +00005111 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005112 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005113
5114 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005115 S->getStartLoc(), S->getEndLoc());
5116}
Mike Stump11289f42009-09-09 15:08:12 +00005117
Douglas Gregorebe10102009-08-20 07:17:43 +00005118template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005119StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005120TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005121
John McCall37ad5512010-08-23 06:44:23 +00005122 ASTOwningVector<Expr*> Constraints(getSema());
5123 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00005124 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005125
John McCalldadc5752010-08-24 06:29:42 +00005126 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005127 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005128
5129 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005130
Anders Carlssonaaeef072010-01-24 05:50:09 +00005131 // Go through the outputs.
5132 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005133 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005134
Anders Carlssonaaeef072010-01-24 05:50:09 +00005135 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005136 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005137
Anders Carlssonaaeef072010-01-24 05:50:09 +00005138 // Transform the output expr.
5139 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005140 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005141 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005142 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005143
Anders Carlssonaaeef072010-01-24 05:50:09 +00005144 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005145
John McCallb268a282010-08-23 23:25:46 +00005146 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005147 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005148
Anders Carlssonaaeef072010-01-24 05:50:09 +00005149 // Go through the inputs.
5150 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005151 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005152
Anders Carlssonaaeef072010-01-24 05:50:09 +00005153 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005154 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005155
Anders Carlssonaaeef072010-01-24 05:50:09 +00005156 // Transform the input expr.
5157 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005158 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005159 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005160 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005161
Anders Carlssonaaeef072010-01-24 05:50:09 +00005162 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005163
John McCallb268a282010-08-23 23:25:46 +00005164 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005165 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005166
Anders Carlssonaaeef072010-01-24 05:50:09 +00005167 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005168 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005169
5170 // Go through the clobbers.
5171 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005172 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005173
5174 // No need to transform the asm string literal.
5175 AsmString = SemaRef.Owned(S->getAsmString());
5176
5177 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5178 S->isSimple(),
5179 S->isVolatile(),
5180 S->getNumOutputs(),
5181 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005182 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005183 move_arg(Constraints),
5184 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005185 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005186 move_arg(Clobbers),
5187 S->getRParenLoc(),
5188 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005189}
5190
5191
5192template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005193StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005194TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005195 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005196 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005197 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005198 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005199
Douglas Gregor96c79492010-04-23 22:50:49 +00005200 // Transform the @catch statements (if present).
5201 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005202 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005203 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005204 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005205 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005206 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005207 if (Catch.get() != S->getCatchStmt(I))
5208 AnyCatchChanged = true;
5209 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005210 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005211
Douglas Gregor306de2f2010-04-22 23:59:56 +00005212 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005213 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005214 if (S->getFinallyStmt()) {
5215 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5216 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005217 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005218 }
5219
5220 // If nothing changed, just retain this statement.
5221 if (!getDerived().AlwaysRebuild() &&
5222 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005223 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005224 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005225 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005226
Douglas Gregor306de2f2010-04-22 23:59:56 +00005227 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005228 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5229 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005230}
Mike Stump11289f42009-09-09 15:08:12 +00005231
Douglas Gregorebe10102009-08-20 07:17:43 +00005232template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005233StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005234TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005235 // Transform the @catch parameter, if there is one.
5236 VarDecl *Var = 0;
5237 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5238 TypeSourceInfo *TSInfo = 0;
5239 if (FromVar->getTypeSourceInfo()) {
5240 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5241 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005242 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005243 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005244
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005245 QualType T;
5246 if (TSInfo)
5247 T = TSInfo->getType();
5248 else {
5249 T = getDerived().TransformType(FromVar->getType());
5250 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005251 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005252 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005253
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005254 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5255 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005256 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005257 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005258
John McCalldadc5752010-08-24 06:29:42 +00005259 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005260 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005261 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005262
5263 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005264 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005265 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005266}
Mike Stump11289f42009-09-09 15:08:12 +00005267
Douglas Gregorebe10102009-08-20 07:17:43 +00005268template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005269StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005270TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005271 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005272 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005273 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005274 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005275
Douglas Gregor306de2f2010-04-22 23:59:56 +00005276 // If nothing changed, just retain this statement.
5277 if (!getDerived().AlwaysRebuild() &&
5278 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005279 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005280
5281 // Build a new statement.
5282 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005283 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005284}
Mike Stump11289f42009-09-09 15:08:12 +00005285
Douglas Gregorebe10102009-08-20 07:17:43 +00005286template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005287StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005288TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005289 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005290 if (S->getThrowExpr()) {
5291 Operand = getDerived().TransformExpr(S->getThrowExpr());
5292 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005293 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005294 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005295
Douglas Gregor2900c162010-04-22 21:44:01 +00005296 if (!getDerived().AlwaysRebuild() &&
5297 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005298 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005299
John McCallb268a282010-08-23 23:25:46 +00005300 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005301}
Mike Stump11289f42009-09-09 15:08:12 +00005302
Douglas Gregorebe10102009-08-20 07:17:43 +00005303template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005304StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005305TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005306 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005307 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005308 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005309 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005310 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005311
Douglas Gregor6148de72010-04-22 22:01:21 +00005312 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005313 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005314 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005315 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005316
Douglas Gregor6148de72010-04-22 22:01:21 +00005317 // If nothing change, just retain the current statement.
5318 if (!getDerived().AlwaysRebuild() &&
5319 Object.get() == S->getSynchExpr() &&
5320 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005321 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005322
5323 // Build a new statement.
5324 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005325 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005326}
5327
5328template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005329StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005330TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005331 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005332 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005333 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005334 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005335 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005336
Douglas Gregorf68a5082010-04-22 23:10:45 +00005337 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005338 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005339 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005340 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005341
Douglas Gregorf68a5082010-04-22 23:10:45 +00005342 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005343 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005344 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005345 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005346
Douglas Gregorf68a5082010-04-22 23:10:45 +00005347 // If nothing changed, just retain this statement.
5348 if (!getDerived().AlwaysRebuild() &&
5349 Element.get() == S->getElement() &&
5350 Collection.get() == S->getCollection() &&
5351 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005352 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005353
Douglas Gregorf68a5082010-04-22 23:10:45 +00005354 // Build a new statement.
5355 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5356 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005357 Element.get(),
5358 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005359 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005360 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005361}
5362
5363
5364template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005365StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005366TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5367 // Transform the exception declaration, if any.
5368 VarDecl *Var = 0;
5369 if (S->getExceptionDecl()) {
5370 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005371 TypeSourceInfo *T = getDerived().TransformType(
5372 ExceptionDecl->getTypeSourceInfo());
5373 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005374 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005375
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005376 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00005377 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005378 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00005379 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005380 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005381 }
Mike Stump11289f42009-09-09 15:08:12 +00005382
Douglas Gregorebe10102009-08-20 07:17:43 +00005383 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005384 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005385 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005386 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005387
Douglas Gregorebe10102009-08-20 07:17:43 +00005388 if (!getDerived().AlwaysRebuild() &&
5389 !Var &&
5390 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005391 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005392
5393 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5394 Var,
John McCallb268a282010-08-23 23:25:46 +00005395 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005396}
Mike Stump11289f42009-09-09 15:08:12 +00005397
Douglas Gregorebe10102009-08-20 07:17:43 +00005398template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005399StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005400TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5401 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005402 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005403 = getDerived().TransformCompoundStmt(S->getTryBlock());
5404 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005405 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005406
Douglas Gregorebe10102009-08-20 07:17:43 +00005407 // Transform the handlers.
5408 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005409 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005410 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005411 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005412 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5413 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005414 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005415
Douglas Gregorebe10102009-08-20 07:17:43 +00005416 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5417 Handlers.push_back(Handler.takeAs<Stmt>());
5418 }
Mike Stump11289f42009-09-09 15:08:12 +00005419
Douglas Gregorebe10102009-08-20 07:17:43 +00005420 if (!getDerived().AlwaysRebuild() &&
5421 TryBlock.get() == S->getTryBlock() &&
5422 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005423 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005424
John McCallb268a282010-08-23 23:25:46 +00005425 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005426 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005427}
Mike Stump11289f42009-09-09 15:08:12 +00005428
Douglas Gregorebe10102009-08-20 07:17:43 +00005429//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005430// Expression transformation
5431//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005432template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005433ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005434TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005435 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005436}
Mike Stump11289f42009-09-09 15:08:12 +00005437
5438template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005439ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005440TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005441 NestedNameSpecifier *Qualifier = 0;
5442 if (E->getQualifier()) {
5443 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005444 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005445 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005446 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005447 }
John McCallce546572009-12-08 09:08:17 +00005448
5449 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005450 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5451 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005452 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005453 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005454
John McCall815039a2010-08-17 21:27:17 +00005455 DeclarationNameInfo NameInfo = E->getNameInfo();
5456 if (NameInfo.getName()) {
5457 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5458 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005459 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005460 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005461
5462 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005463 Qualifier == E->getQualifier() &&
5464 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005465 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005466 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005467
5468 // Mark it referenced in the new context regardless.
5469 // FIXME: this is a bit instantiation-specific.
5470 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5471
John McCallc3007a22010-10-26 07:05:15 +00005472 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005473 }
John McCallce546572009-12-08 09:08:17 +00005474
5475 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005476 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005477 TemplateArgs = &TransArgs;
5478 TransArgs.setLAngleLoc(E->getLAngleLoc());
5479 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005480 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5481 E->getNumTemplateArgs(),
5482 TransArgs))
5483 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005484 }
5485
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005486 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005487 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005488}
Mike Stump11289f42009-09-09 15:08:12 +00005489
Douglas Gregora16548e2009-08-11 05:31:07 +00005490template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005491ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005492TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005493 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005494}
Mike Stump11289f42009-09-09 15:08:12 +00005495
Douglas Gregora16548e2009-08-11 05:31:07 +00005496template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005497ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005498TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005499 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005500}
Mike Stump11289f42009-09-09 15:08:12 +00005501
Douglas Gregora16548e2009-08-11 05:31:07 +00005502template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005503ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005504TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005505 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005506}
Mike Stump11289f42009-09-09 15:08:12 +00005507
Douglas Gregora16548e2009-08-11 05:31:07 +00005508template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005509ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005510TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005511 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005512}
Mike Stump11289f42009-09-09 15:08:12 +00005513
Douglas Gregora16548e2009-08-11 05:31:07 +00005514template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005515ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005516TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005517 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005518}
5519
5520template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005521ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005522TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005523 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005524 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005525 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005526
Douglas Gregora16548e2009-08-11 05:31:07 +00005527 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005528 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005529
John McCallb268a282010-08-23 23:25:46 +00005530 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005531 E->getRParen());
5532}
5533
Mike Stump11289f42009-09-09 15:08:12 +00005534template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005535ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005536TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005537 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005538 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005539 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005540
Douglas Gregora16548e2009-08-11 05:31:07 +00005541 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005542 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005543
Douglas Gregora16548e2009-08-11 05:31:07 +00005544 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5545 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005546 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005547}
Mike Stump11289f42009-09-09 15:08:12 +00005548
Douglas Gregora16548e2009-08-11 05:31:07 +00005549template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005550ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005551TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5552 // Transform the type.
5553 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5554 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005555 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005556
Douglas Gregor882211c2010-04-28 22:16:22 +00005557 // Transform all of the components into components similar to what the
5558 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005559 // FIXME: It would be slightly more efficient in the non-dependent case to
5560 // just map FieldDecls, rather than requiring the rebuilder to look for
5561 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005562 // template code that we don't care.
5563 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005564 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005565 typedef OffsetOfExpr::OffsetOfNode Node;
5566 llvm::SmallVector<Component, 4> Components;
5567 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5568 const Node &ON = E->getComponent(I);
5569 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005570 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00005571 Comp.LocStart = ON.getRange().getBegin();
5572 Comp.LocEnd = ON.getRange().getEnd();
5573 switch (ON.getKind()) {
5574 case Node::Array: {
5575 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005576 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005577 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005578 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005579
Douglas Gregor882211c2010-04-28 22:16:22 +00005580 ExprChanged = ExprChanged || Index.get() != FromIndex;
5581 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005582 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005583 break;
5584 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005585
Douglas Gregor882211c2010-04-28 22:16:22 +00005586 case Node::Field:
5587 case Node::Identifier:
5588 Comp.isBrackets = false;
5589 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005590 if (!Comp.U.IdentInfo)
5591 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005592
Douglas Gregor882211c2010-04-28 22:16:22 +00005593 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005594
Douglas Gregord1702062010-04-29 00:18:15 +00005595 case Node::Base:
5596 // Will be recomputed during the rebuild.
5597 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005598 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005599
Douglas Gregor882211c2010-04-28 22:16:22 +00005600 Components.push_back(Comp);
5601 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005602
Douglas Gregor882211c2010-04-28 22:16:22 +00005603 // If nothing changed, retain the existing expression.
5604 if (!getDerived().AlwaysRebuild() &&
5605 Type == E->getTypeSourceInfo() &&
5606 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005607 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005608
Douglas Gregor882211c2010-04-28 22:16:22 +00005609 // Build a new offsetof expression.
5610 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5611 Components.data(), Components.size(),
5612 E->getRParenLoc());
5613}
5614
5615template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005616ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005617TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5618 assert(getDerived().AlreadyTransformed(E->getType()) &&
5619 "opaque value expression requires transformation");
5620 return SemaRef.Owned(E);
5621}
5622
5623template<typename Derived>
5624ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005625TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005626 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005627 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005628
John McCallbcd03502009-12-07 02:54:59 +00005629 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005630 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005631 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005632
John McCall4c98fd82009-11-04 07:28:41 +00005633 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005634 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005635
John McCall4c98fd82009-11-04 07:28:41 +00005636 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005637 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005638 E->getSourceRange());
5639 }
Mike Stump11289f42009-09-09 15:08:12 +00005640
John McCalldadc5752010-08-24 06:29:42 +00005641 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005642 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005643 // C++0x [expr.sizeof]p1:
5644 // The operand is either an expression, which is an unevaluated operand
5645 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005646 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005647
Douglas Gregora16548e2009-08-11 05:31:07 +00005648 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5649 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005650 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005651
Douglas Gregora16548e2009-08-11 05:31:07 +00005652 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005653 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005654 }
Mike Stump11289f42009-09-09 15:08:12 +00005655
John McCallb268a282010-08-23 23:25:46 +00005656 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005657 E->isSizeOf(),
5658 E->getSourceRange());
5659}
Mike Stump11289f42009-09-09 15:08:12 +00005660
Douglas Gregora16548e2009-08-11 05:31:07 +00005661template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005662ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005663TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005664 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005665 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005666 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005667
John McCalldadc5752010-08-24 06:29:42 +00005668 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005669 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005670 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005671
5672
Douglas Gregora16548e2009-08-11 05:31:07 +00005673 if (!getDerived().AlwaysRebuild() &&
5674 LHS.get() == E->getLHS() &&
5675 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005676 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005677
John McCallb268a282010-08-23 23:25:46 +00005678 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005679 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005680 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005681 E->getRBracketLoc());
5682}
Mike Stump11289f42009-09-09 15:08:12 +00005683
5684template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005685ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005686TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005687 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005688 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005689 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005690 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005691
5692 // Transform arguments.
5693 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005694 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005695 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5696 &ArgChanged))
5697 return ExprError();
5698
Douglas Gregora16548e2009-08-11 05:31:07 +00005699 if (!getDerived().AlwaysRebuild() &&
5700 Callee.get() == E->getCallee() &&
5701 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005702 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005703
Douglas Gregora16548e2009-08-11 05:31:07 +00005704 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005705 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005706 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005707 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005708 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005709 E->getRParenLoc());
5710}
Mike Stump11289f42009-09-09 15:08:12 +00005711
5712template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005713ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005714TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005715 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005716 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005717 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005718
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005719 NestedNameSpecifier *Qualifier = 0;
5720 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00005721 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005722 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005723 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00005724 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00005725 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005726 }
Mike Stump11289f42009-09-09 15:08:12 +00005727
Eli Friedman2cfcef62009-12-04 06:40:45 +00005728 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005729 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5730 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005731 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005732 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005733
John McCall16df1e52010-03-30 21:47:33 +00005734 NamedDecl *FoundDecl = E->getFoundDecl();
5735 if (FoundDecl == E->getMemberDecl()) {
5736 FoundDecl = Member;
5737 } else {
5738 FoundDecl = cast_or_null<NamedDecl>(
5739 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5740 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005741 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005742 }
5743
Douglas Gregora16548e2009-08-11 05:31:07 +00005744 if (!getDerived().AlwaysRebuild() &&
5745 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005746 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005747 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005748 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005749 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005750
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005751 // Mark it referenced in the new context regardless.
5752 // FIXME: this is a bit instantiation-specific.
5753 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005754 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005755 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005756
John McCall6b51f282009-11-23 01:53:49 +00005757 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005758 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005759 TransArgs.setLAngleLoc(E->getLAngleLoc());
5760 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005761 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5762 E->getNumTemplateArgs(),
5763 TransArgs))
5764 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005765 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005766
Douglas Gregora16548e2009-08-11 05:31:07 +00005767 // FIXME: Bogus source location for the operator
5768 SourceLocation FakeOperatorLoc
5769 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5770
John McCall38836f02010-01-15 08:34:02 +00005771 // FIXME: to do this check properly, we will need to preserve the
5772 // first-qualifier-in-scope here, just in case we had a dependent
5773 // base (and therefore couldn't do the check) and a
5774 // nested-name-qualifier (and therefore could do the lookup).
5775 NamedDecl *FirstQualifierInScope = 0;
5776
John McCallb268a282010-08-23 23:25:46 +00005777 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005778 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005779 Qualifier,
5780 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005781 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005782 Member,
John McCall16df1e52010-03-30 21:47:33 +00005783 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005784 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005785 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005786 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005787}
Mike Stump11289f42009-09-09 15:08:12 +00005788
Douglas Gregora16548e2009-08-11 05:31:07 +00005789template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005790ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005791TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005792 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005793 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005794 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005795
John McCalldadc5752010-08-24 06:29:42 +00005796 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005797 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005798 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005799
Douglas Gregora16548e2009-08-11 05:31:07 +00005800 if (!getDerived().AlwaysRebuild() &&
5801 LHS.get() == E->getLHS() &&
5802 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005803 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005804
Douglas Gregora16548e2009-08-11 05:31:07 +00005805 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005806 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005807}
5808
Mike Stump11289f42009-09-09 15:08:12 +00005809template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005810ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005811TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005812 CompoundAssignOperator *E) {
5813 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005814}
Mike Stump11289f42009-09-09 15:08:12 +00005815
Douglas Gregora16548e2009-08-11 05:31:07 +00005816template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00005817ExprResult TreeTransform<Derived>::
5818TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
5819 // Just rebuild the common and RHS expressions and see whether we
5820 // get any changes.
5821
5822 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
5823 if (commonExpr.isInvalid())
5824 return ExprError();
5825
5826 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
5827 if (rhs.isInvalid())
5828 return ExprError();
5829
5830 if (!getDerived().AlwaysRebuild() &&
5831 commonExpr.get() == e->getCommon() &&
5832 rhs.get() == e->getFalseExpr())
5833 return SemaRef.Owned(e);
5834
5835 return getDerived().RebuildConditionalOperator(commonExpr.take(),
5836 e->getQuestionLoc(),
5837 0,
5838 e->getColonLoc(),
5839 rhs.get());
5840}
5841
5842template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005843ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005844TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005845 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005846 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005847 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005848
John McCalldadc5752010-08-24 06:29:42 +00005849 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005850 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005851 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005852
John McCalldadc5752010-08-24 06:29:42 +00005853 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005854 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005855 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005856
Douglas Gregora16548e2009-08-11 05:31:07 +00005857 if (!getDerived().AlwaysRebuild() &&
5858 Cond.get() == E->getCond() &&
5859 LHS.get() == E->getLHS() &&
5860 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005861 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005862
John McCallb268a282010-08-23 23:25:46 +00005863 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005864 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005865 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005866 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005867 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005868}
Mike Stump11289f42009-09-09 15:08:12 +00005869
5870template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005871ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005872TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005873 // Implicit casts are eliminated during transformation, since they
5874 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005875 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005876}
Mike Stump11289f42009-09-09 15:08:12 +00005877
Douglas Gregora16548e2009-08-11 05:31:07 +00005878template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005879ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005880TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005881 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5882 if (!Type)
5883 return ExprError();
5884
John McCalldadc5752010-08-24 06:29:42 +00005885 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005886 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005887 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005888 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005889
Douglas Gregora16548e2009-08-11 05:31:07 +00005890 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005891 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005892 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005893 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005894
John McCall97513962010-01-15 18:39:57 +00005895 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005896 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005897 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005898 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005899}
Mike Stump11289f42009-09-09 15:08:12 +00005900
Douglas Gregora16548e2009-08-11 05:31:07 +00005901template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005902ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005903TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005904 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5905 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5906 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005907 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005908
John McCalldadc5752010-08-24 06:29:42 +00005909 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005910 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005911 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005912
Douglas Gregora16548e2009-08-11 05:31:07 +00005913 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005914 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005915 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005916 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005917
John McCall5d7aa7f2010-01-19 22:33:45 +00005918 // Note: the expression type doesn't necessarily match the
5919 // type-as-written, but that's okay, because it should always be
5920 // derivable from the initializer.
5921
John McCalle15bbff2010-01-18 19:35:47 +00005922 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005923 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005924 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005925}
Mike Stump11289f42009-09-09 15:08:12 +00005926
Douglas Gregora16548e2009-08-11 05:31:07 +00005927template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005928ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005929TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005930 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005931 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005932 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005933
Douglas Gregora16548e2009-08-11 05:31:07 +00005934 if (!getDerived().AlwaysRebuild() &&
5935 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00005936 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005937
Douglas Gregora16548e2009-08-11 05:31:07 +00005938 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005939 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005940 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005941 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005942 E->getAccessorLoc(),
5943 E->getAccessor());
5944}
Mike Stump11289f42009-09-09 15:08:12 +00005945
Douglas Gregora16548e2009-08-11 05:31:07 +00005946template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005947ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005948TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005949 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005950
John McCall37ad5512010-08-23 06:44:23 +00005951 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005952 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5953 Inits, &InitChanged))
5954 return ExprError();
5955
Douglas Gregora16548e2009-08-11 05:31:07 +00005956 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005957 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005958
Douglas Gregora16548e2009-08-11 05:31:07 +00005959 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005960 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005961}
Mike Stump11289f42009-09-09 15:08:12 +00005962
Douglas Gregora16548e2009-08-11 05:31:07 +00005963template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005964ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005965TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005966 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005967
Douglas Gregorebe10102009-08-20 07:17:43 +00005968 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005969 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005970 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005971 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005972
Douglas Gregorebe10102009-08-20 07:17:43 +00005973 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005974 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005975 bool ExprChanged = false;
5976 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5977 DEnd = E->designators_end();
5978 D != DEnd; ++D) {
5979 if (D->isFieldDesignator()) {
5980 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5981 D->getDotLoc(),
5982 D->getFieldLoc()));
5983 continue;
5984 }
Mike Stump11289f42009-09-09 15:08:12 +00005985
Douglas Gregora16548e2009-08-11 05:31:07 +00005986 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005987 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005988 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005989 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005990
5991 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005992 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005993
Douglas Gregora16548e2009-08-11 05:31:07 +00005994 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5995 ArrayExprs.push_back(Index.release());
5996 continue;
5997 }
Mike Stump11289f42009-09-09 15:08:12 +00005998
Douglas Gregora16548e2009-08-11 05:31:07 +00005999 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00006000 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00006001 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6002 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006003 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006004
John McCalldadc5752010-08-24 06:29:42 +00006005 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006006 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006007 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006008
6009 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006010 End.get(),
6011 D->getLBracketLoc(),
6012 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006013
Douglas Gregora16548e2009-08-11 05:31:07 +00006014 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6015 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00006016
Douglas Gregora16548e2009-08-11 05:31:07 +00006017 ArrayExprs.push_back(Start.release());
6018 ArrayExprs.push_back(End.release());
6019 }
Mike Stump11289f42009-09-09 15:08:12 +00006020
Douglas Gregora16548e2009-08-11 05:31:07 +00006021 if (!getDerived().AlwaysRebuild() &&
6022 Init.get() == E->getInit() &&
6023 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006024 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006025
Douglas Gregora16548e2009-08-11 05:31:07 +00006026 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6027 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006028 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006029}
Mike Stump11289f42009-09-09 15:08:12 +00006030
Douglas Gregora16548e2009-08-11 05:31:07 +00006031template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006032ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006033TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006034 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00006035 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006036
Douglas Gregor3da3c062009-10-28 00:29:27 +00006037 // FIXME: Will we ever have proper type location here? Will we actually
6038 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00006039 QualType T = getDerived().TransformType(E->getType());
6040 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006041 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006042
Douglas Gregora16548e2009-08-11 05:31:07 +00006043 if (!getDerived().AlwaysRebuild() &&
6044 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006045 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006046
Douglas Gregora16548e2009-08-11 05:31:07 +00006047 return getDerived().RebuildImplicitValueInitExpr(T);
6048}
Mike Stump11289f42009-09-09 15:08:12 +00006049
Douglas Gregora16548e2009-08-11 05:31:07 +00006050template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006051ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006052TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00006053 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6054 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006055 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006056
John McCalldadc5752010-08-24 06:29:42 +00006057 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006058 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006059 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006060
Douglas Gregora16548e2009-08-11 05:31:07 +00006061 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00006062 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006063 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006064 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006065
John McCallb268a282010-08-23 23:25:46 +00006066 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00006067 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006068}
6069
6070template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006071ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006072TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006073 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006074 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006075 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6076 &ArgumentChanged))
6077 return ExprError();
6078
Douglas Gregora16548e2009-08-11 05:31:07 +00006079 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6080 move_arg(Inits),
6081 E->getRParenLoc());
6082}
Mike Stump11289f42009-09-09 15:08:12 +00006083
Douglas Gregora16548e2009-08-11 05:31:07 +00006084/// \brief Transform an address-of-label expression.
6085///
6086/// By default, the transformation of an address-of-label expression always
6087/// rebuilds the expression, so that the label identifier can be resolved to
6088/// the corresponding label statement by semantic analysis.
6089template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006090ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006091TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006092 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6093 E->getLabel());
6094 if (!LD)
6095 return ExprError();
6096
Douglas Gregora16548e2009-08-11 05:31:07 +00006097 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006098 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006099}
Mike Stump11289f42009-09-09 15:08:12 +00006100
6101template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006102ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006103TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006104 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006105 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6106 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006107 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006108
Douglas Gregora16548e2009-08-11 05:31:07 +00006109 if (!getDerived().AlwaysRebuild() &&
6110 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006111 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006112
6113 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006114 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006115 E->getRParenLoc());
6116}
Mike Stump11289f42009-09-09 15:08:12 +00006117
Douglas Gregora16548e2009-08-11 05:31:07 +00006118template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006119ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006120TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006121 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006122 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006123 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006124
John McCalldadc5752010-08-24 06:29:42 +00006125 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006126 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006127 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006128
John McCalldadc5752010-08-24 06:29:42 +00006129 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006130 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006131 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006132
Douglas Gregora16548e2009-08-11 05:31:07 +00006133 if (!getDerived().AlwaysRebuild() &&
6134 Cond.get() == E->getCond() &&
6135 LHS.get() == E->getLHS() &&
6136 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006137 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006138
Douglas Gregora16548e2009-08-11 05:31:07 +00006139 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006140 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006141 E->getRParenLoc());
6142}
Mike Stump11289f42009-09-09 15:08:12 +00006143
Douglas Gregora16548e2009-08-11 05:31:07 +00006144template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006145ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006146TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006147 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006148}
6149
6150template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006151ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006152TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006153 switch (E->getOperator()) {
6154 case OO_New:
6155 case OO_Delete:
6156 case OO_Array_New:
6157 case OO_Array_Delete:
6158 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006159 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006160
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006161 case OO_Call: {
6162 // This is a call to an object's operator().
6163 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6164
6165 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006166 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006167 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006168 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006169
6170 // FIXME: Poor location information
6171 SourceLocation FakeLParenLoc
6172 = SemaRef.PP.getLocForEndOfToken(
6173 static_cast<Expr *>(Object.get())->getLocEnd());
6174
6175 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006176 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006177 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6178 Args))
6179 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006180
John McCallb268a282010-08-23 23:25:46 +00006181 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006182 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006183 E->getLocEnd());
6184 }
6185
6186#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6187 case OO_##Name:
6188#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6189#include "clang/Basic/OperatorKinds.def"
6190 case OO_Subscript:
6191 // Handled below.
6192 break;
6193
6194 case OO_Conditional:
6195 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006196 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006197
6198 case OO_None:
6199 case NUM_OVERLOADED_OPERATORS:
6200 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006201 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006202 }
6203
John McCalldadc5752010-08-24 06:29:42 +00006204 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006205 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006206 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006207
John McCalldadc5752010-08-24 06:29:42 +00006208 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006209 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006210 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006211
John McCalldadc5752010-08-24 06:29:42 +00006212 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006213 if (E->getNumArgs() == 2) {
6214 Second = getDerived().TransformExpr(E->getArg(1));
6215 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006216 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006217 }
Mike Stump11289f42009-09-09 15:08:12 +00006218
Douglas Gregora16548e2009-08-11 05:31:07 +00006219 if (!getDerived().AlwaysRebuild() &&
6220 Callee.get() == E->getCallee() &&
6221 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006222 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006223 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006224
Douglas Gregora16548e2009-08-11 05:31:07 +00006225 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6226 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006227 Callee.get(),
6228 First.get(),
6229 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006230}
Mike Stump11289f42009-09-09 15:08:12 +00006231
Douglas Gregora16548e2009-08-11 05:31:07 +00006232template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006233ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006234TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6235 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006236}
Mike Stump11289f42009-09-09 15:08:12 +00006237
Douglas Gregora16548e2009-08-11 05:31:07 +00006238template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006239ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006240TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6241 // Transform the callee.
6242 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6243 if (Callee.isInvalid())
6244 return ExprError();
6245
6246 // Transform exec config.
6247 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6248 if (EC.isInvalid())
6249 return ExprError();
6250
6251 // Transform arguments.
6252 bool ArgChanged = false;
6253 ASTOwningVector<Expr*> Args(SemaRef);
6254 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6255 &ArgChanged))
6256 return ExprError();
6257
6258 if (!getDerived().AlwaysRebuild() &&
6259 Callee.get() == E->getCallee() &&
6260 !ArgChanged)
6261 return SemaRef.Owned(E);
6262
6263 // FIXME: Wrong source location information for the '('.
6264 SourceLocation FakeLParenLoc
6265 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6266 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6267 move_arg(Args),
6268 E->getRParenLoc(), EC.get());
6269}
6270
6271template<typename Derived>
6272ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006273TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006274 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6275 if (!Type)
6276 return ExprError();
6277
John McCalldadc5752010-08-24 06:29:42 +00006278 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006279 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006280 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006281 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006282
Douglas Gregora16548e2009-08-11 05:31:07 +00006283 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006284 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006285 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006286 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006287
Douglas Gregora16548e2009-08-11 05:31:07 +00006288 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006289 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006290 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6291 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6292 SourceLocation FakeRParenLoc
6293 = SemaRef.PP.getLocForEndOfToken(
6294 E->getSubExpr()->getSourceRange().getEnd());
6295 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006296 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006297 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006298 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006299 FakeRAngleLoc,
6300 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006301 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006302 FakeRParenLoc);
6303}
Mike Stump11289f42009-09-09 15:08:12 +00006304
Douglas Gregora16548e2009-08-11 05:31:07 +00006305template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006306ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006307TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6308 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006309}
Mike Stump11289f42009-09-09 15:08:12 +00006310
6311template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006312ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006313TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6314 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006315}
6316
Douglas Gregora16548e2009-08-11 05:31:07 +00006317template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006318ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006319TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006320 CXXReinterpretCastExpr *E) {
6321 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006322}
Mike Stump11289f42009-09-09 15:08:12 +00006323
Douglas Gregora16548e2009-08-11 05:31:07 +00006324template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006325ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006326TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6327 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006328}
Mike Stump11289f42009-09-09 15:08:12 +00006329
Douglas Gregora16548e2009-08-11 05:31:07 +00006330template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006331ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006332TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006333 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006334 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6335 if (!Type)
6336 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006337
John McCalldadc5752010-08-24 06:29:42 +00006338 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006339 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006340 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006341 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006342
Douglas Gregora16548e2009-08-11 05:31:07 +00006343 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006344 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006345 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006346 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006347
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006348 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006349 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006350 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006351 E->getRParenLoc());
6352}
Mike Stump11289f42009-09-09 15:08:12 +00006353
Douglas Gregora16548e2009-08-11 05:31:07 +00006354template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006355ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006356TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006357 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006358 TypeSourceInfo *TInfo
6359 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6360 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006361 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006362
Douglas Gregora16548e2009-08-11 05:31:07 +00006363 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006364 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006365 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006366
Douglas Gregor9da64192010-04-26 22:37:10 +00006367 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6368 E->getLocStart(),
6369 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006370 E->getLocEnd());
6371 }
Mike Stump11289f42009-09-09 15:08:12 +00006372
Douglas Gregora16548e2009-08-11 05:31:07 +00006373 // We don't know whether the expression is potentially evaluated until
6374 // after we perform semantic analysis, so the expression is potentially
6375 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006376 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006377 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006378
John McCalldadc5752010-08-24 06:29:42 +00006379 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006380 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006381 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006382
Douglas Gregora16548e2009-08-11 05:31:07 +00006383 if (!getDerived().AlwaysRebuild() &&
6384 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006385 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006386
Douglas Gregor9da64192010-04-26 22:37:10 +00006387 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6388 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006389 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006390 E->getLocEnd());
6391}
6392
6393template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006394ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006395TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6396 if (E->isTypeOperand()) {
6397 TypeSourceInfo *TInfo
6398 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6399 if (!TInfo)
6400 return ExprError();
6401
6402 if (!getDerived().AlwaysRebuild() &&
6403 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006404 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006405
6406 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6407 E->getLocStart(),
6408 TInfo,
6409 E->getLocEnd());
6410 }
6411
6412 // We don't know whether the expression is potentially evaluated until
6413 // after we perform semantic analysis, so the expression is potentially
6414 // potentially evaluated.
6415 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6416
6417 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6418 if (SubExpr.isInvalid())
6419 return ExprError();
6420
6421 if (!getDerived().AlwaysRebuild() &&
6422 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006423 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006424
6425 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6426 E->getLocStart(),
6427 SubExpr.get(),
6428 E->getLocEnd());
6429}
6430
6431template<typename Derived>
6432ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006433TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006434 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006435}
Mike Stump11289f42009-09-09 15:08:12 +00006436
Douglas Gregora16548e2009-08-11 05:31:07 +00006437template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006438ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006439TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006440 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006441 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006442}
Mike Stump11289f42009-09-09 15:08:12 +00006443
Douglas Gregora16548e2009-08-11 05:31:07 +00006444template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006445ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006446TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006447 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6448 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6449 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006450
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006451 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006452 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006453
Douglas Gregorb15af892010-01-07 23:12:05 +00006454 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006455}
Mike Stump11289f42009-09-09 15:08:12 +00006456
Douglas Gregora16548e2009-08-11 05:31:07 +00006457template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006458ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006459TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006460 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006461 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006462 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006463
Douglas Gregora16548e2009-08-11 05:31:07 +00006464 if (!getDerived().AlwaysRebuild() &&
6465 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006466 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006467
John McCallb268a282010-08-23 23:25:46 +00006468 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006469}
Mike Stump11289f42009-09-09 15:08:12 +00006470
Douglas Gregora16548e2009-08-11 05:31:07 +00006471template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006472ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006473TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006474 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006475 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6476 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006477 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006478 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006479
Chandler Carruth794da4c2010-02-08 06:42:49 +00006480 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006481 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006482 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006483
Douglas Gregor033f6752009-12-23 23:03:06 +00006484 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006485}
Mike Stump11289f42009-09-09 15:08:12 +00006486
Douglas Gregora16548e2009-08-11 05:31:07 +00006487template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006488ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006489TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6490 CXXScalarValueInitExpr *E) {
6491 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6492 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006493 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006494
Douglas Gregora16548e2009-08-11 05:31:07 +00006495 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006496 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006497 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006498
Douglas Gregor2b88c112010-09-08 00:15:04 +00006499 return getDerived().RebuildCXXScalarValueInitExpr(T,
6500 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006501 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006502}
Mike Stump11289f42009-09-09 15:08:12 +00006503
Douglas Gregora16548e2009-08-11 05:31:07 +00006504template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006505ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006506TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006507 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006508 TypeSourceInfo *AllocTypeInfo
6509 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6510 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006511 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006512
Douglas Gregora16548e2009-08-11 05:31:07 +00006513 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006514 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006515 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006516 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006517
Douglas Gregora16548e2009-08-11 05:31:07 +00006518 // Transform the placement arguments (if any).
6519 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006520 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006521 if (getDerived().TransformExprs(E->getPlacementArgs(),
6522 E->getNumPlacementArgs(), true,
6523 PlacementArgs, &ArgumentChanged))
6524 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006525
Douglas Gregorebe10102009-08-20 07:17:43 +00006526 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006527 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006528 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6529 ConstructorArgs, &ArgumentChanged))
6530 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006531
Douglas Gregord2d9da02010-02-26 00:38:10 +00006532 // Transform constructor, new operator, and delete operator.
6533 CXXConstructorDecl *Constructor = 0;
6534 if (E->getConstructor()) {
6535 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006536 getDerived().TransformDecl(E->getLocStart(),
6537 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006538 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006539 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006540 }
6541
6542 FunctionDecl *OperatorNew = 0;
6543 if (E->getOperatorNew()) {
6544 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006545 getDerived().TransformDecl(E->getLocStart(),
6546 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006547 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006548 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006549 }
6550
6551 FunctionDecl *OperatorDelete = 0;
6552 if (E->getOperatorDelete()) {
6553 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006554 getDerived().TransformDecl(E->getLocStart(),
6555 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006556 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006557 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006558 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006559
Douglas Gregora16548e2009-08-11 05:31:07 +00006560 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006561 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006562 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006563 Constructor == E->getConstructor() &&
6564 OperatorNew == E->getOperatorNew() &&
6565 OperatorDelete == E->getOperatorDelete() &&
6566 !ArgumentChanged) {
6567 // Mark any declarations we need as referenced.
6568 // FIXME: instantiation-specific.
6569 if (Constructor)
6570 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6571 if (OperatorNew)
6572 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6573 if (OperatorDelete)
6574 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006575 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006576 }
Mike Stump11289f42009-09-09 15:08:12 +00006577
Douglas Gregor0744ef62010-09-07 21:49:58 +00006578 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006579 if (!ArraySize.get()) {
6580 // If no array size was specified, but the new expression was
6581 // instantiated with an array type (e.g., "new T" where T is
6582 // instantiated with "int[4]"), extract the outer bound from the
6583 // array type as our array size. We do this with constant and
6584 // dependently-sized array types.
6585 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6586 if (!ArrayT) {
6587 // Do nothing
6588 } else if (const ConstantArrayType *ConsArrayT
6589 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006590 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006591 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6592 ConsArrayT->getSize(),
6593 SemaRef.Context.getSizeType(),
6594 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006595 AllocType = ConsArrayT->getElementType();
6596 } else if (const DependentSizedArrayType *DepArrayT
6597 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6598 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006599 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006600 AllocType = DepArrayT->getElementType();
6601 }
6602 }
6603 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006604
Douglas Gregora16548e2009-08-11 05:31:07 +00006605 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6606 E->isGlobalNew(),
6607 /*FIXME:*/E->getLocStart(),
6608 move_arg(PlacementArgs),
6609 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006610 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006611 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006612 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006613 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006614 /*FIXME:*/E->getLocStart(),
6615 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006616 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006617}
Mike Stump11289f42009-09-09 15:08:12 +00006618
Douglas Gregora16548e2009-08-11 05:31:07 +00006619template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006620ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006621TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006622 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006623 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006624 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006625
Douglas Gregord2d9da02010-02-26 00:38:10 +00006626 // Transform the delete operator, if known.
6627 FunctionDecl *OperatorDelete = 0;
6628 if (E->getOperatorDelete()) {
6629 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006630 getDerived().TransformDecl(E->getLocStart(),
6631 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006632 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006633 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006634 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006635
Douglas Gregora16548e2009-08-11 05:31:07 +00006636 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006637 Operand.get() == E->getArgument() &&
6638 OperatorDelete == E->getOperatorDelete()) {
6639 // Mark any declarations we need as referenced.
6640 // FIXME: instantiation-specific.
6641 if (OperatorDelete)
6642 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006643
6644 if (!E->getArgument()->isTypeDependent()) {
6645 QualType Destroyed = SemaRef.Context.getBaseElementType(
6646 E->getDestroyedType());
6647 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6648 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6649 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6650 SemaRef.LookupDestructor(Record));
6651 }
6652 }
6653
John McCallc3007a22010-10-26 07:05:15 +00006654 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006655 }
Mike Stump11289f42009-09-09 15:08:12 +00006656
Douglas Gregora16548e2009-08-11 05:31:07 +00006657 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6658 E->isGlobalDelete(),
6659 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006660 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006661}
Mike Stump11289f42009-09-09 15:08:12 +00006662
Douglas Gregora16548e2009-08-11 05:31:07 +00006663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006664ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006665TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006666 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006667 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006668 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006669 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006670
John McCallba7bf592010-08-24 05:47:05 +00006671 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006672 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006673 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006674 E->getOperatorLoc(),
6675 E->isArrow()? tok::arrow : tok::period,
6676 ObjectTypePtr,
6677 MayBePseudoDestructor);
6678 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006679 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006680
John McCallba7bf592010-08-24 05:47:05 +00006681 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00006682 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6683 if (QualifierLoc) {
6684 QualifierLoc
6685 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6686 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00006687 return ExprError();
6688 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00006689 CXXScopeSpec SS;
6690 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00006691
Douglas Gregor678f90d2010-02-25 01:56:36 +00006692 PseudoDestructorTypeStorage Destroyed;
6693 if (E->getDestroyedTypeInfo()) {
6694 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006695 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006696 ObjectType, 0,
6697 QualifierLoc.getNestedNameSpecifier());
Douglas Gregor678f90d2010-02-25 01:56:36 +00006698 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006699 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006700 Destroyed = DestroyedTypeInfo;
6701 } else if (ObjectType->isDependentType()) {
6702 // We aren't likely to be able to resolve the identifier down to a type
6703 // now anyway, so just retain the identifier.
6704 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6705 E->getDestroyedTypeLoc());
6706 } else {
6707 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00006708 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006709 *E->getDestroyedTypeIdentifier(),
6710 E->getDestroyedTypeLoc(),
6711 /*Scope=*/0,
6712 SS, ObjectTypePtr,
6713 false);
6714 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006715 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006716
Douglas Gregor678f90d2010-02-25 01:56:36 +00006717 Destroyed
6718 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6719 E->getDestroyedTypeLoc());
6720 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006721
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006722 TypeSourceInfo *ScopeTypeInfo = 0;
6723 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006724 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006725 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006726 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006727 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006728
John McCallb268a282010-08-23 23:25:46 +00006729 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006730 E->getOperatorLoc(),
6731 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006732 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006733 ScopeTypeInfo,
6734 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006735 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006736 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006737}
Mike Stump11289f42009-09-09 15:08:12 +00006738
Douglas Gregorad8a3362009-09-04 17:36:40 +00006739template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006740ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006741TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006742 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006743 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6744
6745 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6746 Sema::LookupOrdinaryName);
6747
6748 // Transform all the decls.
6749 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6750 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006751 NamedDecl *InstD = static_cast<NamedDecl*>(
6752 getDerived().TransformDecl(Old->getNameLoc(),
6753 *I));
John McCall84d87672009-12-10 09:41:52 +00006754 if (!InstD) {
6755 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6756 // This can happen because of dependent hiding.
6757 if (isa<UsingShadowDecl>(*I))
6758 continue;
6759 else
John McCallfaf5fb42010-08-26 23:41:50 +00006760 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006761 }
John McCalle66edc12009-11-24 19:00:30 +00006762
6763 // Expand using declarations.
6764 if (isa<UsingDecl>(InstD)) {
6765 UsingDecl *UD = cast<UsingDecl>(InstD);
6766 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6767 E = UD->shadow_end(); I != E; ++I)
6768 R.addDecl(*I);
6769 continue;
6770 }
6771
6772 R.addDecl(InstD);
6773 }
6774
6775 // Resolve a kind, but don't do any further analysis. If it's
6776 // ambiguous, the callee needs to deal with it.
6777 R.resolveKind();
6778
6779 // Rebuild the nested-name qualifier, if present.
6780 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00006781 if (Old->getQualifierLoc()) {
6782 NestedNameSpecifierLoc QualifierLoc
6783 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
6784 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006785 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006786
Douglas Gregor0da1d432011-02-28 20:01:57 +00006787 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006788 }
6789
Douglas Gregor9262f472010-04-27 18:19:34 +00006790 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006791 CXXRecordDecl *NamingClass
6792 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6793 Old->getNameLoc(),
6794 Old->getNamingClass()));
6795 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006796 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006797
Douglas Gregorda7be082010-04-27 16:10:10 +00006798 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006799 }
6800
6801 // If we have no template arguments, it's a normal declaration name.
6802 if (!Old->hasExplicitTemplateArgs())
6803 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6804
6805 // If we have template arguments, rebuild them, then rebuild the
6806 // templateid expression.
6807 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006808 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6809 Old->getNumTemplateArgs(),
6810 TransArgs))
6811 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006812
6813 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6814 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006815}
Mike Stump11289f42009-09-09 15:08:12 +00006816
Douglas Gregora16548e2009-08-11 05:31:07 +00006817template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006818ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006819TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006820 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6821 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006822 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006823
Douglas Gregora16548e2009-08-11 05:31:07 +00006824 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006825 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006826 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006827
Mike Stump11289f42009-09-09 15:08:12 +00006828 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006829 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006830 T,
6831 E->getLocEnd());
6832}
Mike Stump11289f42009-09-09 15:08:12 +00006833
Douglas Gregora16548e2009-08-11 05:31:07 +00006834template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006835ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006836TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6837 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6838 if (!LhsT)
6839 return ExprError();
6840
6841 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6842 if (!RhsT)
6843 return ExprError();
6844
6845 if (!getDerived().AlwaysRebuild() &&
6846 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6847 return SemaRef.Owned(E);
6848
6849 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6850 E->getLocStart(),
6851 LhsT, RhsT,
6852 E->getLocEnd());
6853}
6854
6855template<typename Derived>
6856ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006857TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006858 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006859 NestedNameSpecifierLoc QualifierLoc
6860 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6861 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006862 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006863
John McCall31f82722010-11-12 08:19:04 +00006864 // TODO: If this is a conversion-function-id, verify that the
6865 // destination type name (if present) resolves the same way after
6866 // instantiation as it did in the local scope.
6867
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006868 DeclarationNameInfo NameInfo
6869 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6870 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006871 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006872
John McCalle66edc12009-11-24 19:00:30 +00006873 if (!E->hasExplicitTemplateArgs()) {
6874 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006875 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006876 // Note: it is sufficient to compare the Name component of NameInfo:
6877 // if name has not changed, DNLoc has not changed either.
6878 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006879 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006880
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006881 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006882 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006883 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006884 }
John McCall6b51f282009-11-23 01:53:49 +00006885
6886 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006887 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6888 E->getNumTemplateArgs(),
6889 TransArgs))
6890 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006891
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006892 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006893 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006894 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006895}
6896
6897template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006898ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006899TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006900 // CXXConstructExprs are always implicit, so when we have a
6901 // 1-argument construction we just transform that argument.
6902 if (E->getNumArgs() == 1 ||
6903 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6904 return getDerived().TransformExpr(E->getArg(0));
6905
Douglas Gregora16548e2009-08-11 05:31:07 +00006906 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6907
6908 QualType T = getDerived().TransformType(E->getType());
6909 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006910 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006911
6912 CXXConstructorDecl *Constructor
6913 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006914 getDerived().TransformDecl(E->getLocStart(),
6915 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006916 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006917 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006918
Douglas Gregora16548e2009-08-11 05:31:07 +00006919 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006920 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006921 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6922 &ArgumentChanged))
6923 return ExprError();
6924
Douglas Gregora16548e2009-08-11 05:31:07 +00006925 if (!getDerived().AlwaysRebuild() &&
6926 T == E->getType() &&
6927 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006928 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006929 // Mark the constructor as referenced.
6930 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006931 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006932 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006933 }
Mike Stump11289f42009-09-09 15:08:12 +00006934
Douglas Gregordb121ba2009-12-14 16:27:04 +00006935 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6936 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006937 move_arg(Args),
6938 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006939 E->getConstructionKind(),
6940 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006941}
Mike Stump11289f42009-09-09 15:08:12 +00006942
Douglas Gregora16548e2009-08-11 05:31:07 +00006943/// \brief Transform a C++ temporary-binding expression.
6944///
Douglas Gregor363b1512009-12-24 18:51:59 +00006945/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6946/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006947template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006948ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006949TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006950 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006951}
Mike Stump11289f42009-09-09 15:08:12 +00006952
John McCall5d413782010-12-06 08:20:24 +00006953/// \brief Transform a C++ expression that contains cleanups that should
6954/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006955///
John McCall5d413782010-12-06 08:20:24 +00006956/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006957/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006958template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006959ExprResult
John McCall5d413782010-12-06 08:20:24 +00006960TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006961 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006962}
Mike Stump11289f42009-09-09 15:08:12 +00006963
Douglas Gregora16548e2009-08-11 05:31:07 +00006964template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006965ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006966TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006967 CXXTemporaryObjectExpr *E) {
6968 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6969 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006970 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006971
Douglas Gregora16548e2009-08-11 05:31:07 +00006972 CXXConstructorDecl *Constructor
6973 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006974 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006975 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006976 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006977 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006978
Douglas Gregora16548e2009-08-11 05:31:07 +00006979 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006980 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006981 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00006982 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6983 &ArgumentChanged))
6984 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006985
Douglas Gregora16548e2009-08-11 05:31:07 +00006986 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006987 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006988 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006989 !ArgumentChanged) {
6990 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006991 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006992 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006993 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006994
6995 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6996 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006997 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006998 E->getLocEnd());
6999}
Mike Stump11289f42009-09-09 15:08:12 +00007000
Douglas Gregora16548e2009-08-11 05:31:07 +00007001template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007002ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007003TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007004 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00007005 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7006 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007007 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007008
Douglas Gregora16548e2009-08-11 05:31:07 +00007009 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007010 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007011 Args.reserve(E->arg_size());
7012 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7013 &ArgumentChanged))
7014 return ExprError();
7015
Douglas Gregora16548e2009-08-11 05:31:07 +00007016 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007017 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007018 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007019 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007020
Douglas Gregora16548e2009-08-11 05:31:07 +00007021 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00007022 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00007023 E->getLParenLoc(),
7024 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007025 E->getRParenLoc());
7026}
Mike Stump11289f42009-09-09 15:08:12 +00007027
Douglas Gregora16548e2009-08-11 05:31:07 +00007028template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007029ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007030TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007031 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007032 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007033 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007034 Expr *OldBase;
7035 QualType BaseType;
7036 QualType ObjectType;
7037 if (!E->isImplicitAccess()) {
7038 OldBase = E->getBase();
7039 Base = getDerived().TransformExpr(OldBase);
7040 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007041 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007042
John McCall2d74de92009-12-01 22:10:20 +00007043 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00007044 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00007045 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007046 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007047 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007048 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00007049 ObjectTy,
7050 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00007051 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007052 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007053
John McCallba7bf592010-08-24 05:47:05 +00007054 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00007055 BaseType = ((Expr*) Base.get())->getType();
7056 } else {
7057 OldBase = 0;
7058 BaseType = getDerived().TransformType(E->getBaseType());
7059 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7060 }
Mike Stump11289f42009-09-09 15:08:12 +00007061
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007062 // Transform the first part of the nested-name-specifier that qualifies
7063 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007064 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007065 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00007066 E->getFirstQualifierFoundInScope(),
7067 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00007068
Douglas Gregore16af532011-02-28 18:50:33 +00007069 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007070 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00007071 QualifierLoc
7072 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7073 ObjectType,
7074 FirstQualifierInScope);
7075 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007076 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007077 }
Mike Stump11289f42009-09-09 15:08:12 +00007078
John McCall31f82722010-11-12 08:19:04 +00007079 // TODO: If this is a conversion-function-id, verify that the
7080 // destination type name (if present) resolves the same way after
7081 // instantiation as it did in the local scope.
7082
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007083 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007084 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007085 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007086 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007087
John McCall2d74de92009-12-01 22:10:20 +00007088 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007089 // This is a reference to a member without an explicitly-specified
7090 // template argument list. Optimize for this common case.
7091 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007092 Base.get() == OldBase &&
7093 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007094 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007095 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007096 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007097 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007098
John McCallb268a282010-08-23 23:25:46 +00007099 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007100 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007101 E->isArrow(),
7102 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007103 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007104 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007105 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007106 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007107 }
7108
John McCall6b51f282009-11-23 01:53:49 +00007109 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007110 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7111 E->getNumTemplateArgs(),
7112 TransArgs))
7113 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007114
John McCallb268a282010-08-23 23:25:46 +00007115 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007116 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007117 E->isArrow(),
7118 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007119 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007120 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007121 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007122 &TransArgs);
7123}
7124
7125template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007126ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007127TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007128 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007129 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007130 QualType BaseType;
7131 if (!Old->isImplicitAccess()) {
7132 Base = getDerived().TransformExpr(Old->getBase());
7133 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007134 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007135 BaseType = ((Expr*) Base.get())->getType();
7136 } else {
7137 BaseType = getDerived().TransformType(Old->getBaseType());
7138 }
John McCall10eae182009-11-30 22:42:35 +00007139
Douglas Gregor0da1d432011-02-28 20:01:57 +00007140 NestedNameSpecifierLoc QualifierLoc;
7141 if (Old->getQualifierLoc()) {
7142 QualifierLoc
7143 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7144 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007145 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007146 }
7147
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007148 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007149 Sema::LookupOrdinaryName);
7150
7151 // Transform all the decls.
7152 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7153 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007154 NamedDecl *InstD = static_cast<NamedDecl*>(
7155 getDerived().TransformDecl(Old->getMemberLoc(),
7156 *I));
John McCall84d87672009-12-10 09:41:52 +00007157 if (!InstD) {
7158 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7159 // This can happen because of dependent hiding.
7160 if (isa<UsingShadowDecl>(*I))
7161 continue;
7162 else
John McCallfaf5fb42010-08-26 23:41:50 +00007163 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00007164 }
John McCall10eae182009-11-30 22:42:35 +00007165
7166 // Expand using declarations.
7167 if (isa<UsingDecl>(InstD)) {
7168 UsingDecl *UD = cast<UsingDecl>(InstD);
7169 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7170 E = UD->shadow_end(); I != E; ++I)
7171 R.addDecl(*I);
7172 continue;
7173 }
7174
7175 R.addDecl(InstD);
7176 }
7177
7178 R.resolveKind();
7179
Douglas Gregor9262f472010-04-27 18:19:34 +00007180 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007181 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007182 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007183 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007184 Old->getMemberLoc(),
7185 Old->getNamingClass()));
7186 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007187 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007188
Douglas Gregorda7be082010-04-27 16:10:10 +00007189 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007190 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007191
John McCall10eae182009-11-30 22:42:35 +00007192 TemplateArgumentListInfo TransArgs;
7193 if (Old->hasExplicitTemplateArgs()) {
7194 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7195 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007196 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7197 Old->getNumTemplateArgs(),
7198 TransArgs))
7199 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007200 }
John McCall38836f02010-01-15 08:34:02 +00007201
7202 // FIXME: to do this check properly, we will need to preserve the
7203 // first-qualifier-in-scope here, just in case we had a dependent
7204 // base (and therefore couldn't do the check) and a
7205 // nested-name-qualifier (and therefore could do the lookup).
7206 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007207
John McCallb268a282010-08-23 23:25:46 +00007208 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007209 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007210 Old->getOperatorLoc(),
7211 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007212 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007213 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007214 R,
7215 (Old->hasExplicitTemplateArgs()
7216 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007217}
7218
7219template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007220ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007221TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7222 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7223 if (SubExpr.isInvalid())
7224 return ExprError();
7225
7226 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007227 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007228
7229 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7230}
7231
7232template<typename Derived>
7233ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007234TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007235 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7236 if (Pattern.isInvalid())
7237 return ExprError();
7238
7239 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7240 return SemaRef.Owned(E);
7241
Douglas Gregorb8840002011-01-14 21:20:45 +00007242 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7243 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007244}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007245
7246template<typename Derived>
7247ExprResult
7248TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7249 // If E is not value-dependent, then nothing will change when we transform it.
7250 // Note: This is an instantiation-centric view.
7251 if (!E->isValueDependent())
7252 return SemaRef.Owned(E);
7253
7254 // Note: None of the implementations of TryExpandParameterPacks can ever
7255 // produce a diagnostic when given only a single unexpanded parameter pack,
7256 // so
7257 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7258 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007259 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007260 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007261 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7262 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007263 ShouldExpand, RetainExpansion,
7264 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007265 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007266
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007267 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007268 return SemaRef.Owned(E);
7269
7270 // We now know the length of the parameter pack, so build a new expression
7271 // that stores that length.
7272 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7273 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007274 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007275}
7276
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007277template<typename Derived>
7278ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007279TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7280 SubstNonTypeTemplateParmPackExpr *E) {
7281 // Default behavior is to do nothing with this transformation.
7282 return SemaRef.Owned(E);
7283}
7284
7285template<typename Derived>
7286ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007287TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007288 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007289}
7290
Mike Stump11289f42009-09-09 15:08:12 +00007291template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007292ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007293TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007294 TypeSourceInfo *EncodedTypeInfo
7295 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7296 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007297 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007298
Douglas Gregora16548e2009-08-11 05:31:07 +00007299 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007300 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007301 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007302
7303 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007304 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007305 E->getRParenLoc());
7306}
Mike Stump11289f42009-09-09 15:08:12 +00007307
Douglas Gregora16548e2009-08-11 05:31:07 +00007308template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007309ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007310TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007311 // Transform arguments.
7312 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007313 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007314 Args.reserve(E->getNumArgs());
7315 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7316 &ArgChanged))
7317 return ExprError();
7318
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007319 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7320 // Class message: transform the receiver type.
7321 TypeSourceInfo *ReceiverTypeInfo
7322 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7323 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007324 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007325
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007326 // If nothing changed, just retain the existing message send.
7327 if (!getDerived().AlwaysRebuild() &&
7328 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007329 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007330
7331 // Build a new class message send.
7332 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7333 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007334 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007335 E->getMethodDecl(),
7336 E->getLeftLoc(),
7337 move_arg(Args),
7338 E->getRightLoc());
7339 }
7340
7341 // Instance message: transform the receiver
7342 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7343 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007344 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007345 = getDerived().TransformExpr(E->getInstanceReceiver());
7346 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007347 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007348
7349 // If nothing changed, just retain the existing message send.
7350 if (!getDerived().AlwaysRebuild() &&
7351 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007352 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007353
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007354 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007355 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007356 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007357 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007358 E->getMethodDecl(),
7359 E->getLeftLoc(),
7360 move_arg(Args),
7361 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007362}
7363
Mike Stump11289f42009-09-09 15:08:12 +00007364template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007365ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007366TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007367 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007368}
7369
Mike Stump11289f42009-09-09 15:08:12 +00007370template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007371ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007372TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007373 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007374}
7375
Mike Stump11289f42009-09-09 15:08:12 +00007376template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007377ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007378TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007379 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007380 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007381 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007382 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007383
7384 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007385
Douglas Gregord51d90d2010-04-26 20:11:03 +00007386 // If nothing changed, just retain the existing expression.
7387 if (!getDerived().AlwaysRebuild() &&
7388 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007389 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007390
John McCallb268a282010-08-23 23:25:46 +00007391 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007392 E->getLocation(),
7393 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007394}
7395
Mike Stump11289f42009-09-09 15:08:12 +00007396template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007397ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007398TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007399 // 'super' and types never change. Property never changes. Just
7400 // retain the existing expression.
7401 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007402 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007403
Douglas Gregor9faee212010-04-26 20:47:02 +00007404 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007405 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007406 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007407 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007408
Douglas Gregor9faee212010-04-26 20:47:02 +00007409 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007410
Douglas Gregor9faee212010-04-26 20:47:02 +00007411 // If nothing changed, just retain the existing expression.
7412 if (!getDerived().AlwaysRebuild() &&
7413 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007414 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007415
John McCallb7bd14f2010-12-02 01:19:52 +00007416 if (E->isExplicitProperty())
7417 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7418 E->getExplicitProperty(),
7419 E->getLocation());
7420
7421 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7422 E->getType(),
7423 E->getImplicitPropertyGetter(),
7424 E->getImplicitPropertySetter(),
7425 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007426}
7427
Mike Stump11289f42009-09-09 15:08:12 +00007428template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007429ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007430TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007431 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007432 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007433 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007434 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007435
Douglas Gregord51d90d2010-04-26 20:11:03 +00007436 // If nothing changed, just retain the existing expression.
7437 if (!getDerived().AlwaysRebuild() &&
7438 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007439 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007440
John McCallb268a282010-08-23 23:25:46 +00007441 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007442 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007443}
7444
Mike Stump11289f42009-09-09 15:08:12 +00007445template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007446ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007447TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007448 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007449 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007450 SubExprs.reserve(E->getNumSubExprs());
7451 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7452 SubExprs, &ArgumentChanged))
7453 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007454
Douglas Gregora16548e2009-08-11 05:31:07 +00007455 if (!getDerived().AlwaysRebuild() &&
7456 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007457 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007458
Douglas Gregora16548e2009-08-11 05:31:07 +00007459 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7460 move_arg(SubExprs),
7461 E->getRParenLoc());
7462}
7463
Mike Stump11289f42009-09-09 15:08:12 +00007464template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007465ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007466TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007467 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007468
John McCall490112f2011-02-04 18:33:18 +00007469 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7470 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7471
7472 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7473 llvm::SmallVector<ParmVarDecl*, 4> params;
7474 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007475
7476 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007477 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7478 oldBlock->param_begin(),
7479 oldBlock->param_size(),
7480 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007481 return true;
John McCall490112f2011-02-04 18:33:18 +00007482
7483 const FunctionType *exprFunctionType = E->getFunctionType();
7484 QualType exprResultType = exprFunctionType->getResultType();
7485 if (!exprResultType.isNull()) {
7486 if (!exprResultType->isDependentType())
7487 blockScope->ReturnType = exprResultType;
7488 else if (exprResultType != getSema().Context.DependentTy)
7489 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007490 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007491
7492 // If the return type has not been determined yet, leave it as a dependent
7493 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007494 if (blockScope->ReturnType.isNull())
7495 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007496
7497 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007498 if (blockScope->ReturnType->isObjCObjectType()) {
7499 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007500 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007501 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007502 return ExprError();
7503 }
John McCall3882ace2011-01-05 12:14:39 +00007504
John McCall490112f2011-02-04 18:33:18 +00007505 QualType functionType = getDerived().RebuildFunctionProtoType(
7506 blockScope->ReturnType,
7507 paramTypes.data(),
7508 paramTypes.size(),
7509 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007510 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007511 exprFunctionType->getExtInfo());
7512 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007513
7514 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007515 if (!params.empty())
7516 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007517
7518 // If the return type wasn't explicitly set, it will have been marked as a
7519 // dependent type (DependentTy); clear out the return type setting so
7520 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007521 if (blockScope->ReturnType == getSema().Context.DependentTy)
7522 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007523
John McCall3882ace2011-01-05 12:14:39 +00007524 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007525 StmtResult body = getDerived().TransformStmt(E->getBody());
7526 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007527 return ExprError();
7528
John McCall490112f2011-02-04 18:33:18 +00007529#ifndef NDEBUG
7530 // In builds with assertions, make sure that we captured everything we
7531 // captured before.
7532
7533 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7534
7535 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7536 e = oldBlock->capture_end(); i != e; ++i) {
John McCall351762c2011-02-07 10:33:21 +00007537 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007538
7539 // Ignore parameter packs.
7540 if (isa<ParmVarDecl>(oldCapture) &&
7541 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7542 continue;
7543
7544 VarDecl *newCapture =
7545 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7546 oldCapture));
John McCall351762c2011-02-07 10:33:21 +00007547 assert(blockScope->CaptureMap.count(newCapture));
John McCall490112f2011-02-04 18:33:18 +00007548 }
7549#endif
7550
7551 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7552 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007553}
7554
Mike Stump11289f42009-09-09 15:08:12 +00007555template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007556ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007557TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007558 NestedNameSpecifier *Qualifier = 0;
7559
7560 ValueDecl *ND
7561 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7562 E->getDecl()));
7563 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007564 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007565
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007566 if (!getDerived().AlwaysRebuild() &&
7567 ND == E->getDecl()) {
7568 // Mark it referenced in the new context regardless.
7569 // FIXME: this is a bit instantiation-specific.
7570 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7571
John McCallc3007a22010-10-26 07:05:15 +00007572 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007573 }
7574
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007575 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007576 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007577 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007578}
Mike Stump11289f42009-09-09 15:08:12 +00007579
Douglas Gregora16548e2009-08-11 05:31:07 +00007580//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007581// Type reconstruction
7582//===----------------------------------------------------------------------===//
7583
Mike Stump11289f42009-09-09 15:08:12 +00007584template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007585QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7586 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007587 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007588 getDerived().getBaseEntity());
7589}
7590
Mike Stump11289f42009-09-09 15:08:12 +00007591template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007592QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7593 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007594 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007595 getDerived().getBaseEntity());
7596}
7597
Mike Stump11289f42009-09-09 15:08:12 +00007598template<typename Derived>
7599QualType
John McCall70dd5f62009-10-30 00:06:24 +00007600TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7601 bool WrittenAsLValue,
7602 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007603 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007604 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007605}
7606
7607template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007608QualType
John McCall70dd5f62009-10-30 00:06:24 +00007609TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7610 QualType ClassType,
7611 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007612 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007613 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007614}
7615
7616template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007617QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007618TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7619 ArrayType::ArraySizeModifier SizeMod,
7620 const llvm::APInt *Size,
7621 Expr *SizeExpr,
7622 unsigned IndexTypeQuals,
7623 SourceRange BracketsRange) {
7624 if (SizeExpr || !Size)
7625 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7626 IndexTypeQuals, BracketsRange,
7627 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007628
7629 QualType Types[] = {
7630 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7631 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7632 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007633 };
7634 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7635 QualType SizeType;
7636 for (unsigned I = 0; I != NumTypes; ++I)
7637 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7638 SizeType = Types[I];
7639 break;
7640 }
Mike Stump11289f42009-09-09 15:08:12 +00007641
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007642 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7643 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007644 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007645 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007646 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007647}
Mike Stump11289f42009-09-09 15:08:12 +00007648
Douglas Gregord6ff3322009-08-04 16:50:30 +00007649template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007650QualType
7651TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007652 ArrayType::ArraySizeModifier SizeMod,
7653 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007654 unsigned IndexTypeQuals,
7655 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007656 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007657 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007658}
7659
7660template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007661QualType
Mike Stump11289f42009-09-09 15:08:12 +00007662TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007663 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007664 unsigned IndexTypeQuals,
7665 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007666 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007667 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007668}
Mike Stump11289f42009-09-09 15:08:12 +00007669
Douglas Gregord6ff3322009-08-04 16:50:30 +00007670template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007671QualType
7672TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007673 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007674 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007675 unsigned IndexTypeQuals,
7676 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007677 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007678 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007679 IndexTypeQuals, BracketsRange);
7680}
7681
7682template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007683QualType
7684TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007685 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007686 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007687 unsigned IndexTypeQuals,
7688 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007689 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007690 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007691 IndexTypeQuals, BracketsRange);
7692}
7693
7694template<typename Derived>
7695QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007696 unsigned NumElements,
7697 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007698 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007699 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007700}
Mike Stump11289f42009-09-09 15:08:12 +00007701
Douglas Gregord6ff3322009-08-04 16:50:30 +00007702template<typename Derived>
7703QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7704 unsigned NumElements,
7705 SourceLocation AttributeLoc) {
7706 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7707 NumElements, true);
7708 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007709 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7710 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007711 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007712}
Mike Stump11289f42009-09-09 15:08:12 +00007713
Douglas Gregord6ff3322009-08-04 16:50:30 +00007714template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007715QualType
7716TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007717 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007718 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007719 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007720}
Mike Stump11289f42009-09-09 15:08:12 +00007721
Douglas Gregord6ff3322009-08-04 16:50:30 +00007722template<typename Derived>
7723QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007724 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007725 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007726 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007727 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007728 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00007729 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007730 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007731 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007732 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007733 getDerived().getBaseEntity(),
7734 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007735}
Mike Stump11289f42009-09-09 15:08:12 +00007736
Douglas Gregord6ff3322009-08-04 16:50:30 +00007737template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007738QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7739 return SemaRef.Context.getFunctionNoProtoType(T);
7740}
7741
7742template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007743QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7744 assert(D && "no decl found");
7745 if (D->isInvalidDecl()) return QualType();
7746
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007747 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007748 TypeDecl *Ty;
7749 if (isa<UsingDecl>(D)) {
7750 UsingDecl *Using = cast<UsingDecl>(D);
7751 assert(Using->isTypeName() &&
7752 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7753
7754 // A valid resolved using typename decl points to exactly one type decl.
7755 assert(++Using->shadow_begin() == Using->shadow_end());
7756 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007757
John McCallb96ec562009-12-04 22:46:56 +00007758 } else {
7759 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7760 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7761 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7762 }
7763
7764 return SemaRef.Context.getTypeDeclType(Ty);
7765}
7766
7767template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007768QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7769 SourceLocation Loc) {
7770 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007771}
7772
7773template<typename Derived>
7774QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7775 return SemaRef.Context.getTypeOfType(Underlying);
7776}
7777
7778template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007779QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7780 SourceLocation Loc) {
7781 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007782}
7783
7784template<typename Derived>
7785QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007786 TemplateName Template,
7787 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00007788 const TemplateArgumentListInfo &TemplateArgs) {
7789 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007790}
Mike Stump11289f42009-09-09 15:08:12 +00007791
Douglas Gregor1135c352009-08-06 05:28:30 +00007792template<typename Derived>
7793NestedNameSpecifier *
7794TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7795 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007796 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007797 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00007798 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00007799 CXXScopeSpec SS;
7800 // FIXME: The source location information is all wrong.
Douglas Gregor869ad452011-02-24 17:54:50 +00007801 SS.MakeTrivial(SemaRef.Context, Prefix, Range);
Douglas Gregor90c99722011-02-24 00:17:56 +00007802 if (SemaRef.BuildCXXNestedNameSpecifier(0, II, /*FIXME:*/Range.getBegin(),
7803 /*FIXME:*/Range.getEnd(),
7804 ObjectType, false,
7805 SS, FirstQualifierInScope,
7806 false))
7807 return 0;
7808
7809 return SS.getScopeRep();
Douglas Gregor1135c352009-08-06 05:28:30 +00007810}
7811
7812template<typename Derived>
7813NestedNameSpecifier *
7814TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7815 SourceRange Range,
7816 NamespaceDecl *NS) {
7817 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7818}
7819
7820template<typename Derived>
7821NestedNameSpecifier *
7822TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7823 SourceRange Range,
Douglas Gregor7b26ff92011-02-24 02:36:08 +00007824 NamespaceAliasDecl *Alias) {
7825 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, Alias);
7826}
7827
7828template<typename Derived>
7829NestedNameSpecifier *
7830TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7831 SourceRange Range,
Douglas Gregor1135c352009-08-06 05:28:30 +00007832 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00007833 QualType T) {
7834 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00007835 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00007836 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00007837 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7838 T.getTypePtr());
7839 }
Mike Stump11289f42009-09-09 15:08:12 +00007840
Douglas Gregor1135c352009-08-06 05:28:30 +00007841 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7842 return 0;
7843}
Mike Stump11289f42009-09-09 15:08:12 +00007844
Douglas Gregor71dc5092009-08-06 06:41:21 +00007845template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007846TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007847TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7848 bool TemplateKW,
7849 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00007850 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007851 Template);
7852}
7853
7854template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007855TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007856TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00007857 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00007858 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00007859 QualType ObjectType,
7860 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00007861 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +00007862 SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange);
Douglas Gregor3cf81312009-11-03 23:16:33 +00007863 UnqualifiedId Name;
7864 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00007865 Sema::TemplateTy Template;
7866 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7867 /*FIXME:*/getDerived().getBaseLocation(),
7868 SS,
7869 Name,
John McCallba7bf592010-08-24 05:47:05 +00007870 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007871 /*EnteringContext=*/false,
7872 Template);
John McCall31f82722010-11-12 08:19:04 +00007873 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007874}
Mike Stump11289f42009-09-09 15:08:12 +00007875
Douglas Gregora16548e2009-08-11 05:31:07 +00007876template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007877TemplateName
7878TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7879 OverloadedOperatorKind Operator,
7880 QualType ObjectType) {
7881 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +00007882 SS.MakeTrivial(SemaRef.Context, Qualifier, SourceRange(getDerived().getBaseLocation()));
Douglas Gregor71395fa2009-11-04 00:56:37 +00007883 UnqualifiedId Name;
7884 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7885 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7886 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007887 Sema::TemplateTy Template;
7888 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007889 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007890 SS,
7891 Name,
John McCallba7bf592010-08-24 05:47:05 +00007892 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007893 /*EnteringContext=*/false,
7894 Template);
7895 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007896}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007897
Douglas Gregor71395fa2009-11-04 00:56:37 +00007898template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007899ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007900TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7901 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007902 Expr *OrigCallee,
7903 Expr *First,
7904 Expr *Second) {
7905 Expr *Callee = OrigCallee->IgnoreParenCasts();
7906 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007907
Douglas Gregora16548e2009-08-11 05:31:07 +00007908 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007909 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007910 if (!First->getType()->isOverloadableType() &&
7911 !Second->getType()->isOverloadableType())
7912 return getSema().CreateBuiltinArraySubscriptExpr(First,
7913 Callee->getLocStart(),
7914 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007915 } else if (Op == OO_Arrow) {
7916 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007917 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7918 } else if (Second == 0 || isPostIncDec) {
7919 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007920 // The argument is not of overloadable type, so try to create a
7921 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007922 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007923 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007924
John McCallb268a282010-08-23 23:25:46 +00007925 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007926 }
7927 } else {
John McCallb268a282010-08-23 23:25:46 +00007928 if (!First->getType()->isOverloadableType() &&
7929 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007930 // Neither of the arguments is an overloadable type, so try to
7931 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007932 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007933 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007934 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007935 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007936 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007937
Douglas Gregora16548e2009-08-11 05:31:07 +00007938 return move(Result);
7939 }
7940 }
Mike Stump11289f42009-09-09 15:08:12 +00007941
7942 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007943 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007944 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007945
John McCallb268a282010-08-23 23:25:46 +00007946 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007947 assert(ULE->requiresADL());
7948
7949 // FIXME: Do we have to check
7950 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007951 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007952 } else {
John McCallb268a282010-08-23 23:25:46 +00007953 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007954 }
Mike Stump11289f42009-09-09 15:08:12 +00007955
Douglas Gregora16548e2009-08-11 05:31:07 +00007956 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007957 Expr *Args[2] = { First, Second };
7958 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007959
Douglas Gregora16548e2009-08-11 05:31:07 +00007960 // Create the overloaded operator invocation for unary operators.
7961 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007962 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007963 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007964 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007965 }
Mike Stump11289f42009-09-09 15:08:12 +00007966
Sebastian Redladba46e2009-10-29 20:17:01 +00007967 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007968 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007969 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007970 First,
7971 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007972
Douglas Gregora16548e2009-08-11 05:31:07 +00007973 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007974 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007975 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007976 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7977 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007978 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007979
Mike Stump11289f42009-09-09 15:08:12 +00007980 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007981}
Mike Stump11289f42009-09-09 15:08:12 +00007982
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007983template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007984ExprResult
John McCallb268a282010-08-23 23:25:46 +00007985TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007986 SourceLocation OperatorLoc,
7987 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00007988 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007989 TypeSourceInfo *ScopeType,
7990 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007991 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007992 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00007993 QualType BaseType = Base->getType();
7994 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007995 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007996 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007997 !BaseType->getAs<PointerType>()->getPointeeType()
7998 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007999 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00008000 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008001 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008002 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008003 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008004 /*FIXME?*/true);
8005 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008006
Douglas Gregor678f90d2010-02-25 01:56:36 +00008007 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008008 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8009 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8010 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8011 NameInfo.setNamedTypeInfo(DestroyedType);
8012
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008013 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008014
John McCallb268a282010-08-23 23:25:46 +00008015 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008016 OperatorLoc, isArrow,
8017 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008018 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008019 /*TemplateArgs*/ 0);
8020}
8021
Douglas Gregord6ff3322009-08-04 16:50:30 +00008022} // end namespace clang
8023
8024#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H