blob: d0de1df650723ef5afe6e904c2c267f41bfec530 [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.
Douglas Gregorea972d32011-02-28 21:54:11 +00001267 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001268 ValueDecl *VD,
1269 const DeclarationNameInfo &NameInfo,
1270 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001271 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001272 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001273
1274 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001275
1276 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001277 }
Mike Stump11289f42009-09-09 15:08:12 +00001278
Douglas Gregora16548e2009-08-11 05:31:07 +00001279 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001280 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001281 /// By default, performs semantic analysis to build the new expression.
1282 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001283 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001284 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001285 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001286 }
1287
Douglas Gregorad8a3362009-09-04 17:36:40 +00001288 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001289 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001290 /// By default, performs semantic analysis to build the new expression.
1291 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001292 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001293 SourceLocation OperatorLoc,
1294 bool isArrow,
1295 CXXScopeSpec &SS,
1296 TypeSourceInfo *ScopeType,
1297 SourceLocation CCLoc,
1298 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001299 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001300
Douglas Gregora16548e2009-08-11 05:31:07 +00001301 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001302 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001303 /// By default, performs semantic analysis to build the new expression.
1304 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001305 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001306 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001307 Expr *SubExpr) {
1308 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001309 }
Mike Stump11289f42009-09-09 15:08:12 +00001310
Douglas Gregor882211c2010-04-28 22:16:22 +00001311 /// \brief Build a new builtin offsetof expression.
1312 ///
1313 /// By default, performs semantic analysis to build the new expression.
1314 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001315 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001316 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001317 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001318 unsigned NumComponents,
1319 SourceLocation RParenLoc) {
1320 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1321 NumComponents, RParenLoc);
1322 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001323
Douglas Gregora16548e2009-08-11 05:31:07 +00001324 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001325 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001326 /// By default, performs semantic analysis to build the new expression.
1327 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001328 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001329 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001330 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001331 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 }
1333
Mike Stump11289f42009-09-09 15:08:12 +00001334 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001335 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001336 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001337 /// By default, performs semantic analysis to build the new expression.
1338 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001339 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001340 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001341 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001342 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001343 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001344 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001345
Douglas Gregora16548e2009-08-11 05:31:07 +00001346 return move(Result);
1347 }
Mike Stump11289f42009-09-09 15:08:12 +00001348
Douglas Gregora16548e2009-08-11 05:31:07 +00001349 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001350 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001351 /// By default, performs semantic analysis to build the new expression.
1352 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001353 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001354 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001355 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001356 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001357 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1358 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001359 RBracketLoc);
1360 }
1361
1362 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001363 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001364 /// By default, performs semantic analysis to build the new expression.
1365 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001366 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001367 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001368 SourceLocation RParenLoc,
1369 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001370 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001371 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001372 }
1373
1374 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001375 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001376 /// By default, performs semantic analysis to build the new expression.
1377 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001378 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001379 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001380 NestedNameSpecifierLoc QualifierLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001381 const DeclarationNameInfo &MemberNameInfo,
1382 ValueDecl *Member,
1383 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001384 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001385 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001386 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001387 // We have a reference to an unnamed field. This is always the
1388 // base of an anonymous struct/union member access, i.e. the
1389 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001390 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001391 assert(Member->getType()->isRecordType() &&
1392 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001393
Douglas Gregorea972d32011-02-28 21:54:11 +00001394 if (getSema().PerformObjectMemberConversion(Base,
1395 QualifierLoc.getNestedNameSpecifier(),
John McCall16df1e52010-03-30 21:47:33 +00001396 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001397 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001398
John McCall7decc9e2010-11-18 06:31:45 +00001399 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001400 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001401 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001402 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001403 cast<FieldDecl>(Member)->getType(),
1404 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001405 return getSema().Owned(ME);
1406 }
Mike Stump11289f42009-09-09 15:08:12 +00001407
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001408 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001409 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001410
John McCallb268a282010-08-23 23:25:46 +00001411 getSema().DefaultFunctionArrayConversion(Base);
1412 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001413
John McCall16df1e52010-03-30 21:47:33 +00001414 // FIXME: this involves duplicating earlier analysis in a lot of
1415 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001416 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001417 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001418 R.resolveKind();
1419
John McCallb268a282010-08-23 23:25:46 +00001420 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001421 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001422 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001423 }
Mike Stump11289f42009-09-09 15:08:12 +00001424
Douglas Gregora16548e2009-08-11 05:31:07 +00001425 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001426 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001427 /// By default, performs semantic analysis to build the new expression.
1428 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001429 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001430 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001431 Expr *LHS, Expr *RHS) {
1432 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001433 }
1434
1435 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001436 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001437 /// By default, performs semantic analysis to build the new expression.
1438 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001439 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001440 SourceLocation QuestionLoc,
1441 Expr *LHS,
1442 SourceLocation ColonLoc,
1443 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001444 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1445 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001446 }
1447
Douglas Gregora16548e2009-08-11 05:31:07 +00001448 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001449 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001450 /// By default, performs semantic analysis to build the new expression.
1451 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001452 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001453 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001454 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001455 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001456 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001457 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001458 }
Mike Stump11289f42009-09-09 15:08:12 +00001459
Douglas Gregora16548e2009-08-11 05:31:07 +00001460 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001461 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001462 /// By default, performs semantic analysis to build the new expression.
1463 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001464 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001465 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001466 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001467 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001468 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001469 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001470 }
Mike Stump11289f42009-09-09 15:08:12 +00001471
Douglas Gregora16548e2009-08-11 05:31:07 +00001472 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001473 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001474 /// By default, performs semantic analysis to build the new expression.
1475 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001476 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001477 SourceLocation OpLoc,
1478 SourceLocation AccessorLoc,
1479 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001480
John McCall10eae182009-11-30 22:42:35 +00001481 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001482 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001483 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001484 OpLoc, /*IsArrow*/ false,
1485 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001486 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001487 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001488 }
Mike Stump11289f42009-09-09 15:08:12 +00001489
Douglas Gregora16548e2009-08-11 05:31:07 +00001490 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001491 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 /// By default, performs semantic analysis to build the new expression.
1493 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001494 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001495 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001496 SourceLocation RBraceLoc,
1497 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001498 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001499 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1500 if (Result.isInvalid() || ResultTy->isDependentType())
1501 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001502
Douglas Gregord3d93062009-11-09 17:16:50 +00001503 // Patch in the result type we were given, which may have been computed
1504 // when the initial InitListExpr was built.
1505 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1506 ILE->setType(ResultTy);
1507 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001508 }
Mike Stump11289f42009-09-09 15:08:12 +00001509
Douglas Gregora16548e2009-08-11 05:31:07 +00001510 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001511 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001512 /// By default, performs semantic analysis to build the new expression.
1513 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001514 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001515 MultiExprArg ArrayExprs,
1516 SourceLocation EqualOrColonLoc,
1517 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001518 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001519 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001520 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001521 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001523 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001524
Douglas Gregora16548e2009-08-11 05:31:07 +00001525 ArrayExprs.release();
1526 return move(Result);
1527 }
Mike Stump11289f42009-09-09 15:08:12 +00001528
Douglas Gregora16548e2009-08-11 05:31:07 +00001529 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001530 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001531 /// By default, builds the implicit value initialization without performing
1532 /// any semantic analysis. Subclasses may override this routine to provide
1533 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001534 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001535 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1536 }
Mike Stump11289f42009-09-09 15:08:12 +00001537
Douglas Gregora16548e2009-08-11 05:31:07 +00001538 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001539 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001540 /// By default, performs semantic analysis to build the new expression.
1541 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001542 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001543 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001544 SourceLocation RParenLoc) {
1545 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001546 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001547 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001548 }
1549
1550 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001551 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001552 /// By default, performs semantic analysis to build the new expression.
1553 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001554 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001555 MultiExprArg SubExprs,
1556 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001557 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001558 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001559 }
Mike Stump11289f42009-09-09 15:08:12 +00001560
Douglas Gregora16548e2009-08-11 05:31:07 +00001561 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001562 ///
1563 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001564 /// rather than attempting to map the label statement itself.
1565 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001566 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001567 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001568 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001569 }
Mike Stump11289f42009-09-09 15:08:12 +00001570
Douglas Gregora16548e2009-08-11 05:31:07 +00001571 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001572 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001573 /// By default, performs semantic analysis to build the new expression.
1574 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001575 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001576 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001577 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001578 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001579 }
Mike Stump11289f42009-09-09 15:08:12 +00001580
Douglas Gregora16548e2009-08-11 05:31:07 +00001581 /// \brief Build a new __builtin_choose_expr expression.
1582 ///
1583 /// By default, performs semantic analysis to build the new expression.
1584 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001585 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001586 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001587 SourceLocation RParenLoc) {
1588 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001589 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001590 RParenLoc);
1591 }
Mike Stump11289f42009-09-09 15:08:12 +00001592
Douglas Gregora16548e2009-08-11 05:31:07 +00001593 /// \brief Build a new overloaded operator call expression.
1594 ///
1595 /// By default, performs semantic analysis to build the new expression.
1596 /// The semantic analysis provides the behavior of template instantiation,
1597 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001598 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001599 /// argument-dependent lookup, etc. Subclasses may override this routine to
1600 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001601 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001602 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001603 Expr *Callee,
1604 Expr *First,
1605 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001606
1607 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001608 /// reinterpret_cast.
1609 ///
1610 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001611 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001612 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001613 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001614 Stmt::StmtClass Class,
1615 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001616 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001617 SourceLocation RAngleLoc,
1618 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001619 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001620 SourceLocation RParenLoc) {
1621 switch (Class) {
1622 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001623 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001624 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001625 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001626
1627 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001628 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001629 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001630 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001631
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001633 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001634 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001635 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001636 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001637
Douglas Gregora16548e2009-08-11 05:31:07 +00001638 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001639 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001640 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001641 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001642
Douglas Gregora16548e2009-08-11 05:31:07 +00001643 default:
1644 assert(false && "Invalid C++ named cast");
1645 break;
1646 }
Mike Stump11289f42009-09-09 15:08:12 +00001647
John McCallfaf5fb42010-08-26 23:41:50 +00001648 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001649 }
Mike Stump11289f42009-09-09 15:08:12 +00001650
Douglas Gregora16548e2009-08-11 05:31:07 +00001651 /// \brief Build a new C++ static_cast expression.
1652 ///
1653 /// By default, performs semantic analysis to build the new expression.
1654 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001655 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001656 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001657 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 SourceLocation RAngleLoc,
1659 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001660 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001661 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001662 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001663 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001664 SourceRange(LAngleLoc, RAngleLoc),
1665 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001666 }
1667
1668 /// \brief Build a new C++ dynamic_cast expression.
1669 ///
1670 /// By default, performs semantic analysis to build the new expression.
1671 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001672 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001673 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001674 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001675 SourceLocation RAngleLoc,
1676 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001677 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001678 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001679 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001680 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001681 SourceRange(LAngleLoc, RAngleLoc),
1682 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001683 }
1684
1685 /// \brief Build a new C++ reinterpret_cast expression.
1686 ///
1687 /// By default, performs semantic analysis to build the new expression.
1688 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001689 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001690 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001691 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001692 SourceLocation RAngleLoc,
1693 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001694 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001695 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001696 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001697 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001698 SourceRange(LAngleLoc, RAngleLoc),
1699 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001700 }
1701
1702 /// \brief Build a new C++ const_cast expression.
1703 ///
1704 /// By default, performs semantic analysis to build the new expression.
1705 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001706 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001707 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001708 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001709 SourceLocation RAngleLoc,
1710 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001711 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001712 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001713 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001714 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001715 SourceRange(LAngleLoc, RAngleLoc),
1716 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001717 }
Mike Stump11289f42009-09-09 15:08:12 +00001718
Douglas Gregora16548e2009-08-11 05:31:07 +00001719 /// \brief Build a new C++ functional-style cast expression.
1720 ///
1721 /// By default, performs semantic analysis to build the new expression.
1722 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001723 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1724 SourceLocation LParenLoc,
1725 Expr *Sub,
1726 SourceLocation RParenLoc) {
1727 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001728 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001729 RParenLoc);
1730 }
Mike Stump11289f42009-09-09 15:08:12 +00001731
Douglas Gregora16548e2009-08-11 05:31:07 +00001732 /// \brief Build a new C++ typeid(type) expression.
1733 ///
1734 /// By default, performs semantic analysis to build the new expression.
1735 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001736 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001737 SourceLocation TypeidLoc,
1738 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001739 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001740 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001741 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001742 }
Mike Stump11289f42009-09-09 15:08:12 +00001743
Francois Pichet9f4f2072010-09-08 12:20:18 +00001744
Douglas Gregora16548e2009-08-11 05:31:07 +00001745 /// \brief Build a new C++ typeid(expr) expression.
1746 ///
1747 /// By default, performs semantic analysis to build the new expression.
1748 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001749 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001750 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001751 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001752 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001753 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001754 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001755 }
1756
Francois Pichet9f4f2072010-09-08 12:20:18 +00001757 /// \brief Build a new C++ __uuidof(type) expression.
1758 ///
1759 /// By default, performs semantic analysis to build the new expression.
1760 /// Subclasses may override this routine to provide different behavior.
1761 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1762 SourceLocation TypeidLoc,
1763 TypeSourceInfo *Operand,
1764 SourceLocation RParenLoc) {
1765 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1766 RParenLoc);
1767 }
1768
1769 /// \brief Build a new C++ __uuidof(expr) expression.
1770 ///
1771 /// By default, performs semantic analysis to build the new expression.
1772 /// Subclasses may override this routine to provide different behavior.
1773 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1774 SourceLocation TypeidLoc,
1775 Expr *Operand,
1776 SourceLocation RParenLoc) {
1777 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1778 RParenLoc);
1779 }
1780
Douglas Gregora16548e2009-08-11 05:31:07 +00001781 /// \brief Build a new C++ "this" expression.
1782 ///
1783 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001784 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001785 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001786 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001787 QualType ThisType,
1788 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001789 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001790 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1791 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001792 }
1793
1794 /// \brief Build a new C++ throw expression.
1795 ///
1796 /// By default, performs semantic analysis to build the new expression.
1797 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001798 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001799 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001800 }
1801
1802 /// \brief Build a new C++ default-argument expression.
1803 ///
1804 /// By default, builds a new default-argument expression, which does not
1805 /// require any semantic analysis. Subclasses may override this routine to
1806 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001807 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001808 ParmVarDecl *Param) {
1809 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1810 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001811 }
1812
1813 /// \brief Build a new C++ zero-initialization expression.
1814 ///
1815 /// By default, performs semantic analysis to build the new expression.
1816 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001817 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1818 SourceLocation LParenLoc,
1819 SourceLocation RParenLoc) {
1820 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001821 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001822 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001823 }
Mike Stump11289f42009-09-09 15:08:12 +00001824
Douglas Gregora16548e2009-08-11 05:31:07 +00001825 /// \brief Build a new C++ "new" expression.
1826 ///
1827 /// By default, performs semantic analysis to build the new expression.
1828 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001829 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001830 bool UseGlobal,
1831 SourceLocation PlacementLParen,
1832 MultiExprArg PlacementArgs,
1833 SourceLocation PlacementRParen,
1834 SourceRange TypeIdParens,
1835 QualType AllocatedType,
1836 TypeSourceInfo *AllocatedTypeInfo,
1837 Expr *ArraySize,
1838 SourceLocation ConstructorLParen,
1839 MultiExprArg ConstructorArgs,
1840 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001841 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001842 PlacementLParen,
1843 move(PlacementArgs),
1844 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001845 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001846 AllocatedType,
1847 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001848 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001849 ConstructorLParen,
1850 move(ConstructorArgs),
1851 ConstructorRParen);
1852 }
Mike Stump11289f42009-09-09 15:08:12 +00001853
Douglas Gregora16548e2009-08-11 05:31:07 +00001854 /// \brief Build a new C++ "delete" expression.
1855 ///
1856 /// By default, performs semantic analysis to build the new expression.
1857 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001858 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001859 bool IsGlobalDelete,
1860 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001861 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001862 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001863 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001864 }
Mike Stump11289f42009-09-09 15:08:12 +00001865
Douglas Gregora16548e2009-08-11 05:31:07 +00001866 /// \brief Build a new unary type trait expression.
1867 ///
1868 /// By default, performs semantic analysis to build the new expression.
1869 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001870 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001871 SourceLocation StartLoc,
1872 TypeSourceInfo *T,
1873 SourceLocation RParenLoc) {
1874 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001875 }
1876
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001877 /// \brief Build a new binary type trait expression.
1878 ///
1879 /// By default, performs semantic analysis to build the new expression.
1880 /// Subclasses may override this routine to provide different behavior.
1881 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1882 SourceLocation StartLoc,
1883 TypeSourceInfo *LhsT,
1884 TypeSourceInfo *RhsT,
1885 SourceLocation RParenLoc) {
1886 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1887 }
1888
Mike Stump11289f42009-09-09 15:08:12 +00001889 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001890 /// expression.
1891 ///
1892 /// By default, performs semantic analysis to build the new expression.
1893 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001894 ExprResult RebuildDependentScopeDeclRefExpr(
1895 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001896 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001897 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001898 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00001899 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00001900
1901 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001902 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001903 *TemplateArgs);
1904
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001905 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001906 }
1907
1908 /// \brief Build a new template-id expression.
1909 ///
1910 /// By default, performs semantic analysis to build the new expression.
1911 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001912 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001913 LookupResult &R,
1914 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001915 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001916 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001917 }
1918
1919 /// \brief Build a new object-construction expression.
1920 ///
1921 /// By default, performs semantic analysis to build the new expression.
1922 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001923 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001924 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001925 CXXConstructorDecl *Constructor,
1926 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001927 MultiExprArg Args,
1928 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001929 CXXConstructExpr::ConstructionKind ConstructKind,
1930 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001931 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001932 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001933 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001934 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001935
Douglas Gregordb121ba2009-12-14 16:27:04 +00001936 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001937 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001938 RequiresZeroInit, ConstructKind,
1939 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 }
1941
1942 /// \brief Build a new object-construction expression.
1943 ///
1944 /// By default, performs semantic analysis to build the new expression.
1945 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001946 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1947 SourceLocation LParenLoc,
1948 MultiExprArg Args,
1949 SourceLocation RParenLoc) {
1950 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001951 LParenLoc,
1952 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001953 RParenLoc);
1954 }
1955
1956 /// \brief Build a new object-construction expression.
1957 ///
1958 /// By default, performs semantic analysis to build the new expression.
1959 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001960 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1961 SourceLocation LParenLoc,
1962 MultiExprArg Args,
1963 SourceLocation RParenLoc) {
1964 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001965 LParenLoc,
1966 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001967 RParenLoc);
1968 }
Mike Stump11289f42009-09-09 15:08:12 +00001969
Douglas Gregora16548e2009-08-11 05:31:07 +00001970 /// \brief Build a new member reference expression.
1971 ///
1972 /// By default, performs semantic analysis to build the new expression.
1973 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001974 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00001975 QualType BaseType,
1976 bool IsArrow,
1977 SourceLocation OperatorLoc,
1978 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00001979 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001980 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001981 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001982 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00001983 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001984
John McCallb268a282010-08-23 23:25:46 +00001985 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001986 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001987 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001988 MemberNameInfo,
1989 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001990 }
1991
John McCall10eae182009-11-30 22:42:35 +00001992 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001993 ///
1994 /// By default, performs semantic analysis to build the new expression.
1995 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001996 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001997 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001998 SourceLocation OperatorLoc,
1999 bool IsArrow,
Douglas Gregor0da1d432011-02-28 20:01:57 +00002000 NestedNameSpecifierLoc QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00002001 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00002002 LookupResult &R,
2003 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002004 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002005 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002006
John McCallb268a282010-08-23 23:25:46 +00002007 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002008 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00002009 SS, FirstQualifierInScope,
2010 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002011 }
Mike Stump11289f42009-09-09 15:08:12 +00002012
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002013 /// \brief Build a new noexcept expression.
2014 ///
2015 /// By default, performs semantic analysis to build the new expression.
2016 /// Subclasses may override this routine to provide different behavior.
2017 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2018 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2019 }
2020
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002021 /// \brief Build a new expression to compute the length of a parameter pack.
2022 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2023 SourceLocation PackLoc,
2024 SourceLocation RParenLoc,
2025 unsigned Length) {
2026 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2027 OperatorLoc, Pack, PackLoc,
2028 RParenLoc, Length);
2029 }
2030
Douglas Gregora16548e2009-08-11 05:31:07 +00002031 /// \brief Build a new Objective-C @encode expression.
2032 ///
2033 /// By default, performs semantic analysis to build the new expression.
2034 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002035 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002036 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002037 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002038 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002039 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002040 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002041
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002042 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002043 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002044 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002045 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002046 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002047 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002048 MultiExprArg Args,
2049 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002050 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2051 ReceiverTypeInfo->getType(),
2052 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002053 Sel, Method, LBracLoc, SelectorLoc,
2054 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002055 }
2056
2057 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002058 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002059 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002060 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002061 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002062 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002063 MultiExprArg Args,
2064 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002065 return SemaRef.BuildInstanceMessage(Receiver,
2066 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002067 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002068 Sel, Method, LBracLoc, SelectorLoc,
2069 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002070 }
2071
Douglas Gregord51d90d2010-04-26 20:11:03 +00002072 /// \brief Build a new Objective-C ivar reference expression.
2073 ///
2074 /// By default, performs semantic analysis to build the new expression.
2075 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002076 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002077 SourceLocation IvarLoc,
2078 bool IsArrow, bool IsFreeIvar) {
2079 // FIXME: We lose track of the IsFreeIvar bit.
2080 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002081 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002082 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2083 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002084 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002085 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002086 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002087 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002088 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002089 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002090
Douglas Gregord51d90d2010-04-26 20:11:03 +00002091 if (Result.get())
2092 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002093
John McCallb268a282010-08-23 23:25:46 +00002094 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002095 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002096 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002097 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002098 /*TemplateArgs=*/0);
2099 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002100
2101 /// \brief Build a new Objective-C property reference expression.
2102 ///
2103 /// By default, performs semantic analysis to build the new expression.
2104 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002105 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002106 ObjCPropertyDecl *Property,
2107 SourceLocation PropertyLoc) {
2108 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002109 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00002110 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2111 Sema::LookupMemberName);
2112 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002113 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002114 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002115 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00002116 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002117 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002118
Douglas Gregor9faee212010-04-26 20:47:02 +00002119 if (Result.get())
2120 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002121
John McCallb268a282010-08-23 23:25:46 +00002122 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002123 /*FIXME:*/PropertyLoc, IsArrow,
2124 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002125 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002126 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002127 /*TemplateArgs=*/0);
2128 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002129
John McCallb7bd14f2010-12-02 01:19:52 +00002130 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002131 ///
2132 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002133 /// Subclasses may override this routine to provide different behavior.
2134 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2135 ObjCMethodDecl *Getter,
2136 ObjCMethodDecl *Setter,
2137 SourceLocation PropertyLoc) {
2138 // Since these expressions can only be value-dependent, we do not
2139 // need to perform semantic analysis again.
2140 return Owned(
2141 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2142 VK_LValue, OK_ObjCProperty,
2143 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002144 }
2145
Douglas Gregord51d90d2010-04-26 20:11:03 +00002146 /// \brief Build a new Objective-C "isa" expression.
2147 ///
2148 /// By default, performs semantic analysis to build the new expression.
2149 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002150 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002151 bool IsArrow) {
2152 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002153 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002154 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2155 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002156 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002157 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002158 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002159 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002160 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002161
Douglas Gregord51d90d2010-04-26 20:11:03 +00002162 if (Result.get())
2163 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002164
John McCallb268a282010-08-23 23:25:46 +00002165 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002166 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002167 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002168 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002169 /*TemplateArgs=*/0);
2170 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002171
Douglas Gregora16548e2009-08-11 05:31:07 +00002172 /// \brief Build a new shuffle vector expression.
2173 ///
2174 /// By default, performs semantic analysis to build the new expression.
2175 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002176 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002177 MultiExprArg SubExprs,
2178 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002179 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002180 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002181 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2182 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2183 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2184 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002185
Douglas Gregora16548e2009-08-11 05:31:07 +00002186 // Build a reference to the __builtin_shufflevector builtin
2187 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00002188 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00002189 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00002190 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002191 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002192
2193 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002194 unsigned NumSubExprs = SubExprs.size();
2195 Expr **Subs = (Expr **)SubExprs.release();
2196 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2197 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002198 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002199 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002200 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002201 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002202
Douglas Gregora16548e2009-08-11 05:31:07 +00002203 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002204 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002205 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002206 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002207
Douglas Gregora16548e2009-08-11 05:31:07 +00002208 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002209 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002210 }
John McCall31f82722010-11-12 08:19:04 +00002211
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002212 /// \brief Build a new template argument pack expansion.
2213 ///
2214 /// By default, performs semantic analysis to build a new pack expansion
2215 /// for a template argument. Subclasses may override this routine to provide
2216 /// different behavior.
2217 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002218 SourceLocation EllipsisLoc,
2219 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002220 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002221 case TemplateArgument::Expression: {
2222 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002223 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2224 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002225 if (Result.isInvalid())
2226 return TemplateArgumentLoc();
2227
2228 return TemplateArgumentLoc(Result.get(), Result.get());
2229 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002230
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002231 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002232 return TemplateArgumentLoc(TemplateArgument(
2233 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002234 NumExpansions),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002235 Pattern.getTemplateQualifierRange(),
2236 Pattern.getTemplateNameLoc(),
2237 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002238
2239 case TemplateArgument::Null:
2240 case TemplateArgument::Integral:
2241 case TemplateArgument::Declaration:
2242 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002243 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002244 llvm_unreachable("Pack expansion pattern has no parameter packs");
2245
2246 case TemplateArgument::Type:
2247 if (TypeSourceInfo *Expansion
2248 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002249 EllipsisLoc,
2250 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002251 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2252 Expansion);
2253 break;
2254 }
2255
2256 return TemplateArgumentLoc();
2257 }
2258
Douglas Gregor968f23a2011-01-03 19:31:53 +00002259 /// \brief Build a new expression pack expansion.
2260 ///
2261 /// By default, performs semantic analysis to build a new pack expansion
2262 /// for an expression. Subclasses may override this routine to provide
2263 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002264 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2265 llvm::Optional<unsigned> NumExpansions) {
2266 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002267 }
2268
John McCall31f82722010-11-12 08:19:04 +00002269private:
2270 QualType TransformTypeInObjectScope(QualType T,
2271 QualType ObjectType,
2272 NamedDecl *FirstQualifierInScope,
2273 NestedNameSpecifier *Prefix);
2274
2275 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2276 QualType ObjectType,
2277 NamedDecl *FirstQualifierInScope,
2278 NestedNameSpecifier *Prefix);
Douglas Gregor14454802011-02-25 02:25:35 +00002279
2280 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2281 QualType ObjectType,
2282 NamedDecl *FirstQualifierInScope,
2283 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002284};
Douglas Gregora16548e2009-08-11 05:31:07 +00002285
Douglas Gregorebe10102009-08-20 07:17:43 +00002286template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002287StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002288 if (!S)
2289 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002290
Douglas Gregorebe10102009-08-20 07:17:43 +00002291 switch (S->getStmtClass()) {
2292 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002293
Douglas Gregorebe10102009-08-20 07:17:43 +00002294 // Transform individual statement nodes
2295#define STMT(Node, Parent) \
2296 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002297#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002298#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002299#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002300
Douglas Gregorebe10102009-08-20 07:17:43 +00002301 // Transform expressions by calling TransformExpr.
2302#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002303#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002304#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002305#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002306 {
John McCalldadc5752010-08-24 06:29:42 +00002307 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002308 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002309 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002310
John McCallb268a282010-08-23 23:25:46 +00002311 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002312 }
Mike Stump11289f42009-09-09 15:08:12 +00002313 }
2314
John McCallc3007a22010-10-26 07:05:15 +00002315 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002316}
Mike Stump11289f42009-09-09 15:08:12 +00002317
2318
Douglas Gregore922c772009-08-04 22:27:00 +00002319template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002320ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002321 if (!E)
2322 return SemaRef.Owned(E);
2323
2324 switch (E->getStmtClass()) {
2325 case Stmt::NoStmtClass: break;
2326#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002327#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002328#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002329 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002330#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002331 }
2332
John McCallc3007a22010-10-26 07:05:15 +00002333 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002334}
2335
2336template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002337bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2338 unsigned NumInputs,
2339 bool IsCall,
2340 llvm::SmallVectorImpl<Expr *> &Outputs,
2341 bool *ArgChanged) {
2342 for (unsigned I = 0; I != NumInputs; ++I) {
2343 // If requested, drop call arguments that need to be dropped.
2344 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2345 if (ArgChanged)
2346 *ArgChanged = true;
2347
2348 break;
2349 }
2350
Douglas Gregor968f23a2011-01-03 19:31:53 +00002351 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2352 Expr *Pattern = Expansion->getPattern();
2353
2354 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2355 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2356 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2357
2358 // Determine whether the set of unexpanded parameter packs can and should
2359 // be expanded.
2360 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002361 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002362 llvm::Optional<unsigned> OrigNumExpansions
2363 = Expansion->getNumExpansions();
2364 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002365 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2366 Pattern->getSourceRange(),
2367 Unexpanded.data(),
2368 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002369 Expand, RetainExpansion,
2370 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002371 return true;
2372
2373 if (!Expand) {
2374 // The transform has determined that we should perform a simple
2375 // transformation on the pack expansion, producing another pack
2376 // expansion.
2377 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2378 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2379 if (OutPattern.isInvalid())
2380 return true;
2381
2382 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002383 Expansion->getEllipsisLoc(),
2384 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002385 if (Out.isInvalid())
2386 return true;
2387
2388 if (ArgChanged)
2389 *ArgChanged = true;
2390 Outputs.push_back(Out.get());
2391 continue;
2392 }
2393
2394 // The transform has determined that we should perform an elementwise
2395 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002396 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002397 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2398 ExprResult Out = getDerived().TransformExpr(Pattern);
2399 if (Out.isInvalid())
2400 return true;
2401
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002402 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002403 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2404 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002405 if (Out.isInvalid())
2406 return true;
2407 }
2408
Douglas Gregor968f23a2011-01-03 19:31:53 +00002409 if (ArgChanged)
2410 *ArgChanged = true;
2411 Outputs.push_back(Out.get());
2412 }
2413
2414 continue;
2415 }
2416
Douglas Gregora3efea12011-01-03 19:04:46 +00002417 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2418 if (Result.isInvalid())
2419 return true;
2420
2421 if (Result.get() != Inputs[I] && ArgChanged)
2422 *ArgChanged = true;
2423
2424 Outputs.push_back(Result.get());
2425 }
2426
2427 return false;
2428}
2429
2430template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002431NestedNameSpecifier *
2432TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002433 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002434 QualType ObjectType,
2435 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002436 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002437
Douglas Gregorebe10102009-08-20 07:17:43 +00002438 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002439 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002440 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002441 ObjectType,
2442 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002443 if (!Prefix)
2444 return 0;
2445 }
Mike Stump11289f42009-09-09 15:08:12 +00002446
Douglas Gregor1135c352009-08-06 05:28:30 +00002447 switch (NNS->getKind()) {
2448 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002449 if (Prefix) {
2450 // The object type and qualifier-in-scope really apply to the
2451 // leftmost entity.
2452 ObjectType = QualType();
2453 FirstQualifierInScope = 0;
2454 }
2455
Mike Stump11289f42009-09-09 15:08:12 +00002456 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002457 "Identifier nested-name-specifier with no prefix or object type");
2458 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2459 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002460 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002461
2462 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002463 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002464 ObjectType,
2465 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002466
Douglas Gregor1135c352009-08-06 05:28:30 +00002467 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002468 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002469 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002470 getDerived().TransformDecl(Range.getBegin(),
2471 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002472 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002473 Prefix == NNS->getPrefix() &&
2474 NS == NNS->getAsNamespace())
2475 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002476
Douglas Gregor1135c352009-08-06 05:28:30 +00002477 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2478 }
Mike Stump11289f42009-09-09 15:08:12 +00002479
Douglas Gregor7b26ff92011-02-24 02:36:08 +00002480 case NestedNameSpecifier::NamespaceAlias: {
2481 NamespaceAliasDecl *Alias
2482 = cast_or_null<NamespaceAliasDecl>(
2483 getDerived().TransformDecl(Range.getBegin(),
2484 NNS->getAsNamespaceAlias()));
2485 if (!getDerived().AlwaysRebuild() &&
2486 Prefix == NNS->getPrefix() &&
2487 Alias == NNS->getAsNamespaceAlias())
2488 return NNS;
2489
2490 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, Alias);
2491 }
2492
Douglas Gregor1135c352009-08-06 05:28:30 +00002493 case NestedNameSpecifier::Global:
2494 // There is no meaningful transformation that one could perform on the
2495 // global scope.
2496 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002497
Douglas Gregor1135c352009-08-06 05:28:30 +00002498 case NestedNameSpecifier::TypeSpecWithTemplate:
2499 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002500 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002501 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2502 ObjectType,
2503 FirstQualifierInScope,
2504 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002505 if (T.isNull())
2506 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002507
Douglas Gregor1135c352009-08-06 05:28:30 +00002508 if (!getDerived().AlwaysRebuild() &&
2509 Prefix == NNS->getPrefix() &&
2510 T == QualType(NNS->getAsType(), 0))
2511 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002512
2513 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2514 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002515 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002516 }
2517 }
Mike Stump11289f42009-09-09 15:08:12 +00002518
Douglas Gregor1135c352009-08-06 05:28:30 +00002519 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002520 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002521}
2522
2523template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002524NestedNameSpecifierLoc
2525TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2526 NestedNameSpecifierLoc NNS,
2527 QualType ObjectType,
2528 NamedDecl *FirstQualifierInScope) {
2529 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2530 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2531 Qualifier = Qualifier.getPrefix())
2532 Qualifiers.push_back(Qualifier);
2533
2534 CXXScopeSpec SS;
2535 while (!Qualifiers.empty()) {
2536 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2537 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2538
2539 switch (QNNS->getKind()) {
2540 case NestedNameSpecifier::Identifier:
2541 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2542 *QNNS->getAsIdentifier(),
2543 Q.getLocalBeginLoc(),
2544 Q.getLocalEndLoc(),
2545 ObjectType, false, SS,
2546 FirstQualifierInScope, false))
2547 return NestedNameSpecifierLoc();
2548
2549 break;
2550
2551 case NestedNameSpecifier::Namespace: {
2552 NamespaceDecl *NS
2553 = cast_or_null<NamespaceDecl>(
2554 getDerived().TransformDecl(
2555 Q.getLocalBeginLoc(),
2556 QNNS->getAsNamespace()));
2557 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2558 break;
2559 }
2560
2561 case NestedNameSpecifier::NamespaceAlias: {
2562 NamespaceAliasDecl *Alias
2563 = cast_or_null<NamespaceAliasDecl>(
2564 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2565 QNNS->getAsNamespaceAlias()));
2566 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2567 Q.getLocalEndLoc());
2568 break;
2569 }
2570
2571 case NestedNameSpecifier::Global:
2572 // There is no meaningful transformation that one could perform on the
2573 // global scope.
2574 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2575 break;
2576
2577 case NestedNameSpecifier::TypeSpecWithTemplate:
2578 case NestedNameSpecifier::TypeSpec: {
2579 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2580 FirstQualifierInScope, SS);
2581
2582 if (!TL)
2583 return NestedNameSpecifierLoc();
2584
2585 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2586 (SemaRef.getLangOptions().CPlusPlus0x &&
2587 TL.getType()->isEnumeralType())) {
2588 assert(!TL.getType().hasLocalQualifiers() &&
2589 "Can't get cv-qualifiers here");
2590 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2591 Q.getLocalEndLoc());
2592 break;
2593 }
2594
2595 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2596 << TL.getType() << SS.getRange();
2597 return NestedNameSpecifierLoc();
2598 }
Douglas Gregore16af532011-02-28 18:50:33 +00002599 }
Douglas Gregor14454802011-02-25 02:25:35 +00002600
Douglas Gregore16af532011-02-28 18:50:33 +00002601 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002602 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002603 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002604 }
2605
2606 // Don't rebuild the nested-name-specifier if we don't have to.
2607 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2608 !getDerived().AlwaysRebuild())
2609 return NNS;
2610
2611 // If we can re-use the source-location data from the original
2612 // nested-name-specifier, do so.
2613 if (SS.location_size() == NNS.getDataLength() &&
2614 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2615 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2616
2617 // Allocate new nested-name-specifier location information.
2618 return SS.getWithLocInContext(SemaRef.Context);
2619}
2620
2621template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002622DeclarationNameInfo
2623TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002624::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002625 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002626 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002627 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002628
2629 switch (Name.getNameKind()) {
2630 case DeclarationName::Identifier:
2631 case DeclarationName::ObjCZeroArgSelector:
2632 case DeclarationName::ObjCOneArgSelector:
2633 case DeclarationName::ObjCMultiArgSelector:
2634 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002635 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002636 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002637 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002638
Douglas Gregorf816bd72009-09-03 22:13:48 +00002639 case DeclarationName::CXXConstructorName:
2640 case DeclarationName::CXXDestructorName:
2641 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002642 TypeSourceInfo *NewTInfo;
2643 CanQualType NewCanTy;
2644 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002645 NewTInfo = getDerived().TransformType(OldTInfo);
2646 if (!NewTInfo)
2647 return DeclarationNameInfo();
2648 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002649 }
2650 else {
2651 NewTInfo = 0;
2652 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002653 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002654 if (NewT.isNull())
2655 return DeclarationNameInfo();
2656 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2657 }
Mike Stump11289f42009-09-09 15:08:12 +00002658
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002659 DeclarationName NewName
2660 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2661 NewCanTy);
2662 DeclarationNameInfo NewNameInfo(NameInfo);
2663 NewNameInfo.setName(NewName);
2664 NewNameInfo.setNamedTypeInfo(NewTInfo);
2665 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002666 }
Mike Stump11289f42009-09-09 15:08:12 +00002667 }
2668
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002669 assert(0 && "Unknown name kind.");
2670 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002671}
2672
2673template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002674TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002675TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002676 QualType ObjectType,
2677 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002678 SourceLocation Loc = getDerived().getBaseLocation();
2679
Douglas Gregor71dc5092009-08-06 06:41:21 +00002680 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002681 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002682 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002683 /*FIXME*/ SourceRange(Loc),
2684 ObjectType,
2685 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002686 if (!NNS)
2687 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002688
Douglas Gregor71dc5092009-08-06 06:41:21 +00002689 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002690 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002691 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002692 if (!TransTemplate)
2693 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002694
Douglas Gregor71dc5092009-08-06 06:41:21 +00002695 if (!getDerived().AlwaysRebuild() &&
2696 NNS == QTN->getQualifier() &&
2697 TransTemplate == Template)
2698 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002699
Douglas Gregor71dc5092009-08-06 06:41:21 +00002700 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2701 TransTemplate);
2702 }
Mike Stump11289f42009-09-09 15:08:12 +00002703
John McCalle66edc12009-11-24 19:00:30 +00002704 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002705 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002706 }
Mike Stump11289f42009-09-09 15:08:12 +00002707
Douglas Gregor71dc5092009-08-06 06:41:21 +00002708 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002709 NestedNameSpecifier *NNS = DTN->getQualifier();
2710 if (NNS) {
2711 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2712 /*FIXME:*/SourceRange(Loc),
2713 ObjectType,
2714 FirstQualifierInScope);
2715 if (!NNS) return TemplateName();
2716
2717 // These apply to the scope specifier, not the template.
2718 ObjectType = QualType();
2719 FirstQualifierInScope = 0;
2720 }
Mike Stump11289f42009-09-09 15:08:12 +00002721
Douglas Gregor71dc5092009-08-06 06:41:21 +00002722 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002723 NNS == DTN->getQualifier() &&
2724 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002725 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002726
Douglas Gregora5614c52010-09-08 23:56:00 +00002727 if (DTN->isIdentifier()) {
2728 // FIXME: Bad range
2729 SourceRange QualifierRange(getDerived().getBaseLocation());
2730 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2731 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002732 ObjectType,
2733 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002734 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002735
2736 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002737 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002738 }
Mike Stump11289f42009-09-09 15:08:12 +00002739
Douglas Gregor71dc5092009-08-06 06:41:21 +00002740 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002741 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002742 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002743 if (!TransTemplate)
2744 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002745
Douglas Gregor71dc5092009-08-06 06:41:21 +00002746 if (!getDerived().AlwaysRebuild() &&
2747 TransTemplate == Template)
2748 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002749
Douglas Gregor71dc5092009-08-06 06:41:21 +00002750 return TemplateName(TransTemplate);
2751 }
Mike Stump11289f42009-09-09 15:08:12 +00002752
Douglas Gregor5590be02011-01-15 06:45:20 +00002753 if (SubstTemplateTemplateParmPackStorage *SubstPack
2754 = Name.getAsSubstTemplateTemplateParmPack()) {
2755 TemplateTemplateParmDecl *TransParam
2756 = cast_or_null<TemplateTemplateParmDecl>(
2757 getDerived().TransformDecl(Loc, SubstPack->getParameterPack()));
2758 if (!TransParam)
2759 return TemplateName();
2760
2761 if (!getDerived().AlwaysRebuild() &&
2762 TransParam == SubstPack->getParameterPack())
2763 return Name;
2764
2765 return getDerived().RebuildTemplateName(TransParam,
2766 SubstPack->getArgumentPack());
2767 }
2768
John McCalle66edc12009-11-24 19:00:30 +00002769 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002770 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002771 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002772}
2773
2774template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002775void TreeTransform<Derived>::InventTemplateArgumentLoc(
2776 const TemplateArgument &Arg,
2777 TemplateArgumentLoc &Output) {
2778 SourceLocation Loc = getDerived().getBaseLocation();
2779 switch (Arg.getKind()) {
2780 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002781 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002782 break;
2783
2784 case TemplateArgument::Type:
2785 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002786 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002787
John McCall0ad16662009-10-29 08:12:44 +00002788 break;
2789
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002790 case TemplateArgument::Template:
2791 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2792 break;
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002793
2794 case TemplateArgument::TemplateExpansion:
2795 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2796 break;
2797
John McCall0ad16662009-10-29 08:12:44 +00002798 case TemplateArgument::Expression:
2799 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2800 break;
2801
2802 case TemplateArgument::Declaration:
2803 case TemplateArgument::Integral:
2804 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002805 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002806 break;
2807 }
2808}
2809
2810template<typename Derived>
2811bool TreeTransform<Derived>::TransformTemplateArgument(
2812 const TemplateArgumentLoc &Input,
2813 TemplateArgumentLoc &Output) {
2814 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002815 switch (Arg.getKind()) {
2816 case TemplateArgument::Null:
2817 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002818 Output = Input;
2819 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002820
Douglas Gregore922c772009-08-04 22:27:00 +00002821 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002822 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002823 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002824 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002825
2826 DI = getDerived().TransformType(DI);
2827 if (!DI) return true;
2828
2829 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2830 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002831 }
Mike Stump11289f42009-09-09 15:08:12 +00002832
Douglas Gregore922c772009-08-04 22:27:00 +00002833 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002834 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002835 DeclarationName Name;
2836 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2837 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002838 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002839 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002840 if (!D) return true;
2841
John McCall0d07eb32009-10-29 18:45:58 +00002842 Expr *SourceExpr = Input.getSourceDeclExpression();
2843 if (SourceExpr) {
2844 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002845 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002846 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002847 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002848 }
2849
2850 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002851 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002852 }
Mike Stump11289f42009-09-09 15:08:12 +00002853
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002854 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002855 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002856 TemplateName Template
2857 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2858 if (Template.isNull())
2859 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002860
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002861 Output = TemplateArgumentLoc(TemplateArgument(Template),
2862 Input.getTemplateQualifierRange(),
2863 Input.getTemplateNameLoc());
2864 return false;
2865 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002866
2867 case TemplateArgument::TemplateExpansion:
2868 llvm_unreachable("Caller should expand pack expansions");
2869
Douglas Gregore922c772009-08-04 22:27:00 +00002870 case TemplateArgument::Expression: {
2871 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002872 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002873 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002874
John McCall0ad16662009-10-29 08:12:44 +00002875 Expr *InputExpr = Input.getSourceExpression();
2876 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2877
John McCalldadc5752010-08-24 06:29:42 +00002878 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002879 = getDerived().TransformExpr(InputExpr);
2880 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002881 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002882 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002883 }
Mike Stump11289f42009-09-09 15:08:12 +00002884
Douglas Gregore922c772009-08-04 22:27:00 +00002885 case TemplateArgument::Pack: {
2886 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2887 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002888 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002889 AEnd = Arg.pack_end();
2890 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002891
John McCall0ad16662009-10-29 08:12:44 +00002892 // FIXME: preserve source information here when we start
2893 // caring about parameter packs.
2894
John McCall0d07eb32009-10-29 18:45:58 +00002895 TemplateArgumentLoc InputArg;
2896 TemplateArgumentLoc OutputArg;
2897 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2898 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002899 return true;
2900
John McCall0d07eb32009-10-29 18:45:58 +00002901 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002902 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002903
2904 TemplateArgument *TransformedArgsPtr
2905 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2906 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2907 TransformedArgsPtr);
2908 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2909 TransformedArgs.size()),
2910 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002911 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002912 }
2913 }
Mike Stump11289f42009-09-09 15:08:12 +00002914
Douglas Gregore922c772009-08-04 22:27:00 +00002915 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002916 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002917}
2918
Douglas Gregorfe921a72010-12-20 23:36:19 +00002919/// \brief Iterator adaptor that invents template argument location information
2920/// for each of the template arguments in its underlying iterator.
2921template<typename Derived, typename InputIterator>
2922class TemplateArgumentLocInventIterator {
2923 TreeTransform<Derived> &Self;
2924 InputIterator Iter;
2925
2926public:
2927 typedef TemplateArgumentLoc value_type;
2928 typedef TemplateArgumentLoc reference;
2929 typedef typename std::iterator_traits<InputIterator>::difference_type
2930 difference_type;
2931 typedef std::input_iterator_tag iterator_category;
2932
2933 class pointer {
2934 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002935
Douglas Gregorfe921a72010-12-20 23:36:19 +00002936 public:
2937 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2938
2939 const TemplateArgumentLoc *operator->() const { return &Arg; }
2940 };
2941
2942 TemplateArgumentLocInventIterator() { }
2943
2944 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2945 InputIterator Iter)
2946 : Self(Self), Iter(Iter) { }
2947
2948 TemplateArgumentLocInventIterator &operator++() {
2949 ++Iter;
2950 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002951 }
2952
Douglas Gregorfe921a72010-12-20 23:36:19 +00002953 TemplateArgumentLocInventIterator operator++(int) {
2954 TemplateArgumentLocInventIterator Old(*this);
2955 ++(*this);
2956 return Old;
2957 }
2958
2959 reference operator*() const {
2960 TemplateArgumentLoc Result;
2961 Self.InventTemplateArgumentLoc(*Iter, Result);
2962 return Result;
2963 }
2964
2965 pointer operator->() const { return pointer(**this); }
2966
2967 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2968 const TemplateArgumentLocInventIterator &Y) {
2969 return X.Iter == Y.Iter;
2970 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002971
Douglas Gregorfe921a72010-12-20 23:36:19 +00002972 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2973 const TemplateArgumentLocInventIterator &Y) {
2974 return X.Iter != Y.Iter;
2975 }
2976};
2977
Douglas Gregor42cafa82010-12-20 17:42:22 +00002978template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002979template<typename InputIterator>
2980bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2981 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002982 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002983 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002984 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002985 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002986
2987 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2988 // Unpack argument packs, which we translate them into separate
2989 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002990 // FIXME: We could do much better if we could guarantee that the
2991 // TemplateArgumentLocInfo for the pack expansion would be usable for
2992 // all of the template arguments in the argument pack.
2993 typedef TemplateArgumentLocInventIterator<Derived,
2994 TemplateArgument::pack_iterator>
2995 PackLocIterator;
2996 if (TransformTemplateArguments(PackLocIterator(*this,
2997 In.getArgument().pack_begin()),
2998 PackLocIterator(*this,
2999 In.getArgument().pack_end()),
3000 Outputs))
3001 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003002
3003 continue;
3004 }
3005
3006 if (In.getArgument().isPackExpansion()) {
3007 // We have a pack expansion, for which we will be substituting into
3008 // the pattern.
3009 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003010 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003011 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003012 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3013 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003014
3015 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3016 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3017 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3018
3019 // Determine whether the set of unexpanded parameter packs can and should
3020 // be expanded.
3021 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003022 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003023 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003024 if (getDerived().TryExpandParameterPacks(Ellipsis,
3025 Pattern.getSourceRange(),
3026 Unexpanded.data(),
3027 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003028 Expand,
3029 RetainExpansion,
3030 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003031 return true;
3032
3033 if (!Expand) {
3034 // The transform has determined that we should perform a simple
3035 // transformation on the pack expansion, producing another pack
3036 // expansion.
3037 TemplateArgumentLoc OutPattern;
3038 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3039 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3040 return true;
3041
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003042 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3043 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003044 if (Out.getArgument().isNull())
3045 return true;
3046
3047 Outputs.addArgument(Out);
3048 continue;
3049 }
3050
3051 // The transform has determined that we should perform an elementwise
3052 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003053 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003054 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3055
3056 if (getDerived().TransformTemplateArgument(Pattern, Out))
3057 return true;
3058
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003059 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003060 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3061 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003062 if (Out.getArgument().isNull())
3063 return true;
3064 }
3065
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003066 Outputs.addArgument(Out);
3067 }
3068
Douglas Gregor48d24112011-01-10 20:53:55 +00003069 // If we're supposed to retain a pack expansion, do so by temporarily
3070 // forgetting the partially-substituted parameter pack.
3071 if (RetainExpansion) {
3072 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3073
3074 if (getDerived().TransformTemplateArgument(Pattern, Out))
3075 return true;
3076
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003077 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3078 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003079 if (Out.getArgument().isNull())
3080 return true;
3081
3082 Outputs.addArgument(Out);
3083 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003084
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003085 continue;
3086 }
3087
3088 // The simple case:
3089 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003090 return true;
3091
3092 Outputs.addArgument(Out);
3093 }
3094
3095 return false;
3096
3097}
3098
Douglas Gregord6ff3322009-08-04 16:50:30 +00003099//===----------------------------------------------------------------------===//
3100// Type transformation
3101//===----------------------------------------------------------------------===//
3102
3103template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003104QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003105 if (getDerived().AlreadyTransformed(T))
3106 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003107
John McCall550e0c22009-10-21 00:40:46 +00003108 // Temporary workaround. All of these transformations should
3109 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003110 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3111 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003112
John McCall31f82722010-11-12 08:19:04 +00003113 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003114
John McCall550e0c22009-10-21 00:40:46 +00003115 if (!NewDI)
3116 return QualType();
3117
3118 return NewDI->getType();
3119}
3120
3121template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003122TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003123 if (getDerived().AlreadyTransformed(DI->getType()))
3124 return DI;
3125
3126 TypeLocBuilder TLB;
3127
3128 TypeLoc TL = DI->getTypeLoc();
3129 TLB.reserve(TL.getFullDataSize());
3130
John McCall31f82722010-11-12 08:19:04 +00003131 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003132 if (Result.isNull())
3133 return 0;
3134
John McCallbcd03502009-12-07 02:54:59 +00003135 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003136}
3137
3138template<typename Derived>
3139QualType
John McCall31f82722010-11-12 08:19:04 +00003140TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003141 switch (T.getTypeLocClass()) {
3142#define ABSTRACT_TYPELOC(CLASS, PARENT)
3143#define TYPELOC(CLASS, PARENT) \
3144 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003145 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003146#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003147 }
Mike Stump11289f42009-09-09 15:08:12 +00003148
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003149 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003150 return QualType();
3151}
3152
3153/// FIXME: By default, this routine adds type qualifiers only to types
3154/// that can have qualifiers, and silently suppresses those qualifiers
3155/// that are not permitted (e.g., qualifiers on reference or function
3156/// types). This is the right thing for template instantiation, but
3157/// probably not for other clients.
3158template<typename Derived>
3159QualType
3160TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003161 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003162 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003163
John McCall31f82722010-11-12 08:19:04 +00003164 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003165 if (Result.isNull())
3166 return QualType();
3167
3168 // Silently suppress qualifiers if the result type can't be qualified.
3169 // FIXME: this is the right thing for template instantiation, but
3170 // probably not for other clients.
3171 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003172 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003173
John McCallcb0f89a2010-06-05 06:41:15 +00003174 if (!Quals.empty()) {
3175 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3176 TLB.push<QualifiedTypeLoc>(Result);
3177 // No location information to preserve.
3178 }
John McCall550e0c22009-10-21 00:40:46 +00003179
3180 return Result;
3181}
3182
John McCall31f82722010-11-12 08:19:04 +00003183/// \brief Transforms a type that was written in a scope specifier,
3184/// given an object type, the results of unqualified lookup, and
3185/// an already-instantiated prefix.
3186///
3187/// The object type is provided iff the scope specifier qualifies the
3188/// member of a dependent member-access expression. The prefix is
3189/// provided iff the the scope specifier in which this appears has a
3190/// prefix.
3191///
3192/// This is private to TreeTransform.
3193template<typename Derived>
3194QualType
3195TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
3196 QualType ObjectType,
3197 NamedDecl *UnqualLookup,
3198 NestedNameSpecifier *Prefix) {
3199 if (getDerived().AlreadyTransformed(T))
3200 return T;
3201
3202 TypeSourceInfo *TSI =
Douglas Gregor2d525f02011-01-25 19:13:18 +00003203 SemaRef.Context.getTrivialTypeSourceInfo(T, getDerived().getBaseLocation());
John McCall31f82722010-11-12 08:19:04 +00003204
3205 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
3206 UnqualLookup, Prefix);
3207 if (!TSI) return QualType();
3208 return TSI->getType();
3209}
3210
3211template<typename Derived>
3212TypeSourceInfo *
3213TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
3214 QualType ObjectType,
3215 NamedDecl *UnqualLookup,
3216 NestedNameSpecifier *Prefix) {
Douglas Gregor14454802011-02-25 02:25:35 +00003217 // TODO: in some cases, we might have some verification to do here.
John McCall31f82722010-11-12 08:19:04 +00003218 if (ObjectType.isNull())
3219 return getDerived().TransformType(TSI);
3220
3221 QualType T = TSI->getType();
3222 if (getDerived().AlreadyTransformed(T))
3223 return TSI;
3224
3225 TypeLocBuilder TLB;
3226 QualType Result;
3227
3228 if (isa<TemplateSpecializationType>(T)) {
3229 TemplateSpecializationTypeLoc TL
3230 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3231
3232 TemplateName Template =
3233 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
3234 ObjectType, UnqualLookup);
3235 if (Template.isNull()) return 0;
3236
3237 Result = getDerived()
3238 .TransformTemplateSpecializationType(TLB, TL, Template);
3239 } else if (isa<DependentTemplateSpecializationType>(T)) {
3240 DependentTemplateSpecializationTypeLoc TL
3241 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3242
Douglas Gregor5a064722011-02-28 17:23:35 +00003243 TemplateName Template
3244 = SemaRef.Context.getDependentTemplateName(
3245 TL.getTypePtr()->getQualifier(),
3246 TL.getTypePtr()->getIdentifier());
3247
3248 Template = getDerived().TransformTemplateName(Template, ObjectType,
3249 UnqualLookup);
3250 if (Template.isNull())
3251 return 0;
3252
3253 Result = getDerived().TransformDependentTemplateSpecializationType(TLB, TL,
3254 Template);
John McCall31f82722010-11-12 08:19:04 +00003255 } else {
3256 // Nothing special needs to be done for these.
3257 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
3258 }
3259
3260 if (Result.isNull()) return 0;
3261 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3262}
3263
Douglas Gregor14454802011-02-25 02:25:35 +00003264template<typename Derived>
3265TypeLoc
3266TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3267 QualType ObjectType,
3268 NamedDecl *UnqualLookup,
3269 CXXScopeSpec &SS) {
3270 // FIXME: Painfully copy-paste from the above!
3271
Douglas Gregor14454802011-02-25 02:25:35 +00003272 QualType T = TL.getType();
3273 if (getDerived().AlreadyTransformed(T))
3274 return TL;
3275
3276 TypeLocBuilder TLB;
3277 QualType Result;
3278
3279 if (isa<TemplateSpecializationType>(T)) {
3280 TemplateSpecializationTypeLoc SpecTL
3281 = cast<TemplateSpecializationTypeLoc>(TL);
3282
3283 TemplateName Template =
3284 getDerived().TransformTemplateName(SpecTL.getTypePtr()->getTemplateName(),
3285 ObjectType, UnqualLookup);
3286 if (Template.isNull())
3287 return TypeLoc();
3288
3289 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3290 Template);
3291 } else if (isa<DependentTemplateSpecializationType>(T)) {
3292 DependentTemplateSpecializationTypeLoc SpecTL
3293 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3294
Douglas Gregor5a064722011-02-28 17:23:35 +00003295 TemplateName Template
Douglas Gregore16af532011-02-28 18:50:33 +00003296 = getDerived().RebuildTemplateName(SS.getScopeRep(), SS.getRange(),
3297 *SpecTL.getTypePtr()->getIdentifier(),
3298 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003299 if (Template.isNull())
3300 return TypeLoc();
3301
Douglas Gregor14454802011-02-25 02:25:35 +00003302 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003303 SpecTL,
3304 Template);
Douglas Gregor14454802011-02-25 02:25:35 +00003305 } else {
3306 // Nothing special needs to be done for these.
3307 Result = getDerived().TransformType(TLB, TL);
3308 }
3309
3310 if (Result.isNull())
3311 return TypeLoc();
3312
3313 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3314}
3315
John McCall550e0c22009-10-21 00:40:46 +00003316template <class TyLoc> static inline
3317QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3318 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3319 NewT.setNameLoc(T.getNameLoc());
3320 return T.getType();
3321}
3322
John McCall550e0c22009-10-21 00:40:46 +00003323template<typename Derived>
3324QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003325 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003326 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3327 NewT.setBuiltinLoc(T.getBuiltinLoc());
3328 if (T.needsExtraLocalData())
3329 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3330 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003331}
Mike Stump11289f42009-09-09 15:08:12 +00003332
Douglas Gregord6ff3322009-08-04 16:50:30 +00003333template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003334QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003335 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003336 // FIXME: recurse?
3337 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003338}
Mike Stump11289f42009-09-09 15:08:12 +00003339
Douglas Gregord6ff3322009-08-04 16:50:30 +00003340template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003341QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003342 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003343 QualType PointeeType
3344 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003345 if (PointeeType.isNull())
3346 return QualType();
3347
3348 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003349 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003350 // A dependent pointer type 'T *' has is being transformed such
3351 // that an Objective-C class type is being replaced for 'T'. The
3352 // resulting pointer type is an ObjCObjectPointerType, not a
3353 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003354 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003355
John McCall8b07ec22010-05-15 11:32:37 +00003356 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3357 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003358 return Result;
3359 }
John McCall31f82722010-11-12 08:19:04 +00003360
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003361 if (getDerived().AlwaysRebuild() ||
3362 PointeeType != TL.getPointeeLoc().getType()) {
3363 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3364 if (Result.isNull())
3365 return QualType();
3366 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003367
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003368 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3369 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003370 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003371}
Mike Stump11289f42009-09-09 15:08:12 +00003372
3373template<typename Derived>
3374QualType
John McCall550e0c22009-10-21 00:40:46 +00003375TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003376 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003377 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003378 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3379 if (PointeeType.isNull())
3380 return QualType();
3381
3382 QualType Result = TL.getType();
3383 if (getDerived().AlwaysRebuild() ||
3384 PointeeType != TL.getPointeeLoc().getType()) {
3385 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003386 TL.getSigilLoc());
3387 if (Result.isNull())
3388 return QualType();
3389 }
3390
Douglas Gregor049211a2010-04-22 16:50:51 +00003391 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003392 NewT.setSigilLoc(TL.getSigilLoc());
3393 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003394}
3395
John McCall70dd5f62009-10-30 00:06:24 +00003396/// Transforms a reference type. Note that somewhat paradoxically we
3397/// don't care whether the type itself is an l-value type or an r-value
3398/// type; we only care if the type was *written* as an l-value type
3399/// or an r-value type.
3400template<typename Derived>
3401QualType
3402TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003403 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003404 const ReferenceType *T = TL.getTypePtr();
3405
3406 // Note that this works with the pointee-as-written.
3407 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3408 if (PointeeType.isNull())
3409 return QualType();
3410
3411 QualType Result = TL.getType();
3412 if (getDerived().AlwaysRebuild() ||
3413 PointeeType != T->getPointeeTypeAsWritten()) {
3414 Result = getDerived().RebuildReferenceType(PointeeType,
3415 T->isSpelledAsLValue(),
3416 TL.getSigilLoc());
3417 if (Result.isNull())
3418 return QualType();
3419 }
3420
3421 // r-value references can be rebuilt as l-value references.
3422 ReferenceTypeLoc NewTL;
3423 if (isa<LValueReferenceType>(Result))
3424 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3425 else
3426 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3427 NewTL.setSigilLoc(TL.getSigilLoc());
3428
3429 return Result;
3430}
3431
Mike Stump11289f42009-09-09 15:08:12 +00003432template<typename Derived>
3433QualType
John McCall550e0c22009-10-21 00:40:46 +00003434TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003435 LValueReferenceTypeLoc TL) {
3436 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003437}
3438
Mike Stump11289f42009-09-09 15:08:12 +00003439template<typename Derived>
3440QualType
John McCall550e0c22009-10-21 00:40:46 +00003441TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003442 RValueReferenceTypeLoc TL) {
3443 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003444}
Mike Stump11289f42009-09-09 15:08:12 +00003445
Douglas Gregord6ff3322009-08-04 16:50:30 +00003446template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003447QualType
John McCall550e0c22009-10-21 00:40:46 +00003448TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003449 MemberPointerTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003450 const MemberPointerType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003451
3452 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003453 if (PointeeType.isNull())
3454 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003455
John McCall550e0c22009-10-21 00:40:46 +00003456 // TODO: preserve source information for this.
3457 QualType ClassType
3458 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003459 if (ClassType.isNull())
3460 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003461
John McCall550e0c22009-10-21 00:40:46 +00003462 QualType Result = TL.getType();
3463 if (getDerived().AlwaysRebuild() ||
3464 PointeeType != T->getPointeeType() ||
3465 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00003466 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3467 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003468 if (Result.isNull())
3469 return QualType();
3470 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003471
John McCall550e0c22009-10-21 00:40:46 +00003472 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3473 NewTL.setSigilLoc(TL.getSigilLoc());
3474
3475 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003476}
3477
Mike Stump11289f42009-09-09 15:08:12 +00003478template<typename Derived>
3479QualType
John McCall550e0c22009-10-21 00:40:46 +00003480TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003481 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003482 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003483 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003484 if (ElementType.isNull())
3485 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003486
John McCall550e0c22009-10-21 00:40:46 +00003487 QualType Result = TL.getType();
3488 if (getDerived().AlwaysRebuild() ||
3489 ElementType != T->getElementType()) {
3490 Result = getDerived().RebuildConstantArrayType(ElementType,
3491 T->getSizeModifier(),
3492 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003493 T->getIndexTypeCVRQualifiers(),
3494 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003495 if (Result.isNull())
3496 return QualType();
3497 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003498
John McCall550e0c22009-10-21 00:40:46 +00003499 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3500 NewTL.setLBracketLoc(TL.getLBracketLoc());
3501 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003502
John McCall550e0c22009-10-21 00:40:46 +00003503 Expr *Size = TL.getSizeExpr();
3504 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003505 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003506 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3507 }
3508 NewTL.setSizeExpr(Size);
3509
3510 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003511}
Mike Stump11289f42009-09-09 15:08:12 +00003512
Douglas Gregord6ff3322009-08-04 16:50:30 +00003513template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003514QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003515 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003516 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003517 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003518 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003519 if (ElementType.isNull())
3520 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003521
John McCall550e0c22009-10-21 00:40:46 +00003522 QualType Result = TL.getType();
3523 if (getDerived().AlwaysRebuild() ||
3524 ElementType != T->getElementType()) {
3525 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003526 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003527 T->getIndexTypeCVRQualifiers(),
3528 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003529 if (Result.isNull())
3530 return QualType();
3531 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003532
John McCall550e0c22009-10-21 00:40:46 +00003533 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3534 NewTL.setLBracketLoc(TL.getLBracketLoc());
3535 NewTL.setRBracketLoc(TL.getRBracketLoc());
3536 NewTL.setSizeExpr(0);
3537
3538 return Result;
3539}
3540
3541template<typename Derived>
3542QualType
3543TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003544 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003545 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003546 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3547 if (ElementType.isNull())
3548 return QualType();
3549
3550 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003551 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003552
John McCalldadc5752010-08-24 06:29:42 +00003553 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003554 = getDerived().TransformExpr(T->getSizeExpr());
3555 if (SizeResult.isInvalid())
3556 return QualType();
3557
John McCallb268a282010-08-23 23:25:46 +00003558 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003559
3560 QualType Result = TL.getType();
3561 if (getDerived().AlwaysRebuild() ||
3562 ElementType != T->getElementType() ||
3563 Size != T->getSizeExpr()) {
3564 Result = getDerived().RebuildVariableArrayType(ElementType,
3565 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003566 Size,
John McCall550e0c22009-10-21 00:40:46 +00003567 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003568 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003569 if (Result.isNull())
3570 return QualType();
3571 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003572
John McCall550e0c22009-10-21 00:40:46 +00003573 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3574 NewTL.setLBracketLoc(TL.getLBracketLoc());
3575 NewTL.setRBracketLoc(TL.getRBracketLoc());
3576 NewTL.setSizeExpr(Size);
3577
3578 return Result;
3579}
3580
3581template<typename Derived>
3582QualType
3583TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003584 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003585 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003586 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3587 if (ElementType.isNull())
3588 return QualType();
3589
3590 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003591 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003592
John McCall33ddac02011-01-19 10:06:00 +00003593 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3594 Expr *origSize = TL.getSizeExpr();
3595 if (!origSize) origSize = T->getSizeExpr();
3596
3597 ExprResult sizeResult
3598 = getDerived().TransformExpr(origSize);
3599 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003600 return QualType();
3601
John McCall33ddac02011-01-19 10:06:00 +00003602 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003603
3604 QualType Result = TL.getType();
3605 if (getDerived().AlwaysRebuild() ||
3606 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003607 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003608 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3609 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003610 size,
John McCall550e0c22009-10-21 00:40:46 +00003611 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003612 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003613 if (Result.isNull())
3614 return QualType();
3615 }
John McCall550e0c22009-10-21 00:40:46 +00003616
3617 // We might have any sort of array type now, but fortunately they
3618 // all have the same location layout.
3619 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3620 NewTL.setLBracketLoc(TL.getLBracketLoc());
3621 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003622 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003623
3624 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003625}
Mike Stump11289f42009-09-09 15:08:12 +00003626
3627template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003628QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003629 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003630 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003631 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003632
3633 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003634 QualType ElementType = getDerived().TransformType(T->getElementType());
3635 if (ElementType.isNull())
3636 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003637
Douglas Gregore922c772009-08-04 22:27:00 +00003638 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003639 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003640
John McCalldadc5752010-08-24 06:29:42 +00003641 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003642 if (Size.isInvalid())
3643 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003644
John McCall550e0c22009-10-21 00:40:46 +00003645 QualType Result = TL.getType();
3646 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003647 ElementType != T->getElementType() ||
3648 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003649 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003650 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003651 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003652 if (Result.isNull())
3653 return QualType();
3654 }
John McCall550e0c22009-10-21 00:40:46 +00003655
3656 // Result might be dependent or not.
3657 if (isa<DependentSizedExtVectorType>(Result)) {
3658 DependentSizedExtVectorTypeLoc NewTL
3659 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3660 NewTL.setNameLoc(TL.getNameLoc());
3661 } else {
3662 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3663 NewTL.setNameLoc(TL.getNameLoc());
3664 }
3665
3666 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003667}
Mike Stump11289f42009-09-09 15:08:12 +00003668
3669template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003670QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003671 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003672 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003673 QualType ElementType = getDerived().TransformType(T->getElementType());
3674 if (ElementType.isNull())
3675 return QualType();
3676
John McCall550e0c22009-10-21 00:40:46 +00003677 QualType Result = TL.getType();
3678 if (getDerived().AlwaysRebuild() ||
3679 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003680 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003681 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003682 if (Result.isNull())
3683 return QualType();
3684 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003685
John McCall550e0c22009-10-21 00:40:46 +00003686 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3687 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003688
John McCall550e0c22009-10-21 00:40:46 +00003689 return Result;
3690}
3691
3692template<typename Derived>
3693QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003694 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003695 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003696 QualType ElementType = getDerived().TransformType(T->getElementType());
3697 if (ElementType.isNull())
3698 return QualType();
3699
3700 QualType Result = TL.getType();
3701 if (getDerived().AlwaysRebuild() ||
3702 ElementType != T->getElementType()) {
3703 Result = getDerived().RebuildExtVectorType(ElementType,
3704 T->getNumElements(),
3705 /*FIXME*/ SourceLocation());
3706 if (Result.isNull())
3707 return QualType();
3708 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003709
John McCall550e0c22009-10-21 00:40:46 +00003710 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3711 NewTL.setNameLoc(TL.getNameLoc());
3712
3713 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003714}
Mike Stump11289f42009-09-09 15:08:12 +00003715
3716template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003717ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003718TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3719 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003720 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003721 TypeSourceInfo *NewDI = 0;
3722
3723 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3724 // If we're substituting into a pack expansion type and we know the
3725 TypeLoc OldTL = OldDI->getTypeLoc();
3726 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3727
3728 TypeLocBuilder TLB;
3729 TypeLoc NewTL = OldDI->getTypeLoc();
3730 TLB.reserve(NewTL.getFullDataSize());
3731
3732 QualType Result = getDerived().TransformType(TLB,
3733 OldExpansionTL.getPatternLoc());
3734 if (Result.isNull())
3735 return 0;
3736
3737 Result = RebuildPackExpansionType(Result,
3738 OldExpansionTL.getPatternLoc().getSourceRange(),
3739 OldExpansionTL.getEllipsisLoc(),
3740 NumExpansions);
3741 if (Result.isNull())
3742 return 0;
3743
3744 PackExpansionTypeLoc NewExpansionTL
3745 = TLB.push<PackExpansionTypeLoc>(Result);
3746 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3747 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3748 } else
3749 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003750 if (!NewDI)
3751 return 0;
3752
3753 if (NewDI == OldDI)
3754 return OldParm;
3755 else
3756 return ParmVarDecl::Create(SemaRef.Context,
3757 OldParm->getDeclContext(),
3758 OldParm->getLocation(),
3759 OldParm->getIdentifier(),
3760 NewDI->getType(),
3761 NewDI,
3762 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003763 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003764 /* DefArg */ NULL);
3765}
3766
3767template<typename Derived>
3768bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003769 TransformFunctionTypeParams(SourceLocation Loc,
3770 ParmVarDecl **Params, unsigned NumParams,
3771 const QualType *ParamTypes,
3772 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3773 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3774 for (unsigned i = 0; i != NumParams; ++i) {
3775 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor715e4612011-01-14 22:40:04 +00003776 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003777 if (OldParm->isParameterPack()) {
3778 // We have a function parameter pack that may need to be expanded.
3779 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003780
Douglas Gregor5499af42011-01-05 23:12:31 +00003781 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003782 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3783 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3784 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3785 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor5499af42011-01-05 23:12:31 +00003786
3787 // Determine whether we should expand the parameter packs.
3788 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003789 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003790 llvm::Optional<unsigned> OrigNumExpansions
3791 = ExpansionTL.getTypePtr()->getNumExpansions();
3792 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003793 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3794 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003795 Unexpanded.data(),
3796 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003797 ShouldExpand,
3798 RetainExpansion,
3799 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003800 return true;
3801 }
3802
3803 if (ShouldExpand) {
3804 // Expand the function parameter pack into multiple, separate
3805 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003806 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003807 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003808 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3809 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003810 = getDerived().TransformFunctionTypeParam(OldParm,
3811 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003812 if (!NewParm)
3813 return true;
3814
Douglas Gregordd472162011-01-07 00:20:55 +00003815 OutParamTypes.push_back(NewParm->getType());
3816 if (PVars)
3817 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003818 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003819
3820 // If we're supposed to retain a pack expansion, do so by temporarily
3821 // forgetting the partially-substituted parameter pack.
3822 if (RetainExpansion) {
3823 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3824 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003825 = getDerived().TransformFunctionTypeParam(OldParm,
3826 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003827 if (!NewParm)
3828 return true;
3829
3830 OutParamTypes.push_back(NewParm->getType());
3831 if (PVars)
3832 PVars->push_back(NewParm);
3833 }
3834
Douglas Gregor5499af42011-01-05 23:12:31 +00003835 // We're done with the pack expansion.
3836 continue;
3837 }
3838
3839 // We'll substitute the parameter now without expanding the pack
3840 // expansion.
3841 }
3842
3843 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Douglas Gregor715e4612011-01-14 22:40:04 +00003844 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3845 NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +00003846 if (!NewParm)
3847 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003848
Douglas Gregordd472162011-01-07 00:20:55 +00003849 OutParamTypes.push_back(NewParm->getType());
3850 if (PVars)
3851 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003852 continue;
3853 }
John McCall58f10c32010-03-11 09:03:00 +00003854
3855 // Deal with the possibility that we don't have a parameter
3856 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003857 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003858 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003859 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003860 if (const PackExpansionType *Expansion
3861 = dyn_cast<PackExpansionType>(OldType)) {
3862 // We have a function parameter pack that may need to be expanded.
3863 QualType Pattern = Expansion->getPattern();
3864 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3865 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3866
3867 // Determine whether we should expand the parameter packs.
3868 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003869 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003870 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003871 Unexpanded.data(),
3872 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003873 ShouldExpand,
3874 RetainExpansion,
3875 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003876 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003877 }
3878
3879 if (ShouldExpand) {
3880 // Expand the function parameter pack into multiple, separate
3881 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003882 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003883 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3884 QualType NewType = getDerived().TransformType(Pattern);
3885 if (NewType.isNull())
3886 return true;
John McCall58f10c32010-03-11 09:03:00 +00003887
Douglas Gregordd472162011-01-07 00:20:55 +00003888 OutParamTypes.push_back(NewType);
3889 if (PVars)
3890 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003891 }
3892
3893 // We're done with the pack expansion.
3894 continue;
3895 }
3896
Douglas Gregor48d24112011-01-10 20:53:55 +00003897 // If we're supposed to retain a pack expansion, do so by temporarily
3898 // forgetting the partially-substituted parameter pack.
3899 if (RetainExpansion) {
3900 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3901 QualType NewType = getDerived().TransformType(Pattern);
3902 if (NewType.isNull())
3903 return true;
3904
3905 OutParamTypes.push_back(NewType);
3906 if (PVars)
3907 PVars->push_back(0);
3908 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003909
Douglas Gregor5499af42011-01-05 23:12:31 +00003910 // We'll substitute the parameter now without expanding the pack
3911 // expansion.
3912 OldType = Expansion->getPattern();
3913 IsPackExpansion = true;
3914 }
3915
3916 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3917 QualType NewType = getDerived().TransformType(OldType);
3918 if (NewType.isNull())
3919 return true;
3920
3921 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003922 NewType = getSema().Context.getPackExpansionType(NewType,
3923 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003924
Douglas Gregordd472162011-01-07 00:20:55 +00003925 OutParamTypes.push_back(NewType);
3926 if (PVars)
3927 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003928 }
3929
3930 return false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003931 }
John McCall58f10c32010-03-11 09:03:00 +00003932
3933template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003934QualType
John McCall550e0c22009-10-21 00:40:46 +00003935TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003936 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003937 // Transform the parameters and return type.
3938 //
3939 // We instantiate in source order, with the return type first followed by
3940 // the parameters, because users tend to expect this (even if they shouldn't
3941 // rely on it!).
3942 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003943 // When the function has a trailing return type, we instantiate the
3944 // parameters before the return type, since the return type can then refer
3945 // to the parameters themselves (via decltype, sizeof, etc.).
3946 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003947 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003948 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00003949 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003950
Douglas Gregor7fb25412010-10-01 18:44:50 +00003951 QualType ResultType;
3952
3953 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003954 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3955 TL.getParmArray(),
3956 TL.getNumArgs(),
3957 TL.getTypePtr()->arg_type_begin(),
3958 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003959 return QualType();
3960
3961 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3962 if (ResultType.isNull())
3963 return QualType();
3964 }
3965 else {
3966 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3967 if (ResultType.isNull())
3968 return QualType();
3969
Douglas Gregordd472162011-01-07 00:20:55 +00003970 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3971 TL.getParmArray(),
3972 TL.getNumArgs(),
3973 TL.getTypePtr()->arg_type_begin(),
3974 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003975 return QualType();
3976 }
3977
John McCall550e0c22009-10-21 00:40:46 +00003978 QualType Result = TL.getType();
3979 if (getDerived().AlwaysRebuild() ||
3980 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003981 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003982 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3983 Result = getDerived().RebuildFunctionProtoType(ResultType,
3984 ParamTypes.data(),
3985 ParamTypes.size(),
3986 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003987 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00003988 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003989 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003990 if (Result.isNull())
3991 return QualType();
3992 }
Mike Stump11289f42009-09-09 15:08:12 +00003993
John McCall550e0c22009-10-21 00:40:46 +00003994 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3995 NewTL.setLParenLoc(TL.getLParenLoc());
3996 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003997 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003998 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3999 NewTL.setArg(i, ParamDecls[i]);
4000
4001 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004002}
Mike Stump11289f42009-09-09 15:08:12 +00004003
Douglas Gregord6ff3322009-08-04 16:50:30 +00004004template<typename Derived>
4005QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004006 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004007 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004008 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004009 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4010 if (ResultType.isNull())
4011 return QualType();
4012
4013 QualType Result = TL.getType();
4014 if (getDerived().AlwaysRebuild() ||
4015 ResultType != T->getResultType())
4016 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4017
4018 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
4019 NewTL.setLParenLoc(TL.getLParenLoc());
4020 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004021 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00004022
4023 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004024}
Mike Stump11289f42009-09-09 15:08:12 +00004025
John McCallb96ec562009-12-04 22:46:56 +00004026template<typename Derived> QualType
4027TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004028 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004029 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004030 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004031 if (!D)
4032 return QualType();
4033
4034 QualType Result = TL.getType();
4035 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4036 Result = getDerived().RebuildUnresolvedUsingType(D);
4037 if (Result.isNull())
4038 return QualType();
4039 }
4040
4041 // We might get an arbitrary type spec type back. We should at
4042 // least always get a type spec type, though.
4043 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4044 NewTL.setNameLoc(TL.getNameLoc());
4045
4046 return Result;
4047}
4048
Douglas Gregord6ff3322009-08-04 16:50:30 +00004049template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004050QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004051 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004052 const TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004053 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004054 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4055 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004056 if (!Typedef)
4057 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004058
John McCall550e0c22009-10-21 00:40:46 +00004059 QualType Result = TL.getType();
4060 if (getDerived().AlwaysRebuild() ||
4061 Typedef != T->getDecl()) {
4062 Result = getDerived().RebuildTypedefType(Typedef);
4063 if (Result.isNull())
4064 return QualType();
4065 }
Mike Stump11289f42009-09-09 15:08:12 +00004066
John McCall550e0c22009-10-21 00:40:46 +00004067 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4068 NewTL.setNameLoc(TL.getNameLoc());
4069
4070 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004071}
Mike Stump11289f42009-09-09 15:08:12 +00004072
Douglas Gregord6ff3322009-08-04 16:50:30 +00004073template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004074QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004075 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004076 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004077 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004078
John McCalldadc5752010-08-24 06:29:42 +00004079 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004080 if (E.isInvalid())
4081 return QualType();
4082
John McCall550e0c22009-10-21 00:40:46 +00004083 QualType Result = TL.getType();
4084 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004085 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004086 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004087 if (Result.isNull())
4088 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004089 }
John McCall550e0c22009-10-21 00:40:46 +00004090 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004091
John McCall550e0c22009-10-21 00:40:46 +00004092 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004093 NewTL.setTypeofLoc(TL.getTypeofLoc());
4094 NewTL.setLParenLoc(TL.getLParenLoc());
4095 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004096
4097 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004098}
Mike Stump11289f42009-09-09 15:08:12 +00004099
4100template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004101QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004102 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004103 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4104 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4105 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004106 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004107
John McCall550e0c22009-10-21 00:40:46 +00004108 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004109 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4110 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004111 if (Result.isNull())
4112 return QualType();
4113 }
Mike Stump11289f42009-09-09 15:08:12 +00004114
John McCall550e0c22009-10-21 00:40:46 +00004115 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004116 NewTL.setTypeofLoc(TL.getTypeofLoc());
4117 NewTL.setLParenLoc(TL.getLParenLoc());
4118 NewTL.setRParenLoc(TL.getRParenLoc());
4119 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004120
4121 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004122}
Mike Stump11289f42009-09-09 15:08:12 +00004123
4124template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004125QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004126 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004127 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004128
Douglas Gregore922c772009-08-04 22:27:00 +00004129 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004130 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004131
John McCalldadc5752010-08-24 06:29:42 +00004132 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004133 if (E.isInvalid())
4134 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004135
John McCall550e0c22009-10-21 00:40:46 +00004136 QualType Result = TL.getType();
4137 if (getDerived().AlwaysRebuild() ||
4138 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004139 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004140 if (Result.isNull())
4141 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004142 }
John McCall550e0c22009-10-21 00:40:46 +00004143 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004144
John McCall550e0c22009-10-21 00:40:46 +00004145 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4146 NewTL.setNameLoc(TL.getNameLoc());
4147
4148 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004149}
4150
4151template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004152QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4153 AutoTypeLoc TL) {
4154 const AutoType *T = TL.getTypePtr();
4155 QualType OldDeduced = T->getDeducedType();
4156 QualType NewDeduced;
4157 if (!OldDeduced.isNull()) {
4158 NewDeduced = getDerived().TransformType(OldDeduced);
4159 if (NewDeduced.isNull())
4160 return QualType();
4161 }
4162
4163 QualType Result = TL.getType();
4164 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4165 Result = getDerived().RebuildAutoType(NewDeduced);
4166 if (Result.isNull())
4167 return QualType();
4168 }
4169
4170 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4171 NewTL.setNameLoc(TL.getNameLoc());
4172
4173 return Result;
4174}
4175
4176template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004177QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004178 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004179 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004180 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004181 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4182 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004183 if (!Record)
4184 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004185
John McCall550e0c22009-10-21 00:40:46 +00004186 QualType Result = TL.getType();
4187 if (getDerived().AlwaysRebuild() ||
4188 Record != T->getDecl()) {
4189 Result = getDerived().RebuildRecordType(Record);
4190 if (Result.isNull())
4191 return QualType();
4192 }
Mike Stump11289f42009-09-09 15:08:12 +00004193
John McCall550e0c22009-10-21 00:40:46 +00004194 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4195 NewTL.setNameLoc(TL.getNameLoc());
4196
4197 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004198}
Mike Stump11289f42009-09-09 15:08:12 +00004199
4200template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004201QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004202 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004203 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004204 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004205 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4206 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004207 if (!Enum)
4208 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004209
John McCall550e0c22009-10-21 00:40:46 +00004210 QualType Result = TL.getType();
4211 if (getDerived().AlwaysRebuild() ||
4212 Enum != T->getDecl()) {
4213 Result = getDerived().RebuildEnumType(Enum);
4214 if (Result.isNull())
4215 return QualType();
4216 }
Mike Stump11289f42009-09-09 15:08:12 +00004217
John McCall550e0c22009-10-21 00:40:46 +00004218 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4219 NewTL.setNameLoc(TL.getNameLoc());
4220
4221 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004222}
John McCallfcc33b02009-09-05 00:15:47 +00004223
John McCalle78aac42010-03-10 03:28:59 +00004224template<typename Derived>
4225QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4226 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004227 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004228 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4229 TL.getTypePtr()->getDecl());
4230 if (!D) return QualType();
4231
4232 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4233 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4234 return T;
4235}
4236
Douglas Gregord6ff3322009-08-04 16:50:30 +00004237template<typename Derived>
4238QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004239 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004240 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004241 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004242}
4243
Mike Stump11289f42009-09-09 15:08:12 +00004244template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004245QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004246 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004247 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004248 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00004249}
4250
4251template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004252QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4253 TypeLocBuilder &TLB,
4254 SubstTemplateTypeParmPackTypeLoc TL) {
4255 return TransformTypeSpecType(TLB, TL);
4256}
4257
4258template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004259QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004260 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004261 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004262 const TemplateSpecializationType *T = TL.getTypePtr();
4263
Mike Stump11289f42009-09-09 15:08:12 +00004264 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00004265 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004266 if (Template.isNull())
4267 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004268
John McCall31f82722010-11-12 08:19:04 +00004269 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4270}
4271
Douglas Gregorfe921a72010-12-20 23:36:19 +00004272namespace {
4273 /// \brief Simple iterator that traverses the template arguments in a
4274 /// container that provides a \c getArgLoc() member function.
4275 ///
4276 /// This iterator is intended to be used with the iterator form of
4277 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4278 template<typename ArgLocContainer>
4279 class TemplateArgumentLocContainerIterator {
4280 ArgLocContainer *Container;
4281 unsigned Index;
4282
4283 public:
4284 typedef TemplateArgumentLoc value_type;
4285 typedef TemplateArgumentLoc reference;
4286 typedef int difference_type;
4287 typedef std::input_iterator_tag iterator_category;
4288
4289 class pointer {
4290 TemplateArgumentLoc Arg;
4291
4292 public:
4293 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4294
4295 const TemplateArgumentLoc *operator->() const {
4296 return &Arg;
4297 }
4298 };
4299
4300
4301 TemplateArgumentLocContainerIterator() {}
4302
4303 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4304 unsigned Index)
4305 : Container(&Container), Index(Index) { }
4306
4307 TemplateArgumentLocContainerIterator &operator++() {
4308 ++Index;
4309 return *this;
4310 }
4311
4312 TemplateArgumentLocContainerIterator operator++(int) {
4313 TemplateArgumentLocContainerIterator Old(*this);
4314 ++(*this);
4315 return Old;
4316 }
4317
4318 TemplateArgumentLoc operator*() const {
4319 return Container->getArgLoc(Index);
4320 }
4321
4322 pointer operator->() const {
4323 return pointer(Container->getArgLoc(Index));
4324 }
4325
4326 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004327 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004328 return X.Container == Y.Container && X.Index == Y.Index;
4329 }
4330
4331 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004332 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004333 return !(X == Y);
4334 }
4335 };
4336}
4337
4338
John McCall31f82722010-11-12 08:19:04 +00004339template <typename Derived>
4340QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4341 TypeLocBuilder &TLB,
4342 TemplateSpecializationTypeLoc TL,
4343 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004344 TemplateArgumentListInfo NewTemplateArgs;
4345 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4346 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004347 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4348 ArgIterator;
4349 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4350 ArgIterator(TL, TL.getNumArgs()),
4351 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004352 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004353
John McCall0ad16662009-10-29 08:12:44 +00004354 // FIXME: maybe don't rebuild if all the template arguments are the same.
4355
4356 QualType Result =
4357 getDerived().RebuildTemplateSpecializationType(Template,
4358 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004359 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004360
4361 if (!Result.isNull()) {
4362 TemplateSpecializationTypeLoc NewTL
4363 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4364 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4365 NewTL.setLAngleLoc(TL.getLAngleLoc());
4366 NewTL.setRAngleLoc(TL.getRAngleLoc());
4367 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4368 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004369 }
Mike Stump11289f42009-09-09 15:08:12 +00004370
John McCall0ad16662009-10-29 08:12:44 +00004371 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004372}
Mike Stump11289f42009-09-09 15:08:12 +00004373
Douglas Gregor5a064722011-02-28 17:23:35 +00004374template <typename Derived>
4375QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4376 TypeLocBuilder &TLB,
4377 DependentTemplateSpecializationTypeLoc TL,
4378 TemplateName Template) {
4379 TemplateArgumentListInfo NewTemplateArgs;
4380 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4381 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4382 typedef TemplateArgumentLocContainerIterator<
4383 DependentTemplateSpecializationTypeLoc> ArgIterator;
4384 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4385 ArgIterator(TL, TL.getNumArgs()),
4386 NewTemplateArgs))
4387 return QualType();
4388
4389 // FIXME: maybe don't rebuild if all the template arguments are the same.
4390
4391 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4392 QualType Result
4393 = getSema().Context.getDependentTemplateSpecializationType(
4394 TL.getTypePtr()->getKeyword(),
4395 DTN->getQualifier(),
4396 DTN->getIdentifier(),
4397 NewTemplateArgs);
4398
4399 DependentTemplateSpecializationTypeLoc NewTL
4400 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4401 NewTL.setKeywordLoc(TL.getKeywordLoc());
4402 NewTL.setQualifierRange(TL.getQualifierRange());
4403 NewTL.setNameLoc(TL.getNameLoc());
4404 NewTL.setLAngleLoc(TL.getLAngleLoc());
4405 NewTL.setRAngleLoc(TL.getRAngleLoc());
4406 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4407 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4408 return Result;
4409 }
4410
4411 QualType Result
4412 = getDerived().RebuildTemplateSpecializationType(Template,
4413 TL.getNameLoc(),
4414 NewTemplateArgs);
4415
4416 if (!Result.isNull()) {
4417 /// FIXME: Wrap this in an elaborated-type-specifier?
4418 TemplateSpecializationTypeLoc NewTL
4419 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4420 NewTL.setTemplateNameLoc(TL.getNameLoc());
4421 NewTL.setLAngleLoc(TL.getLAngleLoc());
4422 NewTL.setRAngleLoc(TL.getRAngleLoc());
4423 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4424 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4425 }
4426
4427 return Result;
4428}
4429
Mike Stump11289f42009-09-09 15:08:12 +00004430template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004431QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004432TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004433 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004434 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004435
4436 NestedNameSpecifier *NNS = 0;
4437 // NOTE: the qualifier in an ElaboratedType is optional.
4438 if (T->getQualifier() != 0) {
4439 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004440 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00004441 if (!NNS)
4442 return QualType();
4443 }
Mike Stump11289f42009-09-09 15:08:12 +00004444
John McCall31f82722010-11-12 08:19:04 +00004445 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4446 if (NamedT.isNull())
4447 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004448
John McCall550e0c22009-10-21 00:40:46 +00004449 QualType Result = TL.getType();
4450 if (getDerived().AlwaysRebuild() ||
4451 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004452 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004453 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
4454 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004455 if (Result.isNull())
4456 return QualType();
4457 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004458
Abramo Bagnara6150c882010-05-11 21:36:43 +00004459 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004460 NewTL.setKeywordLoc(TL.getKeywordLoc());
4461 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00004462
4463 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004464}
Mike Stump11289f42009-09-09 15:08:12 +00004465
4466template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004467QualType TreeTransform<Derived>::TransformAttributedType(
4468 TypeLocBuilder &TLB,
4469 AttributedTypeLoc TL) {
4470 const AttributedType *oldType = TL.getTypePtr();
4471 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4472 if (modifiedType.isNull())
4473 return QualType();
4474
4475 QualType result = TL.getType();
4476
4477 // FIXME: dependent operand expressions?
4478 if (getDerived().AlwaysRebuild() ||
4479 modifiedType != oldType->getModifiedType()) {
4480 // TODO: this is really lame; we should really be rebuilding the
4481 // equivalent type from first principles.
4482 QualType equivalentType
4483 = getDerived().TransformType(oldType->getEquivalentType());
4484 if (equivalentType.isNull())
4485 return QualType();
4486 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4487 modifiedType,
4488 equivalentType);
4489 }
4490
4491 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4492 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4493 if (TL.hasAttrOperand())
4494 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4495 if (TL.hasAttrExprOperand())
4496 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4497 else if (TL.hasAttrEnumOperand())
4498 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4499
4500 return result;
4501}
4502
4503template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004504QualType
4505TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4506 ParenTypeLoc TL) {
4507 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4508 if (Inner.isNull())
4509 return QualType();
4510
4511 QualType Result = TL.getType();
4512 if (getDerived().AlwaysRebuild() ||
4513 Inner != TL.getInnerLoc().getType()) {
4514 Result = getDerived().RebuildParenType(Inner);
4515 if (Result.isNull())
4516 return QualType();
4517 }
4518
4519 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4520 NewTL.setLParenLoc(TL.getLParenLoc());
4521 NewTL.setRParenLoc(TL.getRParenLoc());
4522 return Result;
4523}
4524
4525template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004526QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004527 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004528 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004529
Douglas Gregord6ff3322009-08-04 16:50:30 +00004530 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00004531 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004532 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004533 if (!NNS)
4534 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004535
John McCallc392f372010-06-11 00:33:02 +00004536 QualType Result
4537 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
4538 T->getIdentifier(),
4539 TL.getKeywordLoc(),
4540 TL.getQualifierRange(),
4541 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004542 if (Result.isNull())
4543 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004544
Abramo Bagnarad7548482010-05-19 21:37:53 +00004545 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4546 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004547 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4548
Abramo Bagnarad7548482010-05-19 21:37:53 +00004549 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4550 NewTL.setKeywordLoc(TL.getKeywordLoc());
4551 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004552 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004553 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4554 NewTL.setKeywordLoc(TL.getKeywordLoc());
4555 NewTL.setQualifierRange(TL.getQualifierRange());
4556 NewTL.setNameLoc(TL.getNameLoc());
4557 }
John McCall550e0c22009-10-21 00:40:46 +00004558 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004559}
Mike Stump11289f42009-09-09 15:08:12 +00004560
Douglas Gregord6ff3322009-08-04 16:50:30 +00004561template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004562QualType TreeTransform<Derived>::
4563 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004564 DependentTemplateSpecializationTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004565 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCallc392f372010-06-11 00:33:02 +00004566
Douglas Gregor5a064722011-02-28 17:23:35 +00004567 NestedNameSpecifier *NNS = 0;
4568 if (T->getQualifier()) {
4569 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
4570 TL.getQualifierRange());
4571 if (!NNS)
4572 return QualType();
4573 }
4574
John McCall31f82722010-11-12 08:19:04 +00004575 return getDerived()
4576 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
4577}
4578
4579template<typename Derived>
4580QualType TreeTransform<Derived>::
4581 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4582 DependentTemplateSpecializationTypeLoc TL,
4583 NestedNameSpecifier *NNS) {
John McCall424cec92011-01-19 06:33:43 +00004584 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCall31f82722010-11-12 08:19:04 +00004585
John McCallc392f372010-06-11 00:33:02 +00004586 TemplateArgumentListInfo NewTemplateArgs;
4587 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4588 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor14454802011-02-25 02:25:35 +00004589
4590 // FIXME: Nested-name-specifier source location info!
Douglas Gregorfe921a72010-12-20 23:36:19 +00004591 typedef TemplateArgumentLocContainerIterator<
4592 DependentTemplateSpecializationTypeLoc> ArgIterator;
4593 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4594 ArgIterator(TL, TL.getNumArgs()),
4595 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004596 return QualType();
John McCallc392f372010-06-11 00:33:02 +00004597
Douglas Gregora5614c52010-09-08 23:56:00 +00004598 QualType Result
4599 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4600 NNS,
4601 TL.getQualifierRange(),
4602 T->getIdentifier(),
4603 TL.getNameLoc(),
4604 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00004605 if (Result.isNull())
4606 return QualType();
4607
4608 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4609 QualType NamedT = ElabT->getNamedType();
4610
4611 // Copy information relevant to the template specialization.
4612 TemplateSpecializationTypeLoc NamedTL
4613 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4614 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4615 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4616 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4617 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4618
4619 // Copy information relevant to the elaborated type.
4620 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4621 NewTL.setKeywordLoc(TL.getKeywordLoc());
4622 NewTL.setQualifierRange(TL.getQualifierRange());
4623 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00004624 TypeLoc NewTL(Result, TL.getOpaqueData());
4625 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00004626 }
4627 return Result;
4628}
4629
4630template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004631QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4632 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004633 QualType Pattern
4634 = getDerived().TransformType(TLB, TL.getPatternLoc());
4635 if (Pattern.isNull())
4636 return QualType();
4637
4638 QualType Result = TL.getType();
4639 if (getDerived().AlwaysRebuild() ||
4640 Pattern != TL.getPatternLoc().getType()) {
4641 Result = getDerived().RebuildPackExpansionType(Pattern,
4642 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004643 TL.getEllipsisLoc(),
4644 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004645 if (Result.isNull())
4646 return QualType();
4647 }
4648
4649 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4650 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4651 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004652}
4653
4654template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004655QualType
4656TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004657 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004658 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004659 TLB.pushFullCopy(TL);
4660 return TL.getType();
4661}
4662
4663template<typename Derived>
4664QualType
4665TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004666 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004667 // ObjCObjectType is never dependent.
4668 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004669 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004670}
Mike Stump11289f42009-09-09 15:08:12 +00004671
4672template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004673QualType
4674TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004675 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004676 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004677 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004678 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004679}
4680
Douglas Gregord6ff3322009-08-04 16:50:30 +00004681//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004682// Statement transformation
4683//===----------------------------------------------------------------------===//
4684template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004685StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004686TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004687 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004688}
4689
4690template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004691StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004692TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4693 return getDerived().TransformCompoundStmt(S, false);
4694}
4695
4696template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004697StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004698TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004699 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004700 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004701 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004702 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004703 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4704 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004705 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004706 if (Result.isInvalid()) {
4707 // Immediately fail if this was a DeclStmt, since it's very
4708 // likely that this will cause problems for future statements.
4709 if (isa<DeclStmt>(*B))
4710 return StmtError();
4711
4712 // Otherwise, just keep processing substatements and fail later.
4713 SubStmtInvalid = true;
4714 continue;
4715 }
Mike Stump11289f42009-09-09 15:08:12 +00004716
Douglas Gregorebe10102009-08-20 07:17:43 +00004717 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4718 Statements.push_back(Result.takeAs<Stmt>());
4719 }
Mike Stump11289f42009-09-09 15:08:12 +00004720
John McCall1ababa62010-08-27 19:56:05 +00004721 if (SubStmtInvalid)
4722 return StmtError();
4723
Douglas Gregorebe10102009-08-20 07:17:43 +00004724 if (!getDerived().AlwaysRebuild() &&
4725 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004726 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004727
4728 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4729 move_arg(Statements),
4730 S->getRBracLoc(),
4731 IsStmtExpr);
4732}
Mike Stump11289f42009-09-09 15:08:12 +00004733
Douglas Gregorebe10102009-08-20 07:17:43 +00004734template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004735StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004736TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004737 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004738 {
4739 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004740 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004741
Eli Friedman06577382009-11-19 03:14:00 +00004742 // Transform the left-hand case value.
4743 LHS = getDerived().TransformExpr(S->getLHS());
4744 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004745 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004746
Eli Friedman06577382009-11-19 03:14:00 +00004747 // Transform the right-hand case value (for the GNU case-range extension).
4748 RHS = getDerived().TransformExpr(S->getRHS());
4749 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004750 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004751 }
Mike Stump11289f42009-09-09 15:08:12 +00004752
Douglas Gregorebe10102009-08-20 07:17:43 +00004753 // Build the case statement.
4754 // Case statements are always rebuilt so that they will attached to their
4755 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004756 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004757 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004758 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004759 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004760 S->getColonLoc());
4761 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004762 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004763
Douglas Gregorebe10102009-08-20 07:17:43 +00004764 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004765 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004766 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004767 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004768
Douglas Gregorebe10102009-08-20 07:17:43 +00004769 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004770 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004771}
4772
4773template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004774StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004775TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004776 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004777 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004778 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004779 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004780
Douglas Gregorebe10102009-08-20 07:17:43 +00004781 // Default statements are always rebuilt
4782 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004783 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004784}
Mike Stump11289f42009-09-09 15:08:12 +00004785
Douglas Gregorebe10102009-08-20 07:17:43 +00004786template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004787StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004788TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004789 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004790 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004791 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004792
Chris Lattnercab02a62011-02-17 20:34:02 +00004793 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4794 S->getDecl());
4795 if (!LD)
4796 return StmtError();
4797
4798
Douglas Gregorebe10102009-08-20 07:17:43 +00004799 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004800 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004801 cast<LabelDecl>(LD), SourceLocation(),
4802 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004803}
Mike Stump11289f42009-09-09 15:08:12 +00004804
Douglas Gregorebe10102009-08-20 07:17:43 +00004805template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004806StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004807TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004808 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004809 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004810 VarDecl *ConditionVar = 0;
4811 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004812 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004813 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004814 getDerived().TransformDefinition(
4815 S->getConditionVariable()->getLocation(),
4816 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004817 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004818 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004819 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004820 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004821
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004822 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004823 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004824
4825 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004826 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004827 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4828 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004829 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004830 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004831
John McCallb268a282010-08-23 23:25:46 +00004832 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004833 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004834 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004835
John McCallb268a282010-08-23 23:25:46 +00004836 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4837 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004838 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004839
Douglas Gregorebe10102009-08-20 07:17:43 +00004840 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004841 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004842 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004843 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004844
Douglas Gregorebe10102009-08-20 07:17:43 +00004845 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004846 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004847 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004848 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004849
Douglas Gregorebe10102009-08-20 07:17:43 +00004850 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004851 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004852 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004853 Then.get() == S->getThen() &&
4854 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004855 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004856
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004857 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004858 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004859 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004860}
4861
4862template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004863StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004864TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004865 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004866 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004867 VarDecl *ConditionVar = 0;
4868 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004869 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004870 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004871 getDerived().TransformDefinition(
4872 S->getConditionVariable()->getLocation(),
4873 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004874 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004875 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004876 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004877 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004878
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004879 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004880 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004881 }
Mike Stump11289f42009-09-09 15:08:12 +00004882
Douglas Gregorebe10102009-08-20 07:17:43 +00004883 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004884 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004885 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004886 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004887 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004888 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004889
Douglas Gregorebe10102009-08-20 07:17:43 +00004890 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004891 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004892 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004893 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004894
Douglas Gregorebe10102009-08-20 07:17:43 +00004895 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004896 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4897 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004898}
Mike Stump11289f42009-09-09 15:08:12 +00004899
Douglas Gregorebe10102009-08-20 07:17:43 +00004900template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004901StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004902TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004903 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004904 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004905 VarDecl *ConditionVar = 0;
4906 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004907 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004908 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004909 getDerived().TransformDefinition(
4910 S->getConditionVariable()->getLocation(),
4911 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004912 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004913 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004914 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004915 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004916
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004917 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004918 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004919
4920 if (S->getCond()) {
4921 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004922 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4923 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004924 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004925 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004926 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004927 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004928 }
Mike Stump11289f42009-09-09 15:08:12 +00004929
John McCallb268a282010-08-23 23:25:46 +00004930 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4931 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004932 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004933
Douglas Gregorebe10102009-08-20 07:17:43 +00004934 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004935 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004936 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004937 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004938
Douglas Gregorebe10102009-08-20 07:17:43 +00004939 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004940 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004941 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004942 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004943 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004944
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004945 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004946 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004947}
Mike Stump11289f42009-09-09 15:08:12 +00004948
Douglas Gregorebe10102009-08-20 07:17:43 +00004949template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004950StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004951TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004952 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004953 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004954 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004955 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004956
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004957 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004958 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004959 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004960 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004961
Douglas Gregorebe10102009-08-20 07:17:43 +00004962 if (!getDerived().AlwaysRebuild() &&
4963 Cond.get() == S->getCond() &&
4964 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004965 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004966
John McCallb268a282010-08-23 23:25:46 +00004967 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4968 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004969 S->getRParenLoc());
4970}
Mike Stump11289f42009-09-09 15:08:12 +00004971
Douglas Gregorebe10102009-08-20 07:17:43 +00004972template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004973StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004974TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004975 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004976 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004977 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004978 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004979
Douglas Gregorebe10102009-08-20 07:17:43 +00004980 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004981 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004982 VarDecl *ConditionVar = 0;
4983 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004984 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004985 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004986 getDerived().TransformDefinition(
4987 S->getConditionVariable()->getLocation(),
4988 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004989 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004990 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004991 } else {
4992 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004993
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004994 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004995 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004996
4997 if (S->getCond()) {
4998 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004999 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5000 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005001 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005002 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005003
John McCallb268a282010-08-23 23:25:46 +00005004 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005005 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005006 }
Mike Stump11289f42009-09-09 15:08:12 +00005007
John McCallb268a282010-08-23 23:25:46 +00005008 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5009 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005010 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005011
Douglas Gregorebe10102009-08-20 07:17:43 +00005012 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005013 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005014 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005015 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005016
John McCallb268a282010-08-23 23:25:46 +00005017 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5018 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005019 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005020
Douglas Gregorebe10102009-08-20 07:17:43 +00005021 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005022 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005023 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005024 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005025
Douglas Gregorebe10102009-08-20 07:17:43 +00005026 if (!getDerived().AlwaysRebuild() &&
5027 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005028 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005029 Inc.get() == S->getInc() &&
5030 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005031 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005032
Douglas Gregorebe10102009-08-20 07:17:43 +00005033 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005034 Init.get(), FullCond, ConditionVar,
5035 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005036}
5037
5038template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005039StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005040TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005041 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5042 S->getLabel());
5043 if (!LD)
5044 return StmtError();
5045
Douglas Gregorebe10102009-08-20 07:17:43 +00005046 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005047 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005048 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005049}
5050
5051template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005052StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005053TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005054 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005055 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005056 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005057
Douglas Gregorebe10102009-08-20 07:17:43 +00005058 if (!getDerived().AlwaysRebuild() &&
5059 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005060 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005061
5062 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005063 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005064}
5065
5066template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005067StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005068TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005069 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005070}
Mike Stump11289f42009-09-09 15:08:12 +00005071
Douglas Gregorebe10102009-08-20 07:17:43 +00005072template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005073StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005074TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005075 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005076}
Mike Stump11289f42009-09-09 15:08:12 +00005077
Douglas Gregorebe10102009-08-20 07:17:43 +00005078template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005079StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005080TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005081 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005082 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005083 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005084
Mike Stump11289f42009-09-09 15:08:12 +00005085 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005086 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005087 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005088}
Mike Stump11289f42009-09-09 15:08:12 +00005089
Douglas Gregorebe10102009-08-20 07:17:43 +00005090template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005091StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005092TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005093 bool DeclChanged = false;
5094 llvm::SmallVector<Decl *, 4> Decls;
5095 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5096 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005097 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5098 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005099 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005100 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005101
Douglas Gregorebe10102009-08-20 07:17:43 +00005102 if (Transformed != *D)
5103 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005104
Douglas Gregorebe10102009-08-20 07:17:43 +00005105 Decls.push_back(Transformed);
5106 }
Mike Stump11289f42009-09-09 15:08:12 +00005107
Douglas Gregorebe10102009-08-20 07:17:43 +00005108 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005109 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005110
5111 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005112 S->getStartLoc(), S->getEndLoc());
5113}
Mike Stump11289f42009-09-09 15:08:12 +00005114
Douglas Gregorebe10102009-08-20 07:17:43 +00005115template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005116StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005117TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005118
John McCall37ad5512010-08-23 06:44:23 +00005119 ASTOwningVector<Expr*> Constraints(getSema());
5120 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00005121 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005122
John McCalldadc5752010-08-24 06:29:42 +00005123 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005124 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005125
5126 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005127
Anders Carlssonaaeef072010-01-24 05:50:09 +00005128 // Go through the outputs.
5129 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005130 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005131
Anders Carlssonaaeef072010-01-24 05:50:09 +00005132 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005133 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005134
Anders Carlssonaaeef072010-01-24 05:50:09 +00005135 // Transform the output expr.
5136 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005137 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005138 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005139 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005140
Anders Carlssonaaeef072010-01-24 05:50:09 +00005141 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005142
John McCallb268a282010-08-23 23:25:46 +00005143 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005144 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005145
Anders Carlssonaaeef072010-01-24 05:50:09 +00005146 // Go through the inputs.
5147 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005148 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005149
Anders Carlssonaaeef072010-01-24 05:50:09 +00005150 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005151 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005152
Anders Carlssonaaeef072010-01-24 05:50:09 +00005153 // Transform the input expr.
5154 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005155 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005156 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005157 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005158
Anders Carlssonaaeef072010-01-24 05:50:09 +00005159 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005160
John McCallb268a282010-08-23 23:25:46 +00005161 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005162 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005163
Anders Carlssonaaeef072010-01-24 05:50:09 +00005164 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005165 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005166
5167 // Go through the clobbers.
5168 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005169 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005170
5171 // No need to transform the asm string literal.
5172 AsmString = SemaRef.Owned(S->getAsmString());
5173
5174 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5175 S->isSimple(),
5176 S->isVolatile(),
5177 S->getNumOutputs(),
5178 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005179 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005180 move_arg(Constraints),
5181 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005182 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005183 move_arg(Clobbers),
5184 S->getRParenLoc(),
5185 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005186}
5187
5188
5189template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005190StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005191TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005192 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005193 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005194 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005195 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005196
Douglas Gregor96c79492010-04-23 22:50:49 +00005197 // Transform the @catch statements (if present).
5198 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005199 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005200 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005201 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005202 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005203 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005204 if (Catch.get() != S->getCatchStmt(I))
5205 AnyCatchChanged = true;
5206 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005207 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005208
Douglas Gregor306de2f2010-04-22 23:59:56 +00005209 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005210 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005211 if (S->getFinallyStmt()) {
5212 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5213 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005214 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005215 }
5216
5217 // If nothing changed, just retain this statement.
5218 if (!getDerived().AlwaysRebuild() &&
5219 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005220 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005221 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005222 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005223
Douglas Gregor306de2f2010-04-22 23:59:56 +00005224 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005225 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5226 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005227}
Mike Stump11289f42009-09-09 15:08:12 +00005228
Douglas Gregorebe10102009-08-20 07:17:43 +00005229template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005230StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005231TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005232 // Transform the @catch parameter, if there is one.
5233 VarDecl *Var = 0;
5234 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5235 TypeSourceInfo *TSInfo = 0;
5236 if (FromVar->getTypeSourceInfo()) {
5237 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5238 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005239 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005240 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005241
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005242 QualType T;
5243 if (TSInfo)
5244 T = TSInfo->getType();
5245 else {
5246 T = getDerived().TransformType(FromVar->getType());
5247 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005248 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005249 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005250
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005251 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5252 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005253 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005254 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005255
John McCalldadc5752010-08-24 06:29:42 +00005256 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005257 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005258 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005259
5260 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005261 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005262 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005263}
Mike Stump11289f42009-09-09 15:08:12 +00005264
Douglas Gregorebe10102009-08-20 07:17:43 +00005265template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005266StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005267TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005268 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005269 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005270 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005271 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005272
Douglas Gregor306de2f2010-04-22 23:59:56 +00005273 // If nothing changed, just retain this statement.
5274 if (!getDerived().AlwaysRebuild() &&
5275 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005276 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005277
5278 // Build a new statement.
5279 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005280 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005281}
Mike Stump11289f42009-09-09 15:08:12 +00005282
Douglas Gregorebe10102009-08-20 07:17:43 +00005283template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005284StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005285TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005286 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005287 if (S->getThrowExpr()) {
5288 Operand = getDerived().TransformExpr(S->getThrowExpr());
5289 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005290 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005291 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005292
Douglas Gregor2900c162010-04-22 21:44:01 +00005293 if (!getDerived().AlwaysRebuild() &&
5294 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005295 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005296
John McCallb268a282010-08-23 23:25:46 +00005297 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005298}
Mike Stump11289f42009-09-09 15:08:12 +00005299
Douglas Gregorebe10102009-08-20 07:17:43 +00005300template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005301StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005302TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005303 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005304 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005305 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005306 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005307 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005308
Douglas Gregor6148de72010-04-22 22:01:21 +00005309 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005310 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005311 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005312 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005313
Douglas Gregor6148de72010-04-22 22:01:21 +00005314 // If nothing change, just retain the current statement.
5315 if (!getDerived().AlwaysRebuild() &&
5316 Object.get() == S->getSynchExpr() &&
5317 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005318 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005319
5320 // Build a new statement.
5321 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005322 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005323}
5324
5325template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005326StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005327TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005328 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005329 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005330 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005331 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005332 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005333
Douglas Gregorf68a5082010-04-22 23:10:45 +00005334 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005335 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005336 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005337 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005338
Douglas Gregorf68a5082010-04-22 23:10:45 +00005339 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005340 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005341 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005342 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005343
Douglas Gregorf68a5082010-04-22 23:10:45 +00005344 // If nothing changed, just retain this statement.
5345 if (!getDerived().AlwaysRebuild() &&
5346 Element.get() == S->getElement() &&
5347 Collection.get() == S->getCollection() &&
5348 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005349 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005350
Douglas Gregorf68a5082010-04-22 23:10:45 +00005351 // Build a new statement.
5352 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5353 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005354 Element.get(),
5355 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005356 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005357 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005358}
5359
5360
5361template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005362StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005363TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5364 // Transform the exception declaration, if any.
5365 VarDecl *Var = 0;
5366 if (S->getExceptionDecl()) {
5367 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005368 TypeSourceInfo *T = getDerived().TransformType(
5369 ExceptionDecl->getTypeSourceInfo());
5370 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005371 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005372
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005373 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00005374 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005375 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00005376 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005377 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005378 }
Mike Stump11289f42009-09-09 15:08:12 +00005379
Douglas Gregorebe10102009-08-20 07:17:43 +00005380 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005381 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005382 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005383 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005384
Douglas Gregorebe10102009-08-20 07:17:43 +00005385 if (!getDerived().AlwaysRebuild() &&
5386 !Var &&
5387 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005388 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005389
5390 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5391 Var,
John McCallb268a282010-08-23 23:25:46 +00005392 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005393}
Mike Stump11289f42009-09-09 15:08:12 +00005394
Douglas Gregorebe10102009-08-20 07:17:43 +00005395template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005396StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005397TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5398 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005399 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005400 = getDerived().TransformCompoundStmt(S->getTryBlock());
5401 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005402 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005403
Douglas Gregorebe10102009-08-20 07:17:43 +00005404 // Transform the handlers.
5405 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005406 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005407 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005408 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005409 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5410 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005411 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005412
Douglas Gregorebe10102009-08-20 07:17:43 +00005413 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5414 Handlers.push_back(Handler.takeAs<Stmt>());
5415 }
Mike Stump11289f42009-09-09 15:08:12 +00005416
Douglas Gregorebe10102009-08-20 07:17:43 +00005417 if (!getDerived().AlwaysRebuild() &&
5418 TryBlock.get() == S->getTryBlock() &&
5419 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005420 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005421
John McCallb268a282010-08-23 23:25:46 +00005422 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005423 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005424}
Mike Stump11289f42009-09-09 15:08:12 +00005425
Douglas Gregorebe10102009-08-20 07:17:43 +00005426//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005427// Expression transformation
5428//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005429template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005430ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005431TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005432 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005433}
Mike Stump11289f42009-09-09 15:08:12 +00005434
5435template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005436ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005437TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005438 NestedNameSpecifierLoc QualifierLoc;
5439 if (E->getQualifierLoc()) {
5440 QualifierLoc
5441 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5442 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005443 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005444 }
John McCallce546572009-12-08 09:08:17 +00005445
5446 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005447 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5448 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005449 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005450 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005451
John McCall815039a2010-08-17 21:27:17 +00005452 DeclarationNameInfo NameInfo = E->getNameInfo();
5453 if (NameInfo.getName()) {
5454 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5455 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005456 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005457 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005458
5459 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005460 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005461 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005462 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005463 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005464
5465 // Mark it referenced in the new context regardless.
5466 // FIXME: this is a bit instantiation-specific.
5467 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5468
John McCallc3007a22010-10-26 07:05:15 +00005469 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005470 }
John McCallce546572009-12-08 09:08:17 +00005471
5472 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005473 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005474 TemplateArgs = &TransArgs;
5475 TransArgs.setLAngleLoc(E->getLAngleLoc());
5476 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005477 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5478 E->getNumTemplateArgs(),
5479 TransArgs))
5480 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005481 }
5482
Douglas Gregorea972d32011-02-28 21:54:11 +00005483 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5484 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005485}
Mike Stump11289f42009-09-09 15:08:12 +00005486
Douglas Gregora16548e2009-08-11 05:31:07 +00005487template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005488ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005489TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005490 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005491}
Mike Stump11289f42009-09-09 15:08:12 +00005492
Douglas Gregora16548e2009-08-11 05:31:07 +00005493template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005494ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005495TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005496 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005497}
Mike Stump11289f42009-09-09 15:08:12 +00005498
Douglas Gregora16548e2009-08-11 05:31:07 +00005499template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005500ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005501TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005502 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005503}
Mike Stump11289f42009-09-09 15:08:12 +00005504
Douglas Gregora16548e2009-08-11 05:31:07 +00005505template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005506ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005507TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005508 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005509}
Mike Stump11289f42009-09-09 15:08:12 +00005510
Douglas Gregora16548e2009-08-11 05:31:07 +00005511template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005512ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005513TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005514 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005515}
5516
5517template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005518ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005519TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005520 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005521 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005522 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005523
Douglas Gregora16548e2009-08-11 05:31:07 +00005524 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005525 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005526
John McCallb268a282010-08-23 23:25:46 +00005527 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005528 E->getRParen());
5529}
5530
Mike Stump11289f42009-09-09 15:08:12 +00005531template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005532ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005533TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005534 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005535 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005536 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005537
Douglas Gregora16548e2009-08-11 05:31:07 +00005538 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005539 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005540
Douglas Gregora16548e2009-08-11 05:31:07 +00005541 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5542 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005543 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005544}
Mike Stump11289f42009-09-09 15:08:12 +00005545
Douglas Gregora16548e2009-08-11 05:31:07 +00005546template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005547ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005548TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5549 // Transform the type.
5550 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5551 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005552 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005553
Douglas Gregor882211c2010-04-28 22:16:22 +00005554 // Transform all of the components into components similar to what the
5555 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005556 // FIXME: It would be slightly more efficient in the non-dependent case to
5557 // just map FieldDecls, rather than requiring the rebuilder to look for
5558 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005559 // template code that we don't care.
5560 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005561 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005562 typedef OffsetOfExpr::OffsetOfNode Node;
5563 llvm::SmallVector<Component, 4> Components;
5564 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5565 const Node &ON = E->getComponent(I);
5566 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005567 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00005568 Comp.LocStart = ON.getRange().getBegin();
5569 Comp.LocEnd = ON.getRange().getEnd();
5570 switch (ON.getKind()) {
5571 case Node::Array: {
5572 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005573 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005574 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005575 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005576
Douglas Gregor882211c2010-04-28 22:16:22 +00005577 ExprChanged = ExprChanged || Index.get() != FromIndex;
5578 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005579 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005580 break;
5581 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005582
Douglas Gregor882211c2010-04-28 22:16:22 +00005583 case Node::Field:
5584 case Node::Identifier:
5585 Comp.isBrackets = false;
5586 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005587 if (!Comp.U.IdentInfo)
5588 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005589
Douglas Gregor882211c2010-04-28 22:16:22 +00005590 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005591
Douglas Gregord1702062010-04-29 00:18:15 +00005592 case Node::Base:
5593 // Will be recomputed during the rebuild.
5594 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005595 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005596
Douglas Gregor882211c2010-04-28 22:16:22 +00005597 Components.push_back(Comp);
5598 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005599
Douglas Gregor882211c2010-04-28 22:16:22 +00005600 // If nothing changed, retain the existing expression.
5601 if (!getDerived().AlwaysRebuild() &&
5602 Type == E->getTypeSourceInfo() &&
5603 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005604 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005605
Douglas Gregor882211c2010-04-28 22:16:22 +00005606 // Build a new offsetof expression.
5607 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5608 Components.data(), Components.size(),
5609 E->getRParenLoc());
5610}
5611
5612template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005613ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005614TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5615 assert(getDerived().AlreadyTransformed(E->getType()) &&
5616 "opaque value expression requires transformation");
5617 return SemaRef.Owned(E);
5618}
5619
5620template<typename Derived>
5621ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005622TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005623 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005624 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005625
John McCallbcd03502009-12-07 02:54:59 +00005626 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005627 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005628 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005629
John McCall4c98fd82009-11-04 07:28:41 +00005630 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005631 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005632
John McCall4c98fd82009-11-04 07:28:41 +00005633 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005634 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005635 E->getSourceRange());
5636 }
Mike Stump11289f42009-09-09 15:08:12 +00005637
John McCalldadc5752010-08-24 06:29:42 +00005638 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005639 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005640 // C++0x [expr.sizeof]p1:
5641 // The operand is either an expression, which is an unevaluated operand
5642 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005643 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005644
Douglas Gregora16548e2009-08-11 05:31:07 +00005645 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5646 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005647 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005648
Douglas Gregora16548e2009-08-11 05:31:07 +00005649 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005650 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005651 }
Mike Stump11289f42009-09-09 15:08:12 +00005652
John McCallb268a282010-08-23 23:25:46 +00005653 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005654 E->isSizeOf(),
5655 E->getSourceRange());
5656}
Mike Stump11289f42009-09-09 15:08:12 +00005657
Douglas Gregora16548e2009-08-11 05:31:07 +00005658template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005659ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005660TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005661 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005662 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005663 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005664
John McCalldadc5752010-08-24 06:29:42 +00005665 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005666 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005667 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005668
5669
Douglas Gregora16548e2009-08-11 05:31:07 +00005670 if (!getDerived().AlwaysRebuild() &&
5671 LHS.get() == E->getLHS() &&
5672 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005673 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005674
John McCallb268a282010-08-23 23:25:46 +00005675 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005676 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005677 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005678 E->getRBracketLoc());
5679}
Mike Stump11289f42009-09-09 15:08:12 +00005680
5681template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005682ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005683TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005684 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005685 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005686 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005687 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005688
5689 // Transform arguments.
5690 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005691 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005692 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5693 &ArgChanged))
5694 return ExprError();
5695
Douglas Gregora16548e2009-08-11 05:31:07 +00005696 if (!getDerived().AlwaysRebuild() &&
5697 Callee.get() == E->getCallee() &&
5698 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005699 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005700
Douglas Gregora16548e2009-08-11 05:31:07 +00005701 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005702 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005703 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005704 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005705 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005706 E->getRParenLoc());
5707}
Mike Stump11289f42009-09-09 15:08:12 +00005708
5709template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005710ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005711TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005712 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005713 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005714 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005715
Douglas Gregorea972d32011-02-28 21:54:11 +00005716 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005717 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005718 QualifierLoc
5719 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5720
5721 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005722 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005723 }
Mike Stump11289f42009-09-09 15:08:12 +00005724
Eli Friedman2cfcef62009-12-04 06:40:45 +00005725 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005726 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5727 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005728 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005729 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005730
John McCall16df1e52010-03-30 21:47:33 +00005731 NamedDecl *FoundDecl = E->getFoundDecl();
5732 if (FoundDecl == E->getMemberDecl()) {
5733 FoundDecl = Member;
5734 } else {
5735 FoundDecl = cast_or_null<NamedDecl>(
5736 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5737 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005738 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005739 }
5740
Douglas Gregora16548e2009-08-11 05:31:07 +00005741 if (!getDerived().AlwaysRebuild() &&
5742 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005743 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005744 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005745 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005746 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005747
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005748 // Mark it referenced in the new context regardless.
5749 // FIXME: this is a bit instantiation-specific.
5750 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005751 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005752 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005753
John McCall6b51f282009-11-23 01:53:49 +00005754 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005755 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005756 TransArgs.setLAngleLoc(E->getLAngleLoc());
5757 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005758 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5759 E->getNumTemplateArgs(),
5760 TransArgs))
5761 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005762 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005763
Douglas Gregora16548e2009-08-11 05:31:07 +00005764 // FIXME: Bogus source location for the operator
5765 SourceLocation FakeOperatorLoc
5766 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5767
John McCall38836f02010-01-15 08:34:02 +00005768 // FIXME: to do this check properly, we will need to preserve the
5769 // first-qualifier-in-scope here, just in case we had a dependent
5770 // base (and therefore couldn't do the check) and a
5771 // nested-name-qualifier (and therefore could do the lookup).
5772 NamedDecl *FirstQualifierInScope = 0;
5773
John McCallb268a282010-08-23 23:25:46 +00005774 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005775 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00005776 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005777 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005778 Member,
John McCall16df1e52010-03-30 21:47:33 +00005779 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005780 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005781 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005782 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005783}
Mike Stump11289f42009-09-09 15:08:12 +00005784
Douglas Gregora16548e2009-08-11 05:31:07 +00005785template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005786ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005787TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005788 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005789 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005790 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005791
John McCalldadc5752010-08-24 06:29:42 +00005792 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005793 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005794 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005795
Douglas Gregora16548e2009-08-11 05:31:07 +00005796 if (!getDerived().AlwaysRebuild() &&
5797 LHS.get() == E->getLHS() &&
5798 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005799 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005800
Douglas Gregora16548e2009-08-11 05:31:07 +00005801 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005802 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005803}
5804
Mike Stump11289f42009-09-09 15:08:12 +00005805template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005806ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005807TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005808 CompoundAssignOperator *E) {
5809 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005810}
Mike Stump11289f42009-09-09 15:08:12 +00005811
Douglas Gregora16548e2009-08-11 05:31:07 +00005812template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00005813ExprResult TreeTransform<Derived>::
5814TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
5815 // Just rebuild the common and RHS expressions and see whether we
5816 // get any changes.
5817
5818 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
5819 if (commonExpr.isInvalid())
5820 return ExprError();
5821
5822 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
5823 if (rhs.isInvalid())
5824 return ExprError();
5825
5826 if (!getDerived().AlwaysRebuild() &&
5827 commonExpr.get() == e->getCommon() &&
5828 rhs.get() == e->getFalseExpr())
5829 return SemaRef.Owned(e);
5830
5831 return getDerived().RebuildConditionalOperator(commonExpr.take(),
5832 e->getQuestionLoc(),
5833 0,
5834 e->getColonLoc(),
5835 rhs.get());
5836}
5837
5838template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005839ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005840TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005841 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005842 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005843 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005844
John McCalldadc5752010-08-24 06:29:42 +00005845 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005846 if (LHS.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 RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005850 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005851 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005852
Douglas Gregora16548e2009-08-11 05:31:07 +00005853 if (!getDerived().AlwaysRebuild() &&
5854 Cond.get() == E->getCond() &&
5855 LHS.get() == E->getLHS() &&
5856 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005857 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005858
John McCallb268a282010-08-23 23:25:46 +00005859 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005860 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005861 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005862 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005863 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005864}
Mike Stump11289f42009-09-09 15:08:12 +00005865
5866template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005867ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005868TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005869 // Implicit casts are eliminated during transformation, since they
5870 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005871 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005872}
Mike Stump11289f42009-09-09 15:08:12 +00005873
Douglas Gregora16548e2009-08-11 05:31:07 +00005874template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005875ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005876TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005877 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5878 if (!Type)
5879 return ExprError();
5880
John McCalldadc5752010-08-24 06:29:42 +00005881 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005882 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005883 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005884 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005885
Douglas Gregora16548e2009-08-11 05:31:07 +00005886 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005887 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005888 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005889 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005890
John McCall97513962010-01-15 18:39:57 +00005891 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005892 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005893 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005894 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005895}
Mike Stump11289f42009-09-09 15:08:12 +00005896
Douglas Gregora16548e2009-08-11 05:31:07 +00005897template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005898ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005899TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005900 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5901 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5902 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005903 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005904
John McCalldadc5752010-08-24 06:29:42 +00005905 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005906 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005907 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005908
Douglas Gregora16548e2009-08-11 05:31:07 +00005909 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005910 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005911 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005912 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005913
John McCall5d7aa7f2010-01-19 22:33:45 +00005914 // Note: the expression type doesn't necessarily match the
5915 // type-as-written, but that's okay, because it should always be
5916 // derivable from the initializer.
5917
John McCalle15bbff2010-01-18 19:35:47 +00005918 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005919 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005920 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005921}
Mike Stump11289f42009-09-09 15:08:12 +00005922
Douglas Gregora16548e2009-08-11 05:31:07 +00005923template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005924ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005925TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005926 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005927 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005928 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005929
Douglas Gregora16548e2009-08-11 05:31:07 +00005930 if (!getDerived().AlwaysRebuild() &&
5931 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00005932 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005933
Douglas Gregora16548e2009-08-11 05:31:07 +00005934 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005935 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005936 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005937 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005938 E->getAccessorLoc(),
5939 E->getAccessor());
5940}
Mike Stump11289f42009-09-09 15:08:12 +00005941
Douglas Gregora16548e2009-08-11 05:31:07 +00005942template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005943ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005944TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005945 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005946
John McCall37ad5512010-08-23 06:44:23 +00005947 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005948 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5949 Inits, &InitChanged))
5950 return ExprError();
5951
Douglas Gregora16548e2009-08-11 05:31:07 +00005952 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005953 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005954
Douglas Gregora16548e2009-08-11 05:31:07 +00005955 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005956 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005957}
Mike Stump11289f42009-09-09 15:08:12 +00005958
Douglas Gregora16548e2009-08-11 05:31:07 +00005959template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005960ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005961TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005962 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005963
Douglas Gregorebe10102009-08-20 07:17:43 +00005964 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005965 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005966 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005967 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005968
Douglas Gregorebe10102009-08-20 07:17:43 +00005969 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005970 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005971 bool ExprChanged = false;
5972 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5973 DEnd = E->designators_end();
5974 D != DEnd; ++D) {
5975 if (D->isFieldDesignator()) {
5976 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5977 D->getDotLoc(),
5978 D->getFieldLoc()));
5979 continue;
5980 }
Mike Stump11289f42009-09-09 15:08:12 +00005981
Douglas Gregora16548e2009-08-11 05:31:07 +00005982 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005983 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005984 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005985 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005986
5987 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005988 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005989
Douglas Gregora16548e2009-08-11 05:31:07 +00005990 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5991 ArrayExprs.push_back(Index.release());
5992 continue;
5993 }
Mike Stump11289f42009-09-09 15:08:12 +00005994
Douglas Gregora16548e2009-08-11 05:31:07 +00005995 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00005996 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00005997 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5998 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005999 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006000
John McCalldadc5752010-08-24 06:29:42 +00006001 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006002 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006003 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006004
6005 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006006 End.get(),
6007 D->getLBracketLoc(),
6008 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006009
Douglas Gregora16548e2009-08-11 05:31:07 +00006010 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6011 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00006012
Douglas Gregora16548e2009-08-11 05:31:07 +00006013 ArrayExprs.push_back(Start.release());
6014 ArrayExprs.push_back(End.release());
6015 }
Mike Stump11289f42009-09-09 15:08:12 +00006016
Douglas Gregora16548e2009-08-11 05:31:07 +00006017 if (!getDerived().AlwaysRebuild() &&
6018 Init.get() == E->getInit() &&
6019 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006020 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006021
Douglas Gregora16548e2009-08-11 05:31:07 +00006022 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6023 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006024 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006025}
Mike Stump11289f42009-09-09 15:08:12 +00006026
Douglas Gregora16548e2009-08-11 05:31:07 +00006027template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006028ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006029TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006030 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00006031 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006032
Douglas Gregor3da3c062009-10-28 00:29:27 +00006033 // FIXME: Will we ever have proper type location here? Will we actually
6034 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00006035 QualType T = getDerived().TransformType(E->getType());
6036 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006037 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006038
Douglas Gregora16548e2009-08-11 05:31:07 +00006039 if (!getDerived().AlwaysRebuild() &&
6040 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006041 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006042
Douglas Gregora16548e2009-08-11 05:31:07 +00006043 return getDerived().RebuildImplicitValueInitExpr(T);
6044}
Mike Stump11289f42009-09-09 15:08:12 +00006045
Douglas Gregora16548e2009-08-11 05:31:07 +00006046template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006047ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006048TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00006049 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6050 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006051 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006052
John McCalldadc5752010-08-24 06:29:42 +00006053 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006054 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006055 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006056
Douglas Gregora16548e2009-08-11 05:31:07 +00006057 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00006058 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006059 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006060 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006061
John McCallb268a282010-08-23 23:25:46 +00006062 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00006063 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006064}
6065
6066template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006067ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006068TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006069 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006070 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006071 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6072 &ArgumentChanged))
6073 return ExprError();
6074
Douglas Gregora16548e2009-08-11 05:31:07 +00006075 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6076 move_arg(Inits),
6077 E->getRParenLoc());
6078}
Mike Stump11289f42009-09-09 15:08:12 +00006079
Douglas Gregora16548e2009-08-11 05:31:07 +00006080/// \brief Transform an address-of-label expression.
6081///
6082/// By default, the transformation of an address-of-label expression always
6083/// rebuilds the expression, so that the label identifier can be resolved to
6084/// the corresponding label statement by semantic analysis.
6085template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006086ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006087TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006088 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6089 E->getLabel());
6090 if (!LD)
6091 return ExprError();
6092
Douglas Gregora16548e2009-08-11 05:31:07 +00006093 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006094 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006095}
Mike Stump11289f42009-09-09 15:08:12 +00006096
6097template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006098ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006099TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006100 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006101 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6102 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006103 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006104
Douglas Gregora16548e2009-08-11 05:31:07 +00006105 if (!getDerived().AlwaysRebuild() &&
6106 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006107 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006108
6109 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006110 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006111 E->getRParenLoc());
6112}
Mike Stump11289f42009-09-09 15:08:12 +00006113
Douglas Gregora16548e2009-08-11 05:31:07 +00006114template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006115ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006116TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006117 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006118 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006119 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006120
John McCalldadc5752010-08-24 06:29:42 +00006121 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006122 if (LHS.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 RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006126 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006127 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006128
Douglas Gregora16548e2009-08-11 05:31:07 +00006129 if (!getDerived().AlwaysRebuild() &&
6130 Cond.get() == E->getCond() &&
6131 LHS.get() == E->getLHS() &&
6132 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006133 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006134
Douglas Gregora16548e2009-08-11 05:31:07 +00006135 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006136 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006137 E->getRParenLoc());
6138}
Mike Stump11289f42009-09-09 15:08:12 +00006139
Douglas Gregora16548e2009-08-11 05:31:07 +00006140template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006141ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006142TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006143 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006144}
6145
6146template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006147ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006148TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006149 switch (E->getOperator()) {
6150 case OO_New:
6151 case OO_Delete:
6152 case OO_Array_New:
6153 case OO_Array_Delete:
6154 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006155 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006156
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006157 case OO_Call: {
6158 // This is a call to an object's operator().
6159 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6160
6161 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006162 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006163 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006164 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006165
6166 // FIXME: Poor location information
6167 SourceLocation FakeLParenLoc
6168 = SemaRef.PP.getLocForEndOfToken(
6169 static_cast<Expr *>(Object.get())->getLocEnd());
6170
6171 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006172 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006173 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6174 Args))
6175 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006176
John McCallb268a282010-08-23 23:25:46 +00006177 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006178 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006179 E->getLocEnd());
6180 }
6181
6182#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6183 case OO_##Name:
6184#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6185#include "clang/Basic/OperatorKinds.def"
6186 case OO_Subscript:
6187 // Handled below.
6188 break;
6189
6190 case OO_Conditional:
6191 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006192 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006193
6194 case OO_None:
6195 case NUM_OVERLOADED_OPERATORS:
6196 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006197 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006198 }
6199
John McCalldadc5752010-08-24 06:29:42 +00006200 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006201 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006202 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006203
John McCalldadc5752010-08-24 06:29:42 +00006204 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006205 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006206 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006207
John McCalldadc5752010-08-24 06:29:42 +00006208 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006209 if (E->getNumArgs() == 2) {
6210 Second = getDerived().TransformExpr(E->getArg(1));
6211 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006212 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006213 }
Mike Stump11289f42009-09-09 15:08:12 +00006214
Douglas Gregora16548e2009-08-11 05:31:07 +00006215 if (!getDerived().AlwaysRebuild() &&
6216 Callee.get() == E->getCallee() &&
6217 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006218 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006219 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006220
Douglas Gregora16548e2009-08-11 05:31:07 +00006221 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6222 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006223 Callee.get(),
6224 First.get(),
6225 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006226}
Mike Stump11289f42009-09-09 15:08:12 +00006227
Douglas Gregora16548e2009-08-11 05:31:07 +00006228template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006229ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006230TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6231 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006232}
Mike Stump11289f42009-09-09 15:08:12 +00006233
Douglas Gregora16548e2009-08-11 05:31:07 +00006234template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006235ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006236TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6237 // Transform the callee.
6238 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6239 if (Callee.isInvalid())
6240 return ExprError();
6241
6242 // Transform exec config.
6243 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6244 if (EC.isInvalid())
6245 return ExprError();
6246
6247 // Transform arguments.
6248 bool ArgChanged = false;
6249 ASTOwningVector<Expr*> Args(SemaRef);
6250 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6251 &ArgChanged))
6252 return ExprError();
6253
6254 if (!getDerived().AlwaysRebuild() &&
6255 Callee.get() == E->getCallee() &&
6256 !ArgChanged)
6257 return SemaRef.Owned(E);
6258
6259 // FIXME: Wrong source location information for the '('.
6260 SourceLocation FakeLParenLoc
6261 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6262 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6263 move_arg(Args),
6264 E->getRParenLoc(), EC.get());
6265}
6266
6267template<typename Derived>
6268ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006269TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006270 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6271 if (!Type)
6272 return ExprError();
6273
John McCalldadc5752010-08-24 06:29:42 +00006274 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006275 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006276 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006277 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006278
Douglas Gregora16548e2009-08-11 05:31:07 +00006279 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006280 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006281 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006282 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006283
Douglas Gregora16548e2009-08-11 05:31:07 +00006284 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006285 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006286 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6287 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6288 SourceLocation FakeRParenLoc
6289 = SemaRef.PP.getLocForEndOfToken(
6290 E->getSubExpr()->getSourceRange().getEnd());
6291 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006292 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006293 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006294 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006295 FakeRAngleLoc,
6296 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006297 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006298 FakeRParenLoc);
6299}
Mike Stump11289f42009-09-09 15:08:12 +00006300
Douglas Gregora16548e2009-08-11 05:31:07 +00006301template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006302ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006303TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6304 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006305}
Mike Stump11289f42009-09-09 15:08:12 +00006306
6307template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006308ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006309TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6310 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006311}
6312
Douglas Gregora16548e2009-08-11 05:31:07 +00006313template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006314ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006315TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006316 CXXReinterpretCastExpr *E) {
6317 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006318}
Mike Stump11289f42009-09-09 15:08:12 +00006319
Douglas Gregora16548e2009-08-11 05:31:07 +00006320template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006321ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006322TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6323 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006324}
Mike Stump11289f42009-09-09 15:08:12 +00006325
Douglas Gregora16548e2009-08-11 05:31:07 +00006326template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006327ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006328TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006329 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006330 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6331 if (!Type)
6332 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006333
John McCalldadc5752010-08-24 06:29:42 +00006334 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006335 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006336 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006337 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006338
Douglas Gregora16548e2009-08-11 05:31:07 +00006339 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006340 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006341 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006342 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006343
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006344 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006345 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006346 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006347 E->getRParenLoc());
6348}
Mike Stump11289f42009-09-09 15:08:12 +00006349
Douglas Gregora16548e2009-08-11 05:31:07 +00006350template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006351ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006352TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006353 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006354 TypeSourceInfo *TInfo
6355 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6356 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006357 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006358
Douglas Gregora16548e2009-08-11 05:31:07 +00006359 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006360 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006361 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006362
Douglas Gregor9da64192010-04-26 22:37:10 +00006363 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6364 E->getLocStart(),
6365 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006366 E->getLocEnd());
6367 }
Mike Stump11289f42009-09-09 15:08:12 +00006368
Douglas Gregora16548e2009-08-11 05:31:07 +00006369 // We don't know whether the expression is potentially evaluated until
6370 // after we perform semantic analysis, so the expression is potentially
6371 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006372 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006373 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006374
John McCalldadc5752010-08-24 06:29:42 +00006375 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006376 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006377 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006378
Douglas Gregora16548e2009-08-11 05:31:07 +00006379 if (!getDerived().AlwaysRebuild() &&
6380 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006381 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006382
Douglas Gregor9da64192010-04-26 22:37:10 +00006383 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6384 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006385 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006386 E->getLocEnd());
6387}
6388
6389template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006390ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006391TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6392 if (E->isTypeOperand()) {
6393 TypeSourceInfo *TInfo
6394 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6395 if (!TInfo)
6396 return ExprError();
6397
6398 if (!getDerived().AlwaysRebuild() &&
6399 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006400 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006401
6402 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6403 E->getLocStart(),
6404 TInfo,
6405 E->getLocEnd());
6406 }
6407
6408 // We don't know whether the expression is potentially evaluated until
6409 // after we perform semantic analysis, so the expression is potentially
6410 // potentially evaluated.
6411 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6412
6413 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6414 if (SubExpr.isInvalid())
6415 return ExprError();
6416
6417 if (!getDerived().AlwaysRebuild() &&
6418 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006419 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006420
6421 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6422 E->getLocStart(),
6423 SubExpr.get(),
6424 E->getLocEnd());
6425}
6426
6427template<typename Derived>
6428ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006429TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006430 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006431}
Mike Stump11289f42009-09-09 15:08:12 +00006432
Douglas Gregora16548e2009-08-11 05:31:07 +00006433template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006434ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006435TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006436 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006437 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006438}
Mike Stump11289f42009-09-09 15:08:12 +00006439
Douglas Gregora16548e2009-08-11 05:31:07 +00006440template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006441ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006442TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006443 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6444 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6445 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006446
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006447 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006448 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006449
Douglas Gregorb15af892010-01-07 23:12:05 +00006450 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006451}
Mike Stump11289f42009-09-09 15:08:12 +00006452
Douglas Gregora16548e2009-08-11 05:31:07 +00006453template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006454ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006455TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006456 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006457 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006458 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006459
Douglas Gregora16548e2009-08-11 05:31:07 +00006460 if (!getDerived().AlwaysRebuild() &&
6461 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006462 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006463
John McCallb268a282010-08-23 23:25:46 +00006464 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006465}
Mike Stump11289f42009-09-09 15:08:12 +00006466
Douglas Gregora16548e2009-08-11 05:31:07 +00006467template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006468ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006469TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006470 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006471 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6472 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006473 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006474 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006475
Chandler Carruth794da4c2010-02-08 06:42:49 +00006476 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006477 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006478 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006479
Douglas Gregor033f6752009-12-23 23:03:06 +00006480 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006481}
Mike Stump11289f42009-09-09 15:08:12 +00006482
Douglas Gregora16548e2009-08-11 05:31:07 +00006483template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006484ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006485TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6486 CXXScalarValueInitExpr *E) {
6487 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6488 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006489 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006490
Douglas Gregora16548e2009-08-11 05:31:07 +00006491 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006492 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006493 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006494
Douglas Gregor2b88c112010-09-08 00:15:04 +00006495 return getDerived().RebuildCXXScalarValueInitExpr(T,
6496 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006497 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006498}
Mike Stump11289f42009-09-09 15:08:12 +00006499
Douglas Gregora16548e2009-08-11 05:31:07 +00006500template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006501ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006502TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006503 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006504 TypeSourceInfo *AllocTypeInfo
6505 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6506 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006507 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006508
Douglas Gregora16548e2009-08-11 05:31:07 +00006509 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006510 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006511 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006512 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006513
Douglas Gregora16548e2009-08-11 05:31:07 +00006514 // Transform the placement arguments (if any).
6515 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006516 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006517 if (getDerived().TransformExprs(E->getPlacementArgs(),
6518 E->getNumPlacementArgs(), true,
6519 PlacementArgs, &ArgumentChanged))
6520 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006521
Douglas Gregorebe10102009-08-20 07:17:43 +00006522 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006523 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006524 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6525 ConstructorArgs, &ArgumentChanged))
6526 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006527
Douglas Gregord2d9da02010-02-26 00:38:10 +00006528 // Transform constructor, new operator, and delete operator.
6529 CXXConstructorDecl *Constructor = 0;
6530 if (E->getConstructor()) {
6531 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006532 getDerived().TransformDecl(E->getLocStart(),
6533 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006534 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006535 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006536 }
6537
6538 FunctionDecl *OperatorNew = 0;
6539 if (E->getOperatorNew()) {
6540 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006541 getDerived().TransformDecl(E->getLocStart(),
6542 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006543 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006544 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006545 }
6546
6547 FunctionDecl *OperatorDelete = 0;
6548 if (E->getOperatorDelete()) {
6549 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006550 getDerived().TransformDecl(E->getLocStart(),
6551 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006552 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006553 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006554 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006555
Douglas Gregora16548e2009-08-11 05:31:07 +00006556 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006557 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006558 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006559 Constructor == E->getConstructor() &&
6560 OperatorNew == E->getOperatorNew() &&
6561 OperatorDelete == E->getOperatorDelete() &&
6562 !ArgumentChanged) {
6563 // Mark any declarations we need as referenced.
6564 // FIXME: instantiation-specific.
6565 if (Constructor)
6566 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6567 if (OperatorNew)
6568 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6569 if (OperatorDelete)
6570 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006571 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006572 }
Mike Stump11289f42009-09-09 15:08:12 +00006573
Douglas Gregor0744ef62010-09-07 21:49:58 +00006574 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006575 if (!ArraySize.get()) {
6576 // If no array size was specified, but the new expression was
6577 // instantiated with an array type (e.g., "new T" where T is
6578 // instantiated with "int[4]"), extract the outer bound from the
6579 // array type as our array size. We do this with constant and
6580 // dependently-sized array types.
6581 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6582 if (!ArrayT) {
6583 // Do nothing
6584 } else if (const ConstantArrayType *ConsArrayT
6585 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006586 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006587 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6588 ConsArrayT->getSize(),
6589 SemaRef.Context.getSizeType(),
6590 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006591 AllocType = ConsArrayT->getElementType();
6592 } else if (const DependentSizedArrayType *DepArrayT
6593 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6594 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006595 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006596 AllocType = DepArrayT->getElementType();
6597 }
6598 }
6599 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006600
Douglas Gregora16548e2009-08-11 05:31:07 +00006601 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6602 E->isGlobalNew(),
6603 /*FIXME:*/E->getLocStart(),
6604 move_arg(PlacementArgs),
6605 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006606 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006607 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006608 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006609 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006610 /*FIXME:*/E->getLocStart(),
6611 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006612 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006613}
Mike Stump11289f42009-09-09 15:08:12 +00006614
Douglas Gregora16548e2009-08-11 05:31:07 +00006615template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006616ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006617TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006618 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006619 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006620 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006621
Douglas Gregord2d9da02010-02-26 00:38:10 +00006622 // Transform the delete operator, if known.
6623 FunctionDecl *OperatorDelete = 0;
6624 if (E->getOperatorDelete()) {
6625 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006626 getDerived().TransformDecl(E->getLocStart(),
6627 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006628 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006629 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006630 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006631
Douglas Gregora16548e2009-08-11 05:31:07 +00006632 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006633 Operand.get() == E->getArgument() &&
6634 OperatorDelete == E->getOperatorDelete()) {
6635 // Mark any declarations we need as referenced.
6636 // FIXME: instantiation-specific.
6637 if (OperatorDelete)
6638 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006639
6640 if (!E->getArgument()->isTypeDependent()) {
6641 QualType Destroyed = SemaRef.Context.getBaseElementType(
6642 E->getDestroyedType());
6643 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6644 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6645 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6646 SemaRef.LookupDestructor(Record));
6647 }
6648 }
6649
John McCallc3007a22010-10-26 07:05:15 +00006650 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006651 }
Mike Stump11289f42009-09-09 15:08:12 +00006652
Douglas Gregora16548e2009-08-11 05:31:07 +00006653 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6654 E->isGlobalDelete(),
6655 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006656 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006657}
Mike Stump11289f42009-09-09 15:08:12 +00006658
Douglas Gregora16548e2009-08-11 05:31:07 +00006659template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006660ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006661TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006662 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006663 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006664 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006665 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006666
John McCallba7bf592010-08-24 05:47:05 +00006667 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006668 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006669 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006670 E->getOperatorLoc(),
6671 E->isArrow()? tok::arrow : tok::period,
6672 ObjectTypePtr,
6673 MayBePseudoDestructor);
6674 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006675 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006676
John McCallba7bf592010-08-24 05:47:05 +00006677 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00006678 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6679 if (QualifierLoc) {
6680 QualifierLoc
6681 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6682 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00006683 return ExprError();
6684 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00006685 CXXScopeSpec SS;
6686 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00006687
Douglas Gregor678f90d2010-02-25 01:56:36 +00006688 PseudoDestructorTypeStorage Destroyed;
6689 if (E->getDestroyedTypeInfo()) {
6690 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006691 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006692 ObjectType, 0,
6693 QualifierLoc.getNestedNameSpecifier());
Douglas Gregor678f90d2010-02-25 01:56:36 +00006694 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006695 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006696 Destroyed = DestroyedTypeInfo;
6697 } else if (ObjectType->isDependentType()) {
6698 // We aren't likely to be able to resolve the identifier down to a type
6699 // now anyway, so just retain the identifier.
6700 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6701 E->getDestroyedTypeLoc());
6702 } else {
6703 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00006704 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006705 *E->getDestroyedTypeIdentifier(),
6706 E->getDestroyedTypeLoc(),
6707 /*Scope=*/0,
6708 SS, ObjectTypePtr,
6709 false);
6710 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006711 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006712
Douglas Gregor678f90d2010-02-25 01:56:36 +00006713 Destroyed
6714 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6715 E->getDestroyedTypeLoc());
6716 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006717
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006718 TypeSourceInfo *ScopeTypeInfo = 0;
6719 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006720 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006721 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006722 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006723 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006724
John McCallb268a282010-08-23 23:25:46 +00006725 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006726 E->getOperatorLoc(),
6727 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006728 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006729 ScopeTypeInfo,
6730 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006731 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006732 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006733}
Mike Stump11289f42009-09-09 15:08:12 +00006734
Douglas Gregorad8a3362009-09-04 17:36:40 +00006735template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006736ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006737TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006738 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006739 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6740
6741 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6742 Sema::LookupOrdinaryName);
6743
6744 // Transform all the decls.
6745 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6746 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006747 NamedDecl *InstD = static_cast<NamedDecl*>(
6748 getDerived().TransformDecl(Old->getNameLoc(),
6749 *I));
John McCall84d87672009-12-10 09:41:52 +00006750 if (!InstD) {
6751 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6752 // This can happen because of dependent hiding.
6753 if (isa<UsingShadowDecl>(*I))
6754 continue;
6755 else
John McCallfaf5fb42010-08-26 23:41:50 +00006756 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006757 }
John McCalle66edc12009-11-24 19:00:30 +00006758
6759 // Expand using declarations.
6760 if (isa<UsingDecl>(InstD)) {
6761 UsingDecl *UD = cast<UsingDecl>(InstD);
6762 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6763 E = UD->shadow_end(); I != E; ++I)
6764 R.addDecl(*I);
6765 continue;
6766 }
6767
6768 R.addDecl(InstD);
6769 }
6770
6771 // Resolve a kind, but don't do any further analysis. If it's
6772 // ambiguous, the callee needs to deal with it.
6773 R.resolveKind();
6774
6775 // Rebuild the nested-name qualifier, if present.
6776 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00006777 if (Old->getQualifierLoc()) {
6778 NestedNameSpecifierLoc QualifierLoc
6779 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
6780 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006781 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006782
Douglas Gregor0da1d432011-02-28 20:01:57 +00006783 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006784 }
6785
Douglas Gregor9262f472010-04-27 18:19:34 +00006786 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006787 CXXRecordDecl *NamingClass
6788 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6789 Old->getNameLoc(),
6790 Old->getNamingClass()));
6791 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006792 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006793
Douglas Gregorda7be082010-04-27 16:10:10 +00006794 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006795 }
6796
6797 // If we have no template arguments, it's a normal declaration name.
6798 if (!Old->hasExplicitTemplateArgs())
6799 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6800
6801 // If we have template arguments, rebuild them, then rebuild the
6802 // templateid expression.
6803 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006804 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6805 Old->getNumTemplateArgs(),
6806 TransArgs))
6807 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006808
6809 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6810 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006811}
Mike Stump11289f42009-09-09 15:08:12 +00006812
Douglas Gregora16548e2009-08-11 05:31:07 +00006813template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006814ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006815TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006816 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6817 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006818 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006819
Douglas Gregora16548e2009-08-11 05:31:07 +00006820 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006821 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006822 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006823
Mike Stump11289f42009-09-09 15:08:12 +00006824 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006825 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006826 T,
6827 E->getLocEnd());
6828}
Mike Stump11289f42009-09-09 15:08:12 +00006829
Douglas Gregora16548e2009-08-11 05:31:07 +00006830template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006831ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006832TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6833 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6834 if (!LhsT)
6835 return ExprError();
6836
6837 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6838 if (!RhsT)
6839 return ExprError();
6840
6841 if (!getDerived().AlwaysRebuild() &&
6842 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6843 return SemaRef.Owned(E);
6844
6845 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6846 E->getLocStart(),
6847 LhsT, RhsT,
6848 E->getLocEnd());
6849}
6850
6851template<typename Derived>
6852ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006853TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006854 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006855 NestedNameSpecifierLoc QualifierLoc
6856 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6857 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006858 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006859
John McCall31f82722010-11-12 08:19:04 +00006860 // TODO: If this is a conversion-function-id, verify that the
6861 // destination type name (if present) resolves the same way after
6862 // instantiation as it did in the local scope.
6863
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006864 DeclarationNameInfo NameInfo
6865 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6866 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006867 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006868
John McCalle66edc12009-11-24 19:00:30 +00006869 if (!E->hasExplicitTemplateArgs()) {
6870 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006871 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006872 // Note: it is sufficient to compare the Name component of NameInfo:
6873 // if name has not changed, DNLoc has not changed either.
6874 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006875 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006876
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006877 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006878 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006879 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006880 }
John McCall6b51f282009-11-23 01:53:49 +00006881
6882 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006883 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6884 E->getNumTemplateArgs(),
6885 TransArgs))
6886 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006887
Douglas Gregor3a43fd62011-02-25 20:49:16 +00006888 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006889 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006890 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006891}
6892
6893template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006894ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006895TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006896 // CXXConstructExprs are always implicit, so when we have a
6897 // 1-argument construction we just transform that argument.
6898 if (E->getNumArgs() == 1 ||
6899 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6900 return getDerived().TransformExpr(E->getArg(0));
6901
Douglas Gregora16548e2009-08-11 05:31:07 +00006902 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6903
6904 QualType T = getDerived().TransformType(E->getType());
6905 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006906 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006907
6908 CXXConstructorDecl *Constructor
6909 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006910 getDerived().TransformDecl(E->getLocStart(),
6911 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006912 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006913 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006914
Douglas Gregora16548e2009-08-11 05:31:07 +00006915 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006916 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006917 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6918 &ArgumentChanged))
6919 return ExprError();
6920
Douglas Gregora16548e2009-08-11 05:31:07 +00006921 if (!getDerived().AlwaysRebuild() &&
6922 T == E->getType() &&
6923 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006924 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006925 // Mark the constructor as referenced.
6926 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006927 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006928 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006929 }
Mike Stump11289f42009-09-09 15:08:12 +00006930
Douglas Gregordb121ba2009-12-14 16:27:04 +00006931 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6932 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006933 move_arg(Args),
6934 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006935 E->getConstructionKind(),
6936 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006937}
Mike Stump11289f42009-09-09 15:08:12 +00006938
Douglas Gregora16548e2009-08-11 05:31:07 +00006939/// \brief Transform a C++ temporary-binding expression.
6940///
Douglas Gregor363b1512009-12-24 18:51:59 +00006941/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6942/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006943template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006944ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006945TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006946 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006947}
Mike Stump11289f42009-09-09 15:08:12 +00006948
John McCall5d413782010-12-06 08:20:24 +00006949/// \brief Transform a C++ expression that contains cleanups that should
6950/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006951///
John McCall5d413782010-12-06 08:20:24 +00006952/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006953/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006954template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006955ExprResult
John McCall5d413782010-12-06 08:20:24 +00006956TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006957 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006958}
Mike Stump11289f42009-09-09 15:08:12 +00006959
Douglas Gregora16548e2009-08-11 05:31:07 +00006960template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006961ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006962TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006963 CXXTemporaryObjectExpr *E) {
6964 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6965 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006966 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006967
Douglas Gregora16548e2009-08-11 05:31:07 +00006968 CXXConstructorDecl *Constructor
6969 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006970 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006971 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006972 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006973 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006974
Douglas Gregora16548e2009-08-11 05:31:07 +00006975 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006976 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006977 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00006978 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6979 &ArgumentChanged))
6980 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006981
Douglas Gregora16548e2009-08-11 05:31:07 +00006982 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006983 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006984 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006985 !ArgumentChanged) {
6986 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006987 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006988 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006989 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006990
6991 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6992 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006993 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006994 E->getLocEnd());
6995}
Mike Stump11289f42009-09-09 15:08:12 +00006996
Douglas Gregora16548e2009-08-11 05:31:07 +00006997template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006998ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006999TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007000 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00007001 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7002 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007003 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007004
Douglas Gregora16548e2009-08-11 05:31:07 +00007005 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007006 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007007 Args.reserve(E->arg_size());
7008 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7009 &ArgumentChanged))
7010 return ExprError();
7011
Douglas Gregora16548e2009-08-11 05:31:07 +00007012 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007013 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007014 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007015 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007016
Douglas Gregora16548e2009-08-11 05:31:07 +00007017 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00007018 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00007019 E->getLParenLoc(),
7020 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007021 E->getRParenLoc());
7022}
Mike Stump11289f42009-09-09 15:08:12 +00007023
Douglas Gregora16548e2009-08-11 05:31:07 +00007024template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007025ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007026TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007027 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007028 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007029 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007030 Expr *OldBase;
7031 QualType BaseType;
7032 QualType ObjectType;
7033 if (!E->isImplicitAccess()) {
7034 OldBase = E->getBase();
7035 Base = getDerived().TransformExpr(OldBase);
7036 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007037 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007038
John McCall2d74de92009-12-01 22:10:20 +00007039 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00007040 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00007041 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007042 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007043 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007044 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00007045 ObjectTy,
7046 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00007047 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007048 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007049
John McCallba7bf592010-08-24 05:47:05 +00007050 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00007051 BaseType = ((Expr*) Base.get())->getType();
7052 } else {
7053 OldBase = 0;
7054 BaseType = getDerived().TransformType(E->getBaseType());
7055 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7056 }
Mike Stump11289f42009-09-09 15:08:12 +00007057
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007058 // Transform the first part of the nested-name-specifier that qualifies
7059 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007060 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007061 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00007062 E->getFirstQualifierFoundInScope(),
7063 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00007064
Douglas Gregore16af532011-02-28 18:50:33 +00007065 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007066 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00007067 QualifierLoc
7068 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7069 ObjectType,
7070 FirstQualifierInScope);
7071 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007072 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007073 }
Mike Stump11289f42009-09-09 15:08:12 +00007074
John McCall31f82722010-11-12 08:19:04 +00007075 // TODO: If this is a conversion-function-id, verify that the
7076 // destination type name (if present) resolves the same way after
7077 // instantiation as it did in the local scope.
7078
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007079 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007080 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007081 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007082 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007083
John McCall2d74de92009-12-01 22:10:20 +00007084 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007085 // This is a reference to a member without an explicitly-specified
7086 // template argument list. Optimize for this common case.
7087 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007088 Base.get() == OldBase &&
7089 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007090 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007091 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007092 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007093 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007094
John McCallb268a282010-08-23 23:25:46 +00007095 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007096 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007097 E->isArrow(),
7098 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007099 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007100 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007101 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007102 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007103 }
7104
John McCall6b51f282009-11-23 01:53:49 +00007105 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007106 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7107 E->getNumTemplateArgs(),
7108 TransArgs))
7109 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007110
John McCallb268a282010-08-23 23:25:46 +00007111 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007112 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007113 E->isArrow(),
7114 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007115 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007116 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007117 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007118 &TransArgs);
7119}
7120
7121template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007122ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007123TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007124 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007125 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007126 QualType BaseType;
7127 if (!Old->isImplicitAccess()) {
7128 Base = getDerived().TransformExpr(Old->getBase());
7129 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007130 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007131 BaseType = ((Expr*) Base.get())->getType();
7132 } else {
7133 BaseType = getDerived().TransformType(Old->getBaseType());
7134 }
John McCall10eae182009-11-30 22:42:35 +00007135
Douglas Gregor0da1d432011-02-28 20:01:57 +00007136 NestedNameSpecifierLoc QualifierLoc;
7137 if (Old->getQualifierLoc()) {
7138 QualifierLoc
7139 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7140 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007141 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007142 }
7143
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007144 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007145 Sema::LookupOrdinaryName);
7146
7147 // Transform all the decls.
7148 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7149 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007150 NamedDecl *InstD = static_cast<NamedDecl*>(
7151 getDerived().TransformDecl(Old->getMemberLoc(),
7152 *I));
John McCall84d87672009-12-10 09:41:52 +00007153 if (!InstD) {
7154 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7155 // This can happen because of dependent hiding.
7156 if (isa<UsingShadowDecl>(*I))
7157 continue;
7158 else
John McCallfaf5fb42010-08-26 23:41:50 +00007159 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00007160 }
John McCall10eae182009-11-30 22:42:35 +00007161
7162 // Expand using declarations.
7163 if (isa<UsingDecl>(InstD)) {
7164 UsingDecl *UD = cast<UsingDecl>(InstD);
7165 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7166 E = UD->shadow_end(); I != E; ++I)
7167 R.addDecl(*I);
7168 continue;
7169 }
7170
7171 R.addDecl(InstD);
7172 }
7173
7174 R.resolveKind();
7175
Douglas Gregor9262f472010-04-27 18:19:34 +00007176 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007177 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007178 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007179 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007180 Old->getMemberLoc(),
7181 Old->getNamingClass()));
7182 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007183 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007184
Douglas Gregorda7be082010-04-27 16:10:10 +00007185 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007186 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007187
John McCall10eae182009-11-30 22:42:35 +00007188 TemplateArgumentListInfo TransArgs;
7189 if (Old->hasExplicitTemplateArgs()) {
7190 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7191 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007192 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7193 Old->getNumTemplateArgs(),
7194 TransArgs))
7195 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007196 }
John McCall38836f02010-01-15 08:34:02 +00007197
7198 // FIXME: to do this check properly, we will need to preserve the
7199 // first-qualifier-in-scope here, just in case we had a dependent
7200 // base (and therefore couldn't do the check) and a
7201 // nested-name-qualifier (and therefore could do the lookup).
7202 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007203
John McCallb268a282010-08-23 23:25:46 +00007204 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007205 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007206 Old->getOperatorLoc(),
7207 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007208 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007209 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007210 R,
7211 (Old->hasExplicitTemplateArgs()
7212 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007213}
7214
7215template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007216ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007217TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7218 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7219 if (SubExpr.isInvalid())
7220 return ExprError();
7221
7222 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007223 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007224
7225 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7226}
7227
7228template<typename Derived>
7229ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007230TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007231 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7232 if (Pattern.isInvalid())
7233 return ExprError();
7234
7235 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7236 return SemaRef.Owned(E);
7237
Douglas Gregorb8840002011-01-14 21:20:45 +00007238 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7239 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007240}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007241
7242template<typename Derived>
7243ExprResult
7244TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7245 // If E is not value-dependent, then nothing will change when we transform it.
7246 // Note: This is an instantiation-centric view.
7247 if (!E->isValueDependent())
7248 return SemaRef.Owned(E);
7249
7250 // Note: None of the implementations of TryExpandParameterPacks can ever
7251 // produce a diagnostic when given only a single unexpanded parameter pack,
7252 // so
7253 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7254 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007255 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007256 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007257 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7258 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007259 ShouldExpand, RetainExpansion,
7260 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007261 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007262
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007263 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007264 return SemaRef.Owned(E);
7265
7266 // We now know the length of the parameter pack, so build a new expression
7267 // that stores that length.
7268 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7269 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007270 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007271}
7272
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007273template<typename Derived>
7274ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007275TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7276 SubstNonTypeTemplateParmPackExpr *E) {
7277 // Default behavior is to do nothing with this transformation.
7278 return SemaRef.Owned(E);
7279}
7280
7281template<typename Derived>
7282ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007283TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007284 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007285}
7286
Mike Stump11289f42009-09-09 15:08:12 +00007287template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007288ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007289TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007290 TypeSourceInfo *EncodedTypeInfo
7291 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7292 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007293 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007294
Douglas Gregora16548e2009-08-11 05:31:07 +00007295 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007296 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007297 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007298
7299 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007300 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007301 E->getRParenLoc());
7302}
Mike Stump11289f42009-09-09 15:08:12 +00007303
Douglas Gregora16548e2009-08-11 05:31:07 +00007304template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007305ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007306TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007307 // Transform arguments.
7308 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007309 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007310 Args.reserve(E->getNumArgs());
7311 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7312 &ArgChanged))
7313 return ExprError();
7314
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007315 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7316 // Class message: transform the receiver type.
7317 TypeSourceInfo *ReceiverTypeInfo
7318 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7319 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007320 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007321
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007322 // If nothing changed, just retain the existing message send.
7323 if (!getDerived().AlwaysRebuild() &&
7324 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007325 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007326
7327 // Build a new class message send.
7328 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7329 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007330 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007331 E->getMethodDecl(),
7332 E->getLeftLoc(),
7333 move_arg(Args),
7334 E->getRightLoc());
7335 }
7336
7337 // Instance message: transform the receiver
7338 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7339 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007340 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007341 = getDerived().TransformExpr(E->getInstanceReceiver());
7342 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007343 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007344
7345 // If nothing changed, just retain the existing message send.
7346 if (!getDerived().AlwaysRebuild() &&
7347 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007348 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007349
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007350 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007351 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007352 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007353 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007354 E->getMethodDecl(),
7355 E->getLeftLoc(),
7356 move_arg(Args),
7357 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007358}
7359
Mike Stump11289f42009-09-09 15:08:12 +00007360template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007361ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007362TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007363 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007364}
7365
Mike Stump11289f42009-09-09 15:08:12 +00007366template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007367ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007368TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007369 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007370}
7371
Mike Stump11289f42009-09-09 15:08:12 +00007372template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007373ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007374TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007375 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007376 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007377 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007378 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007379
7380 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007381
Douglas Gregord51d90d2010-04-26 20:11:03 +00007382 // If nothing changed, just retain the existing expression.
7383 if (!getDerived().AlwaysRebuild() &&
7384 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007385 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007386
John McCallb268a282010-08-23 23:25:46 +00007387 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007388 E->getLocation(),
7389 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007390}
7391
Mike Stump11289f42009-09-09 15:08:12 +00007392template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007393ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007394TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007395 // 'super' and types never change. Property never changes. Just
7396 // retain the existing expression.
7397 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007398 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007399
Douglas Gregor9faee212010-04-26 20:47:02 +00007400 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007401 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007402 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007403 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007404
Douglas Gregor9faee212010-04-26 20:47:02 +00007405 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007406
Douglas Gregor9faee212010-04-26 20:47:02 +00007407 // If nothing changed, just retain the existing expression.
7408 if (!getDerived().AlwaysRebuild() &&
7409 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007410 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007411
John McCallb7bd14f2010-12-02 01:19:52 +00007412 if (E->isExplicitProperty())
7413 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7414 E->getExplicitProperty(),
7415 E->getLocation());
7416
7417 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7418 E->getType(),
7419 E->getImplicitPropertyGetter(),
7420 E->getImplicitPropertySetter(),
7421 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007422}
7423
Mike Stump11289f42009-09-09 15:08:12 +00007424template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007425ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007426TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007427 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007428 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007429 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007430 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007431
Douglas Gregord51d90d2010-04-26 20:11:03 +00007432 // If nothing changed, just retain the existing expression.
7433 if (!getDerived().AlwaysRebuild() &&
7434 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007435 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007436
John McCallb268a282010-08-23 23:25:46 +00007437 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007438 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007439}
7440
Mike Stump11289f42009-09-09 15:08:12 +00007441template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007442ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007443TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007444 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007445 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007446 SubExprs.reserve(E->getNumSubExprs());
7447 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7448 SubExprs, &ArgumentChanged))
7449 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007450
Douglas Gregora16548e2009-08-11 05:31:07 +00007451 if (!getDerived().AlwaysRebuild() &&
7452 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007453 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007454
Douglas Gregora16548e2009-08-11 05:31:07 +00007455 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7456 move_arg(SubExprs),
7457 E->getRParenLoc());
7458}
7459
Mike Stump11289f42009-09-09 15:08:12 +00007460template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007461ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007462TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007463 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007464
John McCall490112f2011-02-04 18:33:18 +00007465 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7466 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7467
7468 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7469 llvm::SmallVector<ParmVarDecl*, 4> params;
7470 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007471
7472 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007473 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7474 oldBlock->param_begin(),
7475 oldBlock->param_size(),
7476 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007477 return true;
John McCall490112f2011-02-04 18:33:18 +00007478
7479 const FunctionType *exprFunctionType = E->getFunctionType();
7480 QualType exprResultType = exprFunctionType->getResultType();
7481 if (!exprResultType.isNull()) {
7482 if (!exprResultType->isDependentType())
7483 blockScope->ReturnType = exprResultType;
7484 else if (exprResultType != getSema().Context.DependentTy)
7485 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007486 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007487
7488 // If the return type has not been determined yet, leave it as a dependent
7489 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007490 if (blockScope->ReturnType.isNull())
7491 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007492
7493 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007494 if (blockScope->ReturnType->isObjCObjectType()) {
7495 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007496 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007497 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007498 return ExprError();
7499 }
John McCall3882ace2011-01-05 12:14:39 +00007500
John McCall490112f2011-02-04 18:33:18 +00007501 QualType functionType = getDerived().RebuildFunctionProtoType(
7502 blockScope->ReturnType,
7503 paramTypes.data(),
7504 paramTypes.size(),
7505 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007506 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007507 exprFunctionType->getExtInfo());
7508 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007509
7510 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007511 if (!params.empty())
7512 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007513
7514 // If the return type wasn't explicitly set, it will have been marked as a
7515 // dependent type (DependentTy); clear out the return type setting so
7516 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007517 if (blockScope->ReturnType == getSema().Context.DependentTy)
7518 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007519
John McCall3882ace2011-01-05 12:14:39 +00007520 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007521 StmtResult body = getDerived().TransformStmt(E->getBody());
7522 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007523 return ExprError();
7524
John McCall490112f2011-02-04 18:33:18 +00007525#ifndef NDEBUG
7526 // In builds with assertions, make sure that we captured everything we
7527 // captured before.
7528
7529 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7530
7531 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7532 e = oldBlock->capture_end(); i != e; ++i) {
John McCall351762c2011-02-07 10:33:21 +00007533 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007534
7535 // Ignore parameter packs.
7536 if (isa<ParmVarDecl>(oldCapture) &&
7537 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7538 continue;
7539
7540 VarDecl *newCapture =
7541 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7542 oldCapture));
John McCall351762c2011-02-07 10:33:21 +00007543 assert(blockScope->CaptureMap.count(newCapture));
John McCall490112f2011-02-04 18:33:18 +00007544 }
7545#endif
7546
7547 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7548 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007549}
7550
Mike Stump11289f42009-09-09 15:08:12 +00007551template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007552ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007553TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007554 ValueDecl *ND
7555 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7556 E->getDecl()));
7557 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007558 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007559
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007560 if (!getDerived().AlwaysRebuild() &&
7561 ND == E->getDecl()) {
7562 // Mark it referenced in the new context regardless.
7563 // FIXME: this is a bit instantiation-specific.
7564 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7565
John McCallc3007a22010-10-26 07:05:15 +00007566 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007567 }
7568
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007569 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00007570 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007571 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007572}
Mike Stump11289f42009-09-09 15:08:12 +00007573
Douglas Gregora16548e2009-08-11 05:31:07 +00007574//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007575// Type reconstruction
7576//===----------------------------------------------------------------------===//
7577
Mike Stump11289f42009-09-09 15:08:12 +00007578template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007579QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7580 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007581 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007582 getDerived().getBaseEntity());
7583}
7584
Mike Stump11289f42009-09-09 15:08:12 +00007585template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007586QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7587 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007588 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007589 getDerived().getBaseEntity());
7590}
7591
Mike Stump11289f42009-09-09 15:08:12 +00007592template<typename Derived>
7593QualType
John McCall70dd5f62009-10-30 00:06:24 +00007594TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7595 bool WrittenAsLValue,
7596 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007597 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007598 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007599}
7600
7601template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007602QualType
John McCall70dd5f62009-10-30 00:06:24 +00007603TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7604 QualType ClassType,
7605 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007606 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007607 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007608}
7609
7610template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007611QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007612TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7613 ArrayType::ArraySizeModifier SizeMod,
7614 const llvm::APInt *Size,
7615 Expr *SizeExpr,
7616 unsigned IndexTypeQuals,
7617 SourceRange BracketsRange) {
7618 if (SizeExpr || !Size)
7619 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7620 IndexTypeQuals, BracketsRange,
7621 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007622
7623 QualType Types[] = {
7624 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7625 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7626 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007627 };
7628 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7629 QualType SizeType;
7630 for (unsigned I = 0; I != NumTypes; ++I)
7631 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7632 SizeType = Types[I];
7633 break;
7634 }
Mike Stump11289f42009-09-09 15:08:12 +00007635
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007636 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7637 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007638 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007639 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007640 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007641}
Mike Stump11289f42009-09-09 15:08:12 +00007642
Douglas Gregord6ff3322009-08-04 16:50:30 +00007643template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007644QualType
7645TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007646 ArrayType::ArraySizeModifier SizeMod,
7647 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007648 unsigned IndexTypeQuals,
7649 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007650 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007651 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007652}
7653
7654template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007655QualType
Mike Stump11289f42009-09-09 15:08:12 +00007656TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007657 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007658 unsigned IndexTypeQuals,
7659 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007660 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007661 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007662}
Mike Stump11289f42009-09-09 15:08:12 +00007663
Douglas Gregord6ff3322009-08-04 16:50:30 +00007664template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007665QualType
7666TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007667 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007668 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007669 unsigned IndexTypeQuals,
7670 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007671 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007672 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007673 IndexTypeQuals, BracketsRange);
7674}
7675
7676template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007677QualType
7678TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007679 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007680 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007681 unsigned IndexTypeQuals,
7682 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007683 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007684 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007685 IndexTypeQuals, BracketsRange);
7686}
7687
7688template<typename Derived>
7689QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007690 unsigned NumElements,
7691 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007692 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007693 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007694}
Mike Stump11289f42009-09-09 15:08:12 +00007695
Douglas Gregord6ff3322009-08-04 16:50:30 +00007696template<typename Derived>
7697QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7698 unsigned NumElements,
7699 SourceLocation AttributeLoc) {
7700 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7701 NumElements, true);
7702 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007703 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7704 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007705 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007706}
Mike Stump11289f42009-09-09 15:08:12 +00007707
Douglas Gregord6ff3322009-08-04 16:50:30 +00007708template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007709QualType
7710TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007711 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007712 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007713 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007714}
Mike Stump11289f42009-09-09 15:08:12 +00007715
Douglas Gregord6ff3322009-08-04 16:50:30 +00007716template<typename Derived>
7717QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007718 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007719 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007720 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007721 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007722 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00007723 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007724 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007725 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007726 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007727 getDerived().getBaseEntity(),
7728 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007729}
Mike Stump11289f42009-09-09 15:08:12 +00007730
Douglas Gregord6ff3322009-08-04 16:50:30 +00007731template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007732QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7733 return SemaRef.Context.getFunctionNoProtoType(T);
7734}
7735
7736template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007737QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7738 assert(D && "no decl found");
7739 if (D->isInvalidDecl()) return QualType();
7740
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007741 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007742 TypeDecl *Ty;
7743 if (isa<UsingDecl>(D)) {
7744 UsingDecl *Using = cast<UsingDecl>(D);
7745 assert(Using->isTypeName() &&
7746 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7747
7748 // A valid resolved using typename decl points to exactly one type decl.
7749 assert(++Using->shadow_begin() == Using->shadow_end());
7750 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007751
John McCallb96ec562009-12-04 22:46:56 +00007752 } else {
7753 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7754 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7755 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7756 }
7757
7758 return SemaRef.Context.getTypeDeclType(Ty);
7759}
7760
7761template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007762QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7763 SourceLocation Loc) {
7764 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007765}
7766
7767template<typename Derived>
7768QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7769 return SemaRef.Context.getTypeOfType(Underlying);
7770}
7771
7772template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007773QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7774 SourceLocation Loc) {
7775 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007776}
7777
7778template<typename Derived>
7779QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007780 TemplateName Template,
7781 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00007782 const TemplateArgumentListInfo &TemplateArgs) {
7783 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007784}
Mike Stump11289f42009-09-09 15:08:12 +00007785
Douglas Gregor1135c352009-08-06 05:28:30 +00007786template<typename Derived>
7787NestedNameSpecifier *
7788TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7789 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007790 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007791 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00007792 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00007793 CXXScopeSpec SS;
7794 // FIXME: The source location information is all wrong.
Douglas Gregor869ad452011-02-24 17:54:50 +00007795 SS.MakeTrivial(SemaRef.Context, Prefix, Range);
Douglas Gregor90c99722011-02-24 00:17:56 +00007796 if (SemaRef.BuildCXXNestedNameSpecifier(0, II, /*FIXME:*/Range.getBegin(),
7797 /*FIXME:*/Range.getEnd(),
7798 ObjectType, false,
7799 SS, FirstQualifierInScope,
7800 false))
7801 return 0;
7802
7803 return SS.getScopeRep();
Douglas Gregor1135c352009-08-06 05:28:30 +00007804}
7805
7806template<typename Derived>
7807NestedNameSpecifier *
7808TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7809 SourceRange Range,
7810 NamespaceDecl *NS) {
7811 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7812}
7813
7814template<typename Derived>
7815NestedNameSpecifier *
7816TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7817 SourceRange Range,
Douglas Gregor7b26ff92011-02-24 02:36:08 +00007818 NamespaceAliasDecl *Alias) {
7819 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, Alias);
7820}
7821
7822template<typename Derived>
7823NestedNameSpecifier *
7824TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7825 SourceRange Range,
Douglas Gregor1135c352009-08-06 05:28:30 +00007826 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00007827 QualType T) {
7828 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00007829 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00007830 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00007831 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7832 T.getTypePtr());
7833 }
Mike Stump11289f42009-09-09 15:08:12 +00007834
Douglas Gregor1135c352009-08-06 05:28:30 +00007835 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7836 return 0;
7837}
Mike Stump11289f42009-09-09 15:08:12 +00007838
Douglas Gregor71dc5092009-08-06 06:41:21 +00007839template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007840TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007841TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7842 bool TemplateKW,
7843 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00007844 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007845 Template);
7846}
7847
7848template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007849TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007850TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00007851 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00007852 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00007853 QualType ObjectType,
7854 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00007855 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +00007856 SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange);
Douglas Gregor3cf81312009-11-03 23:16:33 +00007857 UnqualifiedId Name;
7858 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00007859 Sema::TemplateTy Template;
7860 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7861 /*FIXME:*/getDerived().getBaseLocation(),
7862 SS,
7863 Name,
John McCallba7bf592010-08-24 05:47:05 +00007864 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007865 /*EnteringContext=*/false,
7866 Template);
John McCall31f82722010-11-12 08:19:04 +00007867 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007868}
Mike Stump11289f42009-09-09 15:08:12 +00007869
Douglas Gregora16548e2009-08-11 05:31:07 +00007870template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007871TemplateName
7872TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7873 OverloadedOperatorKind Operator,
7874 QualType ObjectType) {
7875 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +00007876 SS.MakeTrivial(SemaRef.Context, Qualifier, SourceRange(getDerived().getBaseLocation()));
Douglas Gregor71395fa2009-11-04 00:56:37 +00007877 UnqualifiedId Name;
7878 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7879 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7880 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007881 Sema::TemplateTy Template;
7882 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007883 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007884 SS,
7885 Name,
John McCallba7bf592010-08-24 05:47:05 +00007886 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007887 /*EnteringContext=*/false,
7888 Template);
7889 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007890}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007891
Douglas Gregor71395fa2009-11-04 00:56:37 +00007892template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007893ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007894TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7895 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007896 Expr *OrigCallee,
7897 Expr *First,
7898 Expr *Second) {
7899 Expr *Callee = OrigCallee->IgnoreParenCasts();
7900 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007901
Douglas Gregora16548e2009-08-11 05:31:07 +00007902 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007903 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007904 if (!First->getType()->isOverloadableType() &&
7905 !Second->getType()->isOverloadableType())
7906 return getSema().CreateBuiltinArraySubscriptExpr(First,
7907 Callee->getLocStart(),
7908 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007909 } else if (Op == OO_Arrow) {
7910 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007911 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7912 } else if (Second == 0 || isPostIncDec) {
7913 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007914 // The argument is not of overloadable type, so try to create a
7915 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007916 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007917 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007918
John McCallb268a282010-08-23 23:25:46 +00007919 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007920 }
7921 } else {
John McCallb268a282010-08-23 23:25:46 +00007922 if (!First->getType()->isOverloadableType() &&
7923 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007924 // Neither of the arguments is an overloadable type, so try to
7925 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007926 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007927 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007928 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007929 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007930 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007931
Douglas Gregora16548e2009-08-11 05:31:07 +00007932 return move(Result);
7933 }
7934 }
Mike Stump11289f42009-09-09 15:08:12 +00007935
7936 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007937 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007938 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007939
John McCallb268a282010-08-23 23:25:46 +00007940 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007941 assert(ULE->requiresADL());
7942
7943 // FIXME: Do we have to check
7944 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007945 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007946 } else {
John McCallb268a282010-08-23 23:25:46 +00007947 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007948 }
Mike Stump11289f42009-09-09 15:08:12 +00007949
Douglas Gregora16548e2009-08-11 05:31:07 +00007950 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007951 Expr *Args[2] = { First, Second };
7952 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007953
Douglas Gregora16548e2009-08-11 05:31:07 +00007954 // Create the overloaded operator invocation for unary operators.
7955 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007956 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007957 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007958 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007959 }
Mike Stump11289f42009-09-09 15:08:12 +00007960
Sebastian Redladba46e2009-10-29 20:17:01 +00007961 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007962 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007963 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007964 First,
7965 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007966
Douglas Gregora16548e2009-08-11 05:31:07 +00007967 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007968 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007969 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007970 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7971 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007972 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007973
Mike Stump11289f42009-09-09 15:08:12 +00007974 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007975}
Mike Stump11289f42009-09-09 15:08:12 +00007976
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007977template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007978ExprResult
John McCallb268a282010-08-23 23:25:46 +00007979TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007980 SourceLocation OperatorLoc,
7981 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00007982 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007983 TypeSourceInfo *ScopeType,
7984 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007985 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007986 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00007987 QualType BaseType = Base->getType();
7988 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007989 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007990 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007991 !BaseType->getAs<PointerType>()->getPointeeType()
7992 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007993 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00007994 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007995 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007996 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007997 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007998 /*FIXME?*/true);
7999 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008000
Douglas Gregor678f90d2010-02-25 01:56:36 +00008001 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008002 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8003 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8004 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8005 NameInfo.setNamedTypeInfo(DestroyedType);
8006
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008007 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008008
John McCallb268a282010-08-23 23:25:46 +00008009 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008010 OperatorLoc, isArrow,
8011 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008012 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008013 /*TemplateArgs*/ 0);
8014}
8015
Douglas Gregord6ff3322009-08-04 16:50:30 +00008016} // end namespace clang
8017
8018#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H