blob: ae55d32fb478fbade34d7596a1102c4f0746c254 [file] [log] [blame]
John McCall550e0c22009-10-21 00:40:46 +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.
7//===----------------------------------------------------------------------===/
8//
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//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
John McCall83024632010-08-25 22:03:47 +000016#include "clang/Sema/SemaInternal.h"
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000017#include "clang/Sema/Lookup.h"
Douglas Gregor840bd6c2010-12-20 22:05:00 +000018#include "clang/Sema/ParsedTemplate.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000019#include "clang/Sema/SemaDiagnostic.h"
John McCallaab3e412010-08-25 08:40:02 +000020#include "clang/Sema/ScopeInfo.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000021#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000022#include "clang/AST/DeclObjC.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000023#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000024#include "clang/AST/ExprCXX.h"
25#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000026#include "clang/AST/Stmt.h"
27#include "clang/AST/StmtCXX.h"
28#include "clang/AST/StmtObjC.h"
John McCall8b0666c2010-08-20 18:27:03 +000029#include "clang/Sema/Ownership.h"
30#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000031#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000032#include "llvm/Support/ErrorHandling.h"
Douglas Gregor451d1b12010-12-02 00:05:49 +000033#include "TypeLocBuilder.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000034#include <algorithm>
35
36namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000037using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000038
Douglas Gregord6ff3322009-08-04 16:50:30 +000039/// \brief A semantic tree transformation that allows one to transform one
40/// abstract syntax tree into another.
41///
Mike Stump11289f42009-09-09 15:08:12 +000042/// A new tree transformation is defined by creating a new subclass \c X of
43/// \c TreeTransform<X> and then overriding certain operations to provide
44/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000045/// instantiation is implemented as a tree transformation where the
46/// transformation of TemplateTypeParmType nodes involves substituting the
47/// template arguments for their corresponding template parameters; a similar
48/// transformation is performed for non-type template parameters and
49/// template template parameters.
50///
51/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000052/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000053/// override any of the transformation or rebuild operators by providing an
54/// operation with the same signature as the default implementation. The
55/// overridding function should not be virtual.
56///
57/// Semantic tree transformations are split into two stages, either of which
58/// can be replaced by a subclass. The "transform" step transforms an AST node
59/// or the parts of an AST node using the various transformation functions,
60/// then passes the pieces on to the "rebuild" step, which constructs a new AST
61/// node of the appropriate kind from the pieces. The default transformation
62/// routines recursively transform the operands to composite AST nodes (e.g.,
63/// the pointee type of a PointerType node) and, if any of those operand nodes
64/// were changed by the transformation, invokes the rebuild operation to create
65/// a new AST node.
66///
Mike Stump11289f42009-09-09 15:08:12 +000067/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000068/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000069/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
70/// TransformTemplateName(), or TransformTemplateArgument() with entirely
71/// new implementations.
72///
73/// For more fine-grained transformations, subclasses can replace any of the
74/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000075/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000076/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000077/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000078/// parameters. Additionally, subclasses can override the \c RebuildXXX
79/// functions to control how AST nodes are rebuilt when their operands change.
80/// By default, \c TreeTransform will invoke semantic analysis to rebuild
81/// AST nodes. However, certain other tree transformations (e.g, cloning) may
82/// be able to use more efficient rebuild steps.
83///
84/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000085/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000086/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
87/// operands have not changed (\c AlwaysRebuild()), and customize the
88/// default locations and entity names used for type-checking
89/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000090template<typename Derived>
91class TreeTransform {
92protected:
93 Sema &SemaRef;
Douglas Gregor840bd6c2010-12-20 22:05:00 +000094 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex;
95
Mike Stump11289f42009-09-09 15:08:12 +000096public:
Douglas Gregord6ff3322009-08-04 16:50:30 +000097 /// \brief Initializes a new tree transformer.
Douglas Gregor840bd6c2010-12-20 22:05:00 +000098 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef), SubstIndex(SemaRef, -1) { }
Mike Stump11289f42009-09-09 15:08:12 +000099
Douglas Gregord6ff3322009-08-04 16:50:30 +0000100 /// \brief Retrieves a reference to the derived class.
101 Derived &getDerived() { return static_cast<Derived&>(*this); }
102
103 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000104 const Derived &getDerived() const {
105 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000106 }
107
John McCalldadc5752010-08-24 06:29:42 +0000108 static inline ExprResult Owned(Expr *E) { return E; }
109 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000110
Douglas Gregord6ff3322009-08-04 16:50:30 +0000111 /// \brief Retrieves a reference to the semantic analysis object used for
112 /// this tree transform.
113 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000114
Douglas Gregord6ff3322009-08-04 16:50:30 +0000115 /// \brief Whether the transformation should always rebuild AST nodes, even
116 /// if none of the children have changed.
117 ///
118 /// Subclasses may override this function to specify when the transformation
119 /// should rebuild all AST nodes.
120 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000121
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// \brief Returns the location of the entity being transformed, if that
123 /// information was not available elsewhere in the AST.
124 ///
Mike Stump11289f42009-09-09 15:08:12 +0000125 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000126 /// provide an alternative implementation that provides better location
127 /// information.
128 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000129
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 /// \brief Returns the name of the entity being transformed, if that
131 /// information was not available elsewhere in the AST.
132 ///
133 /// By default, returns an empty name. Subclasses can provide an alternative
134 /// implementation with a more precise name.
135 DeclarationName getBaseEntity() { return DeclarationName(); }
136
Douglas Gregora16548e2009-08-11 05:31:07 +0000137 /// \brief Sets the "base" location and entity when that
138 /// information is known based on another transformation.
139 ///
140 /// By default, the source location and entity are ignored. Subclasses can
141 /// override this function to provide a customized implementation.
142 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000143
Douglas Gregora16548e2009-08-11 05:31:07 +0000144 /// \brief RAII object that temporarily sets the base location and entity
145 /// used for reporting diagnostics in types.
146 class TemporaryBase {
147 TreeTransform &Self;
148 SourceLocation OldLocation;
149 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregora16548e2009-08-11 05:31:07 +0000151 public:
152 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000153 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000154 OldLocation = Self.getDerived().getBaseLocation();
155 OldEntity = Self.getDerived().getBaseEntity();
156 Self.getDerived().setBase(Location, Entity);
157 }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregora16548e2009-08-11 05:31:07 +0000159 ~TemporaryBase() {
160 Self.getDerived().setBase(OldLocation, OldEntity);
161 }
162 };
Mike Stump11289f42009-09-09 15:08:12 +0000163
164 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000165 /// transformed.
166 ///
167 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000168 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000169 /// not change. For example, template instantiation need not traverse
170 /// non-dependent types.
171 bool AlreadyTransformed(QualType T) {
172 return T.isNull();
173 }
174
Douglas Gregord196a582009-12-14 19:27:10 +0000175 /// \brief Determine whether the given call argument should be dropped, e.g.,
176 /// because it is a default argument.
177 ///
178 /// Subclasses can provide an alternative implementation of this routine to
179 /// determine which kinds of call arguments get dropped. By default,
180 /// CXXDefaultArgument nodes are dropped (prior to transformation).
181 bool DropCallArgument(Expr *E) {
182 return E->isDefaultArgument();
183 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000184
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000185 /// \brief Determine whether we should expand a pack expansion with the
186 /// given set of parameter packs into separate arguments by repeatedly
187 /// transforming the pattern.
188 ///
189 /// By default, the transformed never tries to expand pack expansions.
190 /// Subclasses can override this routine to provide different behavior.
191 ///
192 /// \param EllipsisLoc The location of the ellipsis that identifies the
193 /// pack expansion.
194 ///
195 /// \param PatternRange The source range that covers the entire pattern of
196 /// the pack expansion.
197 ///
198 /// \param Unexpanded The set of unexpanded parameter packs within the
199 /// pattern.
200 ///
201 /// \param NumUnexpanded The number of unexpanded parameter packs in
202 /// \p Unexpanded.
203 ///
204 /// \param ShouldExpand Will be set to \c true if the transformer should
205 /// expand the corresponding pack expansions into separate arguments. When
206 /// set, \c NumExpansions must also be set.
207 ///
208 /// \param NumExpansions The number of separate arguments that will be in
209 /// the expanded form of the corresponding pack expansion. Must be set when
210 /// \c ShouldExpand is \c true.
211 ///
212 /// \returns true if an error occurred (e.g., because the parameter packs
213 /// are to be instantiated with arguments of different lengths), false
214 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
215 /// must be set.
216 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
217 SourceRange PatternRange,
218 const UnexpandedParameterPack *Unexpanded,
219 unsigned NumUnexpanded,
220 bool &ShouldExpand,
221 unsigned &NumExpansions) {
222 ShouldExpand = false;
223 return false;
224 }
225
Douglas Gregord6ff3322009-08-04 16:50:30 +0000226 /// \brief Transforms the given type into another type.
227 ///
John McCall550e0c22009-10-21 00:40:46 +0000228 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000229 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000230 /// function. This is expensive, but we don't mind, because
231 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000232 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000233 ///
234 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000235 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000236
John McCall550e0c22009-10-21 00:40:46 +0000237 /// \brief Transforms the given type-with-location into a new
238 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000239 ///
John McCall550e0c22009-10-21 00:40:46 +0000240 /// By default, this routine transforms a type by delegating to the
241 /// appropriate TransformXXXType to build a new type. Subclasses
242 /// may override this function (to take over all type
243 /// transformations) or some set of the TransformXXXType functions
244 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000245 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000246
247 /// \brief Transform the given type-with-location into a new
248 /// type, collecting location information in the given builder
249 /// as necessary.
250 ///
John McCall31f82722010-11-12 08:19:04 +0000251 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000252
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000253 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000254 ///
Mike Stump11289f42009-09-09 15:08:12 +0000255 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000256 /// appropriate TransformXXXStmt function to transform a specific kind of
257 /// statement or the TransformExpr() function to transform an expression.
258 /// Subclasses may override this function to transform statements using some
259 /// other mechanism.
260 ///
261 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000262 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000263
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000264 /// \brief Transform the given expression.
265 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000266 /// By default, this routine transforms an expression by delegating to the
267 /// appropriate TransformXXXExpr function to build a new expression.
268 /// Subclasses may override this function to transform expressions using some
269 /// other mechanism.
270 ///
271 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000272 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000273
Douglas Gregord6ff3322009-08-04 16:50:30 +0000274 /// \brief Transform the given declaration, which is referenced from a type
275 /// or expression.
276 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000277 /// By default, acts as the identity function on declarations. Subclasses
278 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000279 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000280
281 /// \brief Transform the definition of the given declaration.
282 ///
Mike Stump11289f42009-09-09 15:08:12 +0000283 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000284 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000285 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
286 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000287 }
Mike Stump11289f42009-09-09 15:08:12 +0000288
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000289 /// \brief Transform the given declaration, which was the first part of a
290 /// nested-name-specifier in a member access expression.
291 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000292 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000293 /// identifier in a nested-name-specifier of a member access expression, e.g.,
294 /// the \c T in \c x->T::member
295 ///
296 /// By default, invokes TransformDecl() to transform the declaration.
297 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000298 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
299 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000300 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000301
Douglas Gregord6ff3322009-08-04 16:50:30 +0000302 /// \brief Transform the given nested-name-specifier.
303 ///
Mike Stump11289f42009-09-09 15:08:12 +0000304 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000305 /// nested-name-specifier. Subclasses may override this function to provide
306 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000307 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000308 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000309 QualType ObjectType = QualType(),
310 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000311
Douglas Gregorf816bd72009-09-03 22:13:48 +0000312 /// \brief Transform the given declaration name.
313 ///
314 /// By default, transforms the types of conversion function, constructor,
315 /// and destructor names and then (if needed) rebuilds the declaration name.
316 /// Identifiers and selectors are returned unmodified. Sublcasses may
317 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000318 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000319 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000320
Douglas Gregord6ff3322009-08-04 16:50:30 +0000321 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000322 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000323 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000324 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000325 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000326 TemplateName TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +0000327 QualType ObjectType = QualType(),
328 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000329
Douglas Gregord6ff3322009-08-04 16:50:30 +0000330 /// \brief Transform the given template argument.
331 ///
Mike Stump11289f42009-09-09 15:08:12 +0000332 /// By default, this operation transforms the type, expression, or
333 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000334 /// new template argument from the transformed result. Subclasses may
335 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000336 ///
337 /// Returns true if there was an error.
338 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
339 TemplateArgumentLoc &Output);
340
Douglas Gregor62e06f22010-12-20 17:31:10 +0000341 /// \brief Transform the given set of template arguments.
342 ///
343 /// By default, this operation transforms all of the template arguments
344 /// in the input set using \c TransformTemplateArgument(), and appends
345 /// the transformed arguments to the output list.
346 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000347 /// Note that this overload of \c TransformTemplateArguments() is merely
348 /// a convenience function. Subclasses that wish to override this behavior
349 /// should override the iterator-based member template version.
350 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000351 /// \param Inputs The set of template arguments to be transformed.
352 ///
353 /// \param NumInputs The number of template arguments in \p Inputs.
354 ///
355 /// \param Outputs The set of transformed template arguments output by this
356 /// routine.
357 ///
358 /// Returns true if an error occurred.
359 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
360 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000361 TemplateArgumentListInfo &Outputs) {
362 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
363 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000364
365 /// \brief Transform the given set of template arguments.
366 ///
367 /// By default, this operation transforms all of the template arguments
368 /// in the input set using \c TransformTemplateArgument(), and appends
369 /// the transformed arguments to the output list.
370 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000371 /// \param First An iterator to the first template argument.
372 ///
373 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000374 ///
375 /// \param Outputs The set of transformed template arguments output by this
376 /// routine.
377 ///
378 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000379 template<typename InputIterator>
380 bool TransformTemplateArguments(InputIterator First,
381 InputIterator Last,
382 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000383
John McCall0ad16662009-10-29 08:12:44 +0000384 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
385 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
386 TemplateArgumentLoc &ArgLoc);
387
John McCallbcd03502009-12-07 02:54:59 +0000388 /// \brief Fakes up a TypeSourceInfo for a type.
389 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
390 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000391 getDerived().getBaseLocation());
392 }
Mike Stump11289f42009-09-09 15:08:12 +0000393
John McCall550e0c22009-10-21 00:40:46 +0000394#define ABSTRACT_TYPELOC(CLASS, PARENT)
395#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000396 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000397#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000398
John McCall31f82722010-11-12 08:19:04 +0000399 QualType
400 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
401 TemplateSpecializationTypeLoc TL,
402 TemplateName Template);
403
404 QualType
405 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
406 DependentTemplateSpecializationTypeLoc TL,
407 NestedNameSpecifier *Prefix);
408
John McCall58f10c32010-03-11 09:03:00 +0000409 /// \brief Transforms the parameters of a function type into the
410 /// given vectors.
411 ///
412 /// The result vectors should be kept in sync; null entries in the
413 /// variables vector are acceptable.
414 ///
415 /// Return true on error.
416 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
417 llvm::SmallVectorImpl<QualType> &PTypes,
418 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
419
420 /// \brief Transforms a single function-type parameter. Return null
421 /// on error.
422 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
423
John McCall31f82722010-11-12 08:19:04 +0000424 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000425
John McCalldadc5752010-08-24 06:29:42 +0000426 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
427 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000428
Douglas Gregorebe10102009-08-20 07:17:43 +0000429#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000430 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000431#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000432 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000433#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000434#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000435
Douglas Gregord6ff3322009-08-04 16:50:30 +0000436 /// \brief Build a new pointer type given its pointee type.
437 ///
438 /// By default, performs semantic analysis when building the pointer type.
439 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000440 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000441
442 /// \brief Build a new block pointer type given its pointee type.
443 ///
Mike Stump11289f42009-09-09 15:08:12 +0000444 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000445 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000446 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000447
John McCall70dd5f62009-10-30 00:06:24 +0000448 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000449 ///
John McCall70dd5f62009-10-30 00:06:24 +0000450 /// By default, performs semantic analysis when building the
451 /// reference type. Subclasses may override this routine to provide
452 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000453 ///
John McCall70dd5f62009-10-30 00:06:24 +0000454 /// \param LValue whether the type was written with an lvalue sigil
455 /// or an rvalue sigil.
456 QualType RebuildReferenceType(QualType ReferentType,
457 bool LValue,
458 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000459
Douglas Gregord6ff3322009-08-04 16:50:30 +0000460 /// \brief Build a new member pointer type given the pointee type and the
461 /// class type it refers into.
462 ///
463 /// By default, performs semantic analysis when building the member pointer
464 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000465 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
466 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000467
Douglas Gregord6ff3322009-08-04 16:50:30 +0000468 /// \brief Build a new array type given the element type, size
469 /// modifier, size of the array (if known), size expression, and index type
470 /// qualifiers.
471 ///
472 /// By default, performs semantic analysis when building the array type.
473 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000474 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000475 QualType RebuildArrayType(QualType ElementType,
476 ArrayType::ArraySizeModifier SizeMod,
477 const llvm::APInt *Size,
478 Expr *SizeExpr,
479 unsigned IndexTypeQuals,
480 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000481
Douglas Gregord6ff3322009-08-04 16:50:30 +0000482 /// \brief Build a new constant array type given the element type, size
483 /// modifier, (known) size of the array, and index type qualifiers.
484 ///
485 /// By default, performs semantic analysis when building the array type.
486 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000487 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000488 ArrayType::ArraySizeModifier SizeMod,
489 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000490 unsigned IndexTypeQuals,
491 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000492
Douglas Gregord6ff3322009-08-04 16:50:30 +0000493 /// \brief Build a new incomplete array type given the element type, size
494 /// modifier, and index type qualifiers.
495 ///
496 /// By default, performs semantic analysis when building the array type.
497 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000498 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000499 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000500 unsigned IndexTypeQuals,
501 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000502
Mike Stump11289f42009-09-09 15:08:12 +0000503 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000504 /// size modifier, size expression, and index type qualifiers.
505 ///
506 /// By default, performs semantic analysis when building the array type.
507 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000508 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000509 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000510 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000511 unsigned IndexTypeQuals,
512 SourceRange BracketsRange);
513
Mike Stump11289f42009-09-09 15:08:12 +0000514 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000515 /// size modifier, size expression, and index type qualifiers.
516 ///
517 /// By default, performs semantic analysis when building the array type.
518 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000519 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000520 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000521 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000522 unsigned IndexTypeQuals,
523 SourceRange BracketsRange);
524
525 /// \brief Build a new vector type given the element type and
526 /// number of elements.
527 ///
528 /// By default, performs semantic analysis when building the vector type.
529 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000530 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000531 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000532
Douglas Gregord6ff3322009-08-04 16:50:30 +0000533 /// \brief Build a new extended vector type given the element type and
534 /// number of elements.
535 ///
536 /// By default, performs semantic analysis when building the vector type.
537 /// Subclasses may override this routine to provide different behavior.
538 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
539 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000540
541 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000542 /// given the element type and number of elements.
543 ///
544 /// By default, performs semantic analysis when building the vector type.
545 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000546 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000547 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000548 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000549
Douglas Gregord6ff3322009-08-04 16:50:30 +0000550 /// \brief Build a new function type.
551 ///
552 /// By default, performs semantic analysis when building the function type.
553 /// Subclasses may override this routine to provide different behavior.
554 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000555 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000556 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000557 bool Variadic, unsigned Quals,
558 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000559
John McCall550e0c22009-10-21 00:40:46 +0000560 /// \brief Build a new unprototyped function type.
561 QualType RebuildFunctionNoProtoType(QualType ResultType);
562
John McCallb96ec562009-12-04 22:46:56 +0000563 /// \brief Rebuild an unresolved typename type, given the decl that
564 /// the UnresolvedUsingTypenameDecl was transformed to.
565 QualType RebuildUnresolvedUsingType(Decl *D);
566
Douglas Gregord6ff3322009-08-04 16:50:30 +0000567 /// \brief Build a new typedef type.
568 QualType RebuildTypedefType(TypedefDecl *Typedef) {
569 return SemaRef.Context.getTypeDeclType(Typedef);
570 }
571
572 /// \brief Build a new class/struct/union type.
573 QualType RebuildRecordType(RecordDecl *Record) {
574 return SemaRef.Context.getTypeDeclType(Record);
575 }
576
577 /// \brief Build a new Enum type.
578 QualType RebuildEnumType(EnumDecl *Enum) {
579 return SemaRef.Context.getTypeDeclType(Enum);
580 }
John McCallfcc33b02009-09-05 00:15:47 +0000581
Mike Stump11289f42009-09-09 15:08:12 +0000582 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000583 ///
584 /// By default, performs semantic analysis when building the typeof type.
585 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000586 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000587
Mike Stump11289f42009-09-09 15:08:12 +0000588 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000589 ///
590 /// By default, builds a new TypeOfType with the given underlying type.
591 QualType RebuildTypeOfType(QualType Underlying);
592
Mike Stump11289f42009-09-09 15:08:12 +0000593 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000594 ///
595 /// By default, performs semantic analysis when building the decltype type.
596 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000597 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000598
Douglas Gregord6ff3322009-08-04 16:50:30 +0000599 /// \brief Build a new template specialization type.
600 ///
601 /// By default, performs semantic analysis when building the template
602 /// specialization type. Subclasses may override this routine to provide
603 /// different behavior.
604 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000605 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000606 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000607
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000608 /// \brief Build a new parenthesized type.
609 ///
610 /// By default, builds a new ParenType type from the inner type.
611 /// Subclasses may override this routine to provide different behavior.
612 QualType RebuildParenType(QualType InnerType) {
613 return SemaRef.Context.getParenType(InnerType);
614 }
615
Douglas Gregord6ff3322009-08-04 16:50:30 +0000616 /// \brief Build a new qualified name type.
617 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000618 /// By default, builds a new ElaboratedType type from the keyword,
619 /// the nested-name-specifier and the named type.
620 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000621 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
622 ElaboratedTypeKeyword Keyword,
Abramo Bagnara6150c882010-05-11 21:36:43 +0000623 NestedNameSpecifier *NNS, QualType Named) {
624 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000625 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000626
627 /// \brief Build a new typename type that refers to a template-id.
628 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000629 /// By default, builds a new DependentNameType type from the
630 /// nested-name-specifier and the given type. Subclasses may override
631 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000632 QualType RebuildDependentTemplateSpecializationType(
633 ElaboratedTypeKeyword Keyword,
Douglas Gregora5614c52010-09-08 23:56:00 +0000634 NestedNameSpecifier *Qualifier,
635 SourceRange QualifierRange,
John McCallc392f372010-06-11 00:33:02 +0000636 const IdentifierInfo *Name,
637 SourceLocation NameLoc,
638 const TemplateArgumentListInfo &Args) {
639 // Rebuild the template name.
640 // TODO: avoid TemplateName abstraction
641 TemplateName InstName =
Douglas Gregora5614c52010-09-08 23:56:00 +0000642 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall31f82722010-11-12 08:19:04 +0000643 QualType(), 0);
John McCallc392f372010-06-11 00:33:02 +0000644
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000645 if (InstName.isNull())
646 return QualType();
647
John McCallc392f372010-06-11 00:33:02 +0000648 // If it's still dependent, make a dependent specialization.
649 if (InstName.getAsDependentTemplateName())
650 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregora5614c52010-09-08 23:56:00 +0000651 Keyword, Qualifier, Name, Args);
John McCallc392f372010-06-11 00:33:02 +0000652
653 // Otherwise, make an elaborated type wrapping a non-dependent
654 // specialization.
655 QualType T =
656 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
657 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000658
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000659 // NOTE: NNS is already recorded in template specialization type T.
660 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000661 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000662
663 /// \brief Build a new typename type that refers to an identifier.
664 ///
665 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000666 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000667 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000668 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000669 NestedNameSpecifier *NNS,
670 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000671 SourceLocation KeywordLoc,
672 SourceRange NNSRange,
673 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000674 CXXScopeSpec SS;
675 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000676 SS.setRange(NNSRange);
677
Douglas Gregore677daf2010-03-31 22:19:08 +0000678 if (NNS->isDependent()) {
679 // If the name is still dependent, just build a new dependent name type.
680 if (!SemaRef.computeDeclContext(SS))
681 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
682 }
683
Abramo Bagnara6150c882010-05-11 21:36:43 +0000684 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000685 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
686 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000687
688 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
689
Abramo Bagnarad7548482010-05-19 21:37:53 +0000690 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000691 // into a non-dependent elaborated-type-specifier. Find the tag we're
692 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000693 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000694 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
695 if (!DC)
696 return QualType();
697
John McCallbf8c5192010-05-27 06:40:31 +0000698 if (SemaRef.RequireCompleteDeclContext(SS, DC))
699 return QualType();
700
Douglas Gregore677daf2010-03-31 22:19:08 +0000701 TagDecl *Tag = 0;
702 SemaRef.LookupQualifiedName(Result, DC);
703 switch (Result.getResultKind()) {
704 case LookupResult::NotFound:
705 case LookupResult::NotFoundInCurrentInstantiation:
706 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000707
Douglas Gregore677daf2010-03-31 22:19:08 +0000708 case LookupResult::Found:
709 Tag = Result.getAsSingle<TagDecl>();
710 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000711
Douglas Gregore677daf2010-03-31 22:19:08 +0000712 case LookupResult::FoundOverloaded:
713 case LookupResult::FoundUnresolvedValue:
714 llvm_unreachable("Tag lookup cannot find non-tags");
715 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000716
Douglas Gregore677daf2010-03-31 22:19:08 +0000717 case LookupResult::Ambiguous:
718 // Let the LookupResult structure handle ambiguities.
719 return QualType();
720 }
721
722 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000723 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000724 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000725 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000726 return QualType();
727 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000728
Abramo Bagnarad7548482010-05-19 21:37:53 +0000729 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
730 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000731 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
732 return QualType();
733 }
734
735 // Build the elaborated-type-specifier type.
736 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000737 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000738 }
Mike Stump11289f42009-09-09 15:08:12 +0000739
Douglas Gregor1135c352009-08-06 05:28:30 +0000740 /// \brief Build a new nested-name-specifier given the prefix and an
741 /// identifier that names the next step in the nested-name-specifier.
742 ///
743 /// By default, performs semantic analysis when building the new
744 /// nested-name-specifier. Subclasses may override this routine to provide
745 /// different behavior.
746 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
747 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000748 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000749 QualType ObjectType,
750 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000751
752 /// \brief Build a new nested-name-specifier given the prefix and the
753 /// namespace named in the next step in the nested-name-specifier.
754 ///
755 /// By default, performs semantic analysis when building the new
756 /// nested-name-specifier. Subclasses may override this routine to provide
757 /// different behavior.
758 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
759 SourceRange Range,
760 NamespaceDecl *NS);
761
762 /// \brief Build a new nested-name-specifier given the prefix and the
763 /// type named in the next step in the nested-name-specifier.
764 ///
765 /// By default, performs semantic analysis when building the new
766 /// nested-name-specifier. Subclasses may override this routine to provide
767 /// different behavior.
768 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
769 SourceRange Range,
770 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000771 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000772
773 /// \brief Build a new template name given a nested name specifier, a flag
774 /// indicating whether the "template" keyword was provided, and the template
775 /// that the template name refers to.
776 ///
777 /// By default, builds the new template name directly. Subclasses may override
778 /// this routine to provide different behavior.
779 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
780 bool TemplateKW,
781 TemplateDecl *Template);
782
Douglas Gregor71dc5092009-08-06 06:41:21 +0000783 /// \brief Build a new template name given a nested name specifier and the
784 /// name that is referred to as a template.
785 ///
786 /// By default, performs semantic analysis to determine whether the name can
787 /// be resolved to a specific template, then builds the appropriate kind of
788 /// template name. Subclasses may override this routine to provide different
789 /// behavior.
790 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +0000791 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +0000792 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +0000793 QualType ObjectType,
794 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000795
Douglas Gregor71395fa2009-11-04 00:56:37 +0000796 /// \brief Build a new template name given a nested name specifier and the
797 /// overloaded operator name that is referred to as a template.
798 ///
799 /// By default, performs semantic analysis to determine whether the name can
800 /// be resolved to a specific template, then builds the appropriate kind of
801 /// template name. Subclasses may override this routine to provide different
802 /// behavior.
803 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
804 OverloadedOperatorKind Operator,
805 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000806
Douglas Gregorebe10102009-08-20 07:17:43 +0000807 /// \brief Build a new compound statement.
808 ///
809 /// By default, performs semantic analysis to build the new statement.
810 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000811 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000812 MultiStmtArg Statements,
813 SourceLocation RBraceLoc,
814 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000815 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000816 IsStmtExpr);
817 }
818
819 /// \brief Build a new case statement.
820 ///
821 /// By default, performs semantic analysis to build the new statement.
822 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000823 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000824 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000825 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000826 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000827 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000828 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000829 ColonLoc);
830 }
Mike Stump11289f42009-09-09 15:08:12 +0000831
Douglas Gregorebe10102009-08-20 07:17:43 +0000832 /// \brief Attach the body to a new case statement.
833 ///
834 /// By default, performs semantic analysis to build the new statement.
835 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000836 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000837 getSema().ActOnCaseStmtBody(S, Body);
838 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000839 }
Mike Stump11289f42009-09-09 15:08:12 +0000840
Douglas Gregorebe10102009-08-20 07:17:43 +0000841 /// \brief Build a new default statement.
842 ///
843 /// By default, performs semantic analysis to build the new statement.
844 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000845 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000846 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000847 Stmt *SubStmt) {
848 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000849 /*CurScope=*/0);
850 }
Mike Stump11289f42009-09-09 15:08:12 +0000851
Douglas Gregorebe10102009-08-20 07:17:43 +0000852 /// \brief Build a new label statement.
853 ///
854 /// By default, performs semantic analysis to build the new statement.
855 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000856 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000857 IdentifierInfo *Id,
858 SourceLocation ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +0000859 Stmt *SubStmt, bool HasUnusedAttr) {
860 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
861 HasUnusedAttr);
Douglas Gregorebe10102009-08-20 07:17:43 +0000862 }
Mike Stump11289f42009-09-09 15:08:12 +0000863
Douglas Gregorebe10102009-08-20 07:17:43 +0000864 /// \brief Build a new "if" statement.
865 ///
866 /// By default, performs semantic analysis to build the new statement.
867 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000868 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000869 VarDecl *CondVar, Stmt *Then,
John McCallb268a282010-08-23 23:25:46 +0000870 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000871 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +0000872 }
Mike Stump11289f42009-09-09 15:08:12 +0000873
Douglas Gregorebe10102009-08-20 07:17:43 +0000874 /// \brief Start building a new switch statement.
875 ///
876 /// By default, performs semantic analysis to build the new statement.
877 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000878 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000879 Expr *Cond, VarDecl *CondVar) {
880 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +0000881 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +0000882 }
Mike Stump11289f42009-09-09 15:08:12 +0000883
Douglas Gregorebe10102009-08-20 07:17:43 +0000884 /// \brief Attach the body to the switch statement.
885 ///
886 /// By default, performs semantic analysis to build the new statement.
887 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000888 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000889 Stmt *Switch, Stmt *Body) {
890 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000891 }
892
893 /// \brief Build a new while statement.
894 ///
895 /// By default, performs semantic analysis to build the new statement.
896 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000897 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000898 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000899 VarDecl *CondVar,
John McCallb268a282010-08-23 23:25:46 +0000900 Stmt *Body) {
901 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000902 }
Mike Stump11289f42009-09-09 15:08:12 +0000903
Douglas Gregorebe10102009-08-20 07:17:43 +0000904 /// \brief Build a new do-while statement.
905 ///
906 /// By default, performs semantic analysis to build the new statement.
907 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000908 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregorebe10102009-08-20 07:17:43 +0000909 SourceLocation WhileLoc,
910 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000911 Expr *Cond,
Douglas Gregorebe10102009-08-20 07:17:43 +0000912 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +0000913 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
914 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +0000915 }
916
917 /// \brief Build a new for statement.
918 ///
919 /// By default, performs semantic analysis to build the new statement.
920 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000921 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000922 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000923 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000924 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCallb268a282010-08-23 23:25:46 +0000925 SourceLocation RParenLoc, Stmt *Body) {
926 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCall48871652010-08-21 09:40:31 +0000927 CondVar,
John McCallb268a282010-08-23 23:25:46 +0000928 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000929 }
Mike Stump11289f42009-09-09 15:08:12 +0000930
Douglas Gregorebe10102009-08-20 07:17:43 +0000931 /// \brief Build a new goto statement.
932 ///
933 /// By default, performs semantic analysis to build the new statement.
934 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000935 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000936 SourceLocation LabelLoc,
937 LabelStmt *Label) {
938 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
939 }
940
941 /// \brief Build a new indirect goto statement.
942 ///
943 /// By default, performs semantic analysis to build the new statement.
944 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000945 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000946 SourceLocation StarLoc,
John McCallb268a282010-08-23 23:25:46 +0000947 Expr *Target) {
948 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +0000949 }
Mike Stump11289f42009-09-09 15:08:12 +0000950
Douglas Gregorebe10102009-08-20 07:17:43 +0000951 /// \brief Build a new return statement.
952 ///
953 /// By default, performs semantic analysis to build the new statement.
954 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000955 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCallb268a282010-08-23 23:25:46 +0000956 Expr *Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000957
John McCallb268a282010-08-23 23:25:46 +0000958 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +0000959 }
Mike Stump11289f42009-09-09 15:08:12 +0000960
Douglas Gregorebe10102009-08-20 07:17:43 +0000961 /// \brief Build a new declaration statement.
962 ///
963 /// By default, performs semantic analysis to build the new statement.
964 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000965 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000966 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000967 SourceLocation EndLoc) {
968 return getSema().Owned(
969 new (getSema().Context) DeclStmt(
970 DeclGroupRef::Create(getSema().Context,
971 Decls, NumDecls),
972 StartLoc, EndLoc));
973 }
Mike Stump11289f42009-09-09 15:08:12 +0000974
Anders Carlssonaaeef072010-01-24 05:50:09 +0000975 /// \brief Build a new inline asm statement.
976 ///
977 /// By default, performs semantic analysis to build the new statement.
978 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000979 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000980 bool IsSimple,
981 bool IsVolatile,
982 unsigned NumOutputs,
983 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000984 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000985 MultiExprArg Constraints,
986 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +0000987 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000988 MultiExprArg Clobbers,
989 SourceLocation RParenLoc,
990 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000991 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000992 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +0000993 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000994 RParenLoc, MSAsm);
995 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000996
997 /// \brief Build a new Objective-C @try statement.
998 ///
999 /// By default, performs semantic analysis to build the new statement.
1000 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001001 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001002 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001003 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001004 Stmt *Finally) {
1005 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1006 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001007 }
1008
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001009 /// \brief Rebuild an Objective-C exception declaration.
1010 ///
1011 /// By default, performs semantic analysis to build the new declaration.
1012 /// Subclasses may override this routine to provide different behavior.
1013 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1014 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001015 return getSema().BuildObjCExceptionDecl(TInfo, T,
1016 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001017 ExceptionDecl->getLocation());
1018 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001019
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001020 /// \brief Build a new Objective-C @catch statement.
1021 ///
1022 /// By default, performs semantic analysis to build the new statement.
1023 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001024 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001025 SourceLocation RParenLoc,
1026 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001027 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001028 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001029 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001030 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001031
Douglas Gregor306de2f2010-04-22 23:59:56 +00001032 /// \brief Build a new Objective-C @finally statement.
1033 ///
1034 /// By default, performs semantic analysis to build the new statement.
1035 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001036 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001037 Stmt *Body) {
1038 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001039 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001040
Douglas Gregor6148de72010-04-22 22:01:21 +00001041 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001042 ///
1043 /// By default, performs semantic analysis to build the new statement.
1044 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001045 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001046 Expr *Operand) {
1047 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001048 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001049
Douglas Gregor6148de72010-04-22 22:01:21 +00001050 /// \brief Build a new Objective-C @synchronized statement.
1051 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001052 /// By default, performs semantic analysis to build the new statement.
1053 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001054 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001055 Expr *Object,
1056 Stmt *Body) {
1057 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1058 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001059 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001060
1061 /// \brief Build a new Objective-C fast enumeration statement.
1062 ///
1063 /// By default, performs semantic analysis to build the new statement.
1064 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001065 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001066 SourceLocation LParenLoc,
1067 Stmt *Element,
1068 Expr *Collection,
1069 SourceLocation RParenLoc,
1070 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001071 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001072 Element,
1073 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001074 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001075 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001076 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001077
Douglas Gregorebe10102009-08-20 07:17:43 +00001078 /// \brief Build a new C++ exception declaration.
1079 ///
1080 /// By default, performs semantic analysis to build the new decaration.
1081 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001082 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001083 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +00001084 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001085 SourceLocation Loc) {
1086 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001087 }
1088
1089 /// \brief Build a new C++ catch statement.
1090 ///
1091 /// By default, performs semantic analysis to build the new statement.
1092 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001093 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001094 VarDecl *ExceptionDecl,
1095 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001096 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1097 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001098 }
Mike Stump11289f42009-09-09 15:08:12 +00001099
Douglas Gregorebe10102009-08-20 07:17:43 +00001100 /// \brief Build a new C++ try statement.
1101 ///
1102 /// By default, performs semantic analysis to build the new statement.
1103 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001104 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001105 Stmt *TryBlock,
1106 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001107 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001108 }
Mike Stump11289f42009-09-09 15:08:12 +00001109
Douglas Gregora16548e2009-08-11 05:31:07 +00001110 /// \brief Build a new expression that references a declaration.
1111 ///
1112 /// By default, performs semantic analysis to build the new expression.
1113 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001114 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001115 LookupResult &R,
1116 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001117 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1118 }
1119
1120
1121 /// \brief Build a new expression that references a declaration.
1122 ///
1123 /// By default, performs semantic analysis to build the new expression.
1124 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001125 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallfaf5fb42010-08-26 23:41:50 +00001126 SourceRange QualifierRange,
1127 ValueDecl *VD,
1128 const DeclarationNameInfo &NameInfo,
1129 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001130 CXXScopeSpec SS;
1131 SS.setScopeRep(Qualifier);
1132 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001133
1134 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001135
1136 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001137 }
Mike Stump11289f42009-09-09 15:08:12 +00001138
Douglas Gregora16548e2009-08-11 05:31:07 +00001139 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001140 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001141 /// By default, performs semantic analysis to build the new expression.
1142 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001143 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001144 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001145 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001146 }
1147
Douglas Gregorad8a3362009-09-04 17:36:40 +00001148 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001149 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001150 /// By default, performs semantic analysis to build the new expression.
1151 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001152 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001153 SourceLocation OperatorLoc,
1154 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001155 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001156 SourceRange QualifierRange,
1157 TypeSourceInfo *ScopeType,
1158 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001159 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001160 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001161
Douglas Gregora16548e2009-08-11 05:31:07 +00001162 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001163 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001164 /// By default, performs semantic analysis to build the new expression.
1165 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001166 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001167 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001168 Expr *SubExpr) {
1169 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001170 }
Mike Stump11289f42009-09-09 15:08:12 +00001171
Douglas Gregor882211c2010-04-28 22:16:22 +00001172 /// \brief Build a new builtin offsetof expression.
1173 ///
1174 /// By default, performs semantic analysis to build the new expression.
1175 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001176 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001177 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001178 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001179 unsigned NumComponents,
1180 SourceLocation RParenLoc) {
1181 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1182 NumComponents, RParenLoc);
1183 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001184
Douglas Gregora16548e2009-08-11 05:31:07 +00001185 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001186 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001187 /// By default, performs semantic analysis to build the new expression.
1188 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001189 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001190 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001191 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001192 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001193 }
1194
Mike Stump11289f42009-09-09 15:08:12 +00001195 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001196 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001197 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001198 /// By default, performs semantic analysis to build the new expression.
1199 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001200 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001201 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001202 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001203 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001204 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001205 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001206
Douglas Gregora16548e2009-08-11 05:31:07 +00001207 return move(Result);
1208 }
Mike Stump11289f42009-09-09 15:08:12 +00001209
Douglas Gregora16548e2009-08-11 05:31:07 +00001210 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001211 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001212 /// By default, performs semantic analysis to build the new expression.
1213 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001214 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001215 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001216 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001217 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001218 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1219 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001220 RBracketLoc);
1221 }
1222
1223 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001224 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001225 /// By default, performs semantic analysis to build the new expression.
1226 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001227 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001228 MultiExprArg Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00001229 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001230 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregorce5aa332010-09-09 16:33:13 +00001231 move(Args), RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001232 }
1233
1234 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001235 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001236 /// By default, performs semantic analysis to build the new expression.
1237 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001238 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001239 bool isArrow,
1240 NestedNameSpecifier *Qualifier,
1241 SourceRange QualifierRange,
1242 const DeclarationNameInfo &MemberNameInfo,
1243 ValueDecl *Member,
1244 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001245 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001246 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001247 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001248 // We have a reference to an unnamed field. This is always the
1249 // base of an anonymous struct/union member access, i.e. the
1250 // field is always of record type.
Anders Carlsson5da84842009-09-01 04:26:58 +00001251 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001252 assert(Member->getType()->isRecordType() &&
1253 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001254
John McCallb268a282010-08-23 23:25:46 +00001255 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001256 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001257 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001258
John McCall7decc9e2010-11-18 06:31:45 +00001259 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001260 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001261 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001262 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001263 cast<FieldDecl>(Member)->getType(),
1264 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001265 return getSema().Owned(ME);
1266 }
Mike Stump11289f42009-09-09 15:08:12 +00001267
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001268 CXXScopeSpec SS;
1269 if (Qualifier) {
1270 SS.setRange(QualifierRange);
1271 SS.setScopeRep(Qualifier);
1272 }
1273
John McCallb268a282010-08-23 23:25:46 +00001274 getSema().DefaultFunctionArrayConversion(Base);
1275 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001276
John McCall16df1e52010-03-30 21:47:33 +00001277 // FIXME: this involves duplicating earlier analysis in a lot of
1278 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001279 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001280 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001281 R.resolveKind();
1282
John McCallb268a282010-08-23 23:25:46 +00001283 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001284 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001285 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001286 }
Mike Stump11289f42009-09-09 15:08:12 +00001287
Douglas Gregora16548e2009-08-11 05:31:07 +00001288 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001289 ///
Douglas Gregora16548e2009-08-11 05:31:07 +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 RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001293 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001294 Expr *LHS, Expr *RHS) {
1295 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001296 }
1297
1298 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001299 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001300 /// By default, performs semantic analysis to build the new expression.
1301 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001302 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregora16548e2009-08-11 05:31:07 +00001303 SourceLocation QuestionLoc,
John McCallb268a282010-08-23 23:25:46 +00001304 Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001305 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001306 Expr *RHS) {
1307 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1308 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001309 }
1310
Douglas Gregora16548e2009-08-11 05:31:07 +00001311 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001312 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001313 /// 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 RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001316 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001317 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001318 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001319 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001320 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 }
Mike Stump11289f42009-09-09 15:08:12 +00001322
Douglas Gregora16548e2009-08-11 05:31:07 +00001323 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001324 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001325 /// By default, performs semantic analysis to build the new expression.
1326 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001327 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001328 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001329 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001330 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001331 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001332 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 }
Mike Stump11289f42009-09-09 15:08:12 +00001334
Douglas Gregora16548e2009-08-11 05:31:07 +00001335 /// \brief Build a new extended vector element access expression.
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 RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001340 SourceLocation OpLoc,
1341 SourceLocation AccessorLoc,
1342 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001343
John McCall10eae182009-11-30 22:42:35 +00001344 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001345 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001346 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001347 OpLoc, /*IsArrow*/ false,
1348 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001349 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001350 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001351 }
Mike Stump11289f42009-09-09 15:08:12 +00001352
Douglas Gregora16548e2009-08-11 05:31:07 +00001353 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001354 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 /// By default, performs semantic analysis to build the new expression.
1356 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001357 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001358 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001359 SourceLocation RBraceLoc,
1360 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001361 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001362 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1363 if (Result.isInvalid() || ResultTy->isDependentType())
1364 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001365
Douglas Gregord3d93062009-11-09 17:16:50 +00001366 // Patch in the result type we were given, which may have been computed
1367 // when the initial InitListExpr was built.
1368 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1369 ILE->setType(ResultTy);
1370 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001371 }
Mike Stump11289f42009-09-09 15:08:12 +00001372
Douglas Gregora16548e2009-08-11 05:31:07 +00001373 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001374 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001375 /// By default, performs semantic analysis to build the new expression.
1376 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001377 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001378 MultiExprArg ArrayExprs,
1379 SourceLocation EqualOrColonLoc,
1380 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001381 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001382 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001383 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001384 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001385 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001386 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001387
Douglas Gregora16548e2009-08-11 05:31:07 +00001388 ArrayExprs.release();
1389 return move(Result);
1390 }
Mike Stump11289f42009-09-09 15:08:12 +00001391
Douglas Gregora16548e2009-08-11 05:31:07 +00001392 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001393 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001394 /// By default, builds the implicit value initialization without performing
1395 /// any semantic analysis. Subclasses may override this routine to provide
1396 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001397 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001398 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1399 }
Mike Stump11289f42009-09-09 15:08:12 +00001400
Douglas Gregora16548e2009-08-11 05:31:07 +00001401 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001402 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001403 /// By default, performs semantic analysis to build the new expression.
1404 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001405 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001406 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001407 SourceLocation RParenLoc) {
1408 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001409 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001410 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001411 }
1412
1413 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001414 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001415 /// By default, performs semantic analysis to build the new expression.
1416 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001417 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001418 MultiExprArg SubExprs,
1419 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001420 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001421 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001422 }
Mike Stump11289f42009-09-09 15:08:12 +00001423
Douglas Gregora16548e2009-08-11 05:31:07 +00001424 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001425 ///
1426 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001427 /// rather than attempting to map the label statement itself.
1428 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001429 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001430 SourceLocation LabelLoc,
1431 LabelStmt *Label) {
1432 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1433 }
Mike Stump11289f42009-09-09 15:08:12 +00001434
Douglas Gregora16548e2009-08-11 05:31:07 +00001435 /// \brief Build a new GNU statement 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 RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001440 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001441 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001442 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001443 }
Mike Stump11289f42009-09-09 15:08:12 +00001444
Douglas Gregora16548e2009-08-11 05:31:07 +00001445 /// \brief Build a new __builtin_choose_expr expression.
1446 ///
1447 /// By default, performs semantic analysis to build the new expression.
1448 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001449 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001450 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001451 SourceLocation RParenLoc) {
1452 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001453 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001454 RParenLoc);
1455 }
Mike Stump11289f42009-09-09 15:08:12 +00001456
Douglas Gregora16548e2009-08-11 05:31:07 +00001457 /// \brief Build a new overloaded operator call expression.
1458 ///
1459 /// By default, performs semantic analysis to build the new expression.
1460 /// The semantic analysis provides the behavior of template instantiation,
1461 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001462 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001463 /// argument-dependent lookup, etc. Subclasses may override this routine to
1464 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001465 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001466 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001467 Expr *Callee,
1468 Expr *First,
1469 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001470
1471 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001472 /// reinterpret_cast.
1473 ///
1474 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001475 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001476 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001477 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001478 Stmt::StmtClass Class,
1479 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001480 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001481 SourceLocation RAngleLoc,
1482 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001483 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001484 SourceLocation RParenLoc) {
1485 switch (Class) {
1486 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001487 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001488 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001489 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001490
1491 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001492 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001493 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001494 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001495
Douglas Gregora16548e2009-08-11 05:31:07 +00001496 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001497 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001498 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001499 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001500 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001501
Douglas Gregora16548e2009-08-11 05:31:07 +00001502 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001503 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001504 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001505 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001506
Douglas Gregora16548e2009-08-11 05:31:07 +00001507 default:
1508 assert(false && "Invalid C++ named cast");
1509 break;
1510 }
Mike Stump11289f42009-09-09 15:08:12 +00001511
John McCallfaf5fb42010-08-26 23:41:50 +00001512 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001513 }
Mike Stump11289f42009-09-09 15:08:12 +00001514
Douglas Gregora16548e2009-08-11 05:31:07 +00001515 /// \brief Build a new C++ static_cast expression.
1516 ///
1517 /// By default, performs semantic analysis to build the new expression.
1518 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001519 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001520 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001521 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 SourceLocation RAngleLoc,
1523 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001524 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001525 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001526 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001527 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001528 SourceRange(LAngleLoc, RAngleLoc),
1529 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001530 }
1531
1532 /// \brief Build a new C++ dynamic_cast expression.
1533 ///
1534 /// By default, performs semantic analysis to build the new expression.
1535 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001536 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001537 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001538 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001539 SourceLocation RAngleLoc,
1540 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001541 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001542 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001543 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001544 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001545 SourceRange(LAngleLoc, RAngleLoc),
1546 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001547 }
1548
1549 /// \brief Build a new C++ reinterpret_cast expression.
1550 ///
1551 /// By default, performs semantic analysis to build the new expression.
1552 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001553 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001554 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001555 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001556 SourceLocation RAngleLoc,
1557 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001558 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001559 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001560 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001561 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001562 SourceRange(LAngleLoc, RAngleLoc),
1563 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001564 }
1565
1566 /// \brief Build a new C++ const_cast expression.
1567 ///
1568 /// By default, performs semantic analysis to build the new expression.
1569 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001570 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001571 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001572 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001573 SourceLocation RAngleLoc,
1574 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001575 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001576 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001577 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001578 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001579 SourceRange(LAngleLoc, RAngleLoc),
1580 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001581 }
Mike Stump11289f42009-09-09 15:08:12 +00001582
Douglas Gregora16548e2009-08-11 05:31:07 +00001583 /// \brief Build a new C++ functional-style cast expression.
1584 ///
1585 /// By default, performs semantic analysis to build the new expression.
1586 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001587 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1588 SourceLocation LParenLoc,
1589 Expr *Sub,
1590 SourceLocation RParenLoc) {
1591 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001592 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001593 RParenLoc);
1594 }
Mike Stump11289f42009-09-09 15:08:12 +00001595
Douglas Gregora16548e2009-08-11 05:31:07 +00001596 /// \brief Build a new C++ typeid(type) expression.
1597 ///
1598 /// By default, performs semantic analysis to build the new expression.
1599 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001600 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001601 SourceLocation TypeidLoc,
1602 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001603 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001604 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001605 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001606 }
Mike Stump11289f42009-09-09 15:08:12 +00001607
Francois Pichet9f4f2072010-09-08 12:20:18 +00001608
Douglas Gregora16548e2009-08-11 05:31:07 +00001609 /// \brief Build a new C++ typeid(expr) expression.
1610 ///
1611 /// By default, performs semantic analysis to build the new expression.
1612 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001613 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001614 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001615 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001616 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001617 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001618 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001619 }
1620
Francois Pichet9f4f2072010-09-08 12:20:18 +00001621 /// \brief Build a new C++ __uuidof(type) expression.
1622 ///
1623 /// By default, performs semantic analysis to build the new expression.
1624 /// Subclasses may override this routine to provide different behavior.
1625 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1626 SourceLocation TypeidLoc,
1627 TypeSourceInfo *Operand,
1628 SourceLocation RParenLoc) {
1629 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1630 RParenLoc);
1631 }
1632
1633 /// \brief Build a new C++ __uuidof(expr) expression.
1634 ///
1635 /// By default, performs semantic analysis to build the new expression.
1636 /// Subclasses may override this routine to provide different behavior.
1637 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1638 SourceLocation TypeidLoc,
1639 Expr *Operand,
1640 SourceLocation RParenLoc) {
1641 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1642 RParenLoc);
1643 }
1644
Douglas Gregora16548e2009-08-11 05:31:07 +00001645 /// \brief Build a new C++ "this" expression.
1646 ///
1647 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001648 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001649 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001650 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001651 QualType ThisType,
1652 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001653 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001654 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1655 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001656 }
1657
1658 /// \brief Build a new C++ throw expression.
1659 ///
1660 /// By default, performs semantic analysis to build the new expression.
1661 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001662 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001663 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001664 }
1665
1666 /// \brief Build a new C++ default-argument expression.
1667 ///
1668 /// By default, builds a new default-argument expression, which does not
1669 /// require any semantic analysis. Subclasses may override this routine to
1670 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001671 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001672 ParmVarDecl *Param) {
1673 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1674 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001675 }
1676
1677 /// \brief Build a new C++ zero-initialization expression.
1678 ///
1679 /// By default, performs semantic analysis to build the new expression.
1680 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001681 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1682 SourceLocation LParenLoc,
1683 SourceLocation RParenLoc) {
1684 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001685 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001686 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001687 }
Mike Stump11289f42009-09-09 15:08:12 +00001688
Douglas Gregora16548e2009-08-11 05:31:07 +00001689 /// \brief Build a new C++ "new" expression.
1690 ///
1691 /// By default, performs semantic analysis to build the new expression.
1692 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001693 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001694 bool UseGlobal,
1695 SourceLocation PlacementLParen,
1696 MultiExprArg PlacementArgs,
1697 SourceLocation PlacementRParen,
1698 SourceRange TypeIdParens,
1699 QualType AllocatedType,
1700 TypeSourceInfo *AllocatedTypeInfo,
1701 Expr *ArraySize,
1702 SourceLocation ConstructorLParen,
1703 MultiExprArg ConstructorArgs,
1704 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001705 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001706 PlacementLParen,
1707 move(PlacementArgs),
1708 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001709 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001710 AllocatedType,
1711 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001712 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001713 ConstructorLParen,
1714 move(ConstructorArgs),
1715 ConstructorRParen);
1716 }
Mike Stump11289f42009-09-09 15:08:12 +00001717
Douglas Gregora16548e2009-08-11 05:31:07 +00001718 /// \brief Build a new C++ "delete" expression.
1719 ///
1720 /// By default, performs semantic analysis to build the new expression.
1721 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001722 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001723 bool IsGlobalDelete,
1724 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001725 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001726 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001727 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001728 }
Mike Stump11289f42009-09-09 15:08:12 +00001729
Douglas Gregora16548e2009-08-11 05:31:07 +00001730 /// \brief Build a new unary type trait expression.
1731 ///
1732 /// By default, performs semantic analysis to build the new expression.
1733 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001734 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001735 SourceLocation StartLoc,
1736 TypeSourceInfo *T,
1737 SourceLocation RParenLoc) {
1738 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001739 }
1740
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001741 /// \brief Build a new binary type trait expression.
1742 ///
1743 /// By default, performs semantic analysis to build the new expression.
1744 /// Subclasses may override this routine to provide different behavior.
1745 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1746 SourceLocation StartLoc,
1747 TypeSourceInfo *LhsT,
1748 TypeSourceInfo *RhsT,
1749 SourceLocation RParenLoc) {
1750 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1751 }
1752
Mike Stump11289f42009-09-09 15:08:12 +00001753 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001754 /// expression.
1755 ///
1756 /// By default, performs semantic analysis to build the new expression.
1757 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001758 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001759 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001760 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001761 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001762 CXXScopeSpec SS;
1763 SS.setRange(QualifierRange);
1764 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001765
1766 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001767 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001768 *TemplateArgs);
1769
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001770 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001771 }
1772
1773 /// \brief Build a new template-id expression.
1774 ///
1775 /// By default, performs semantic analysis to build the new expression.
1776 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001777 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001778 LookupResult &R,
1779 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001780 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001781 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001782 }
1783
1784 /// \brief Build a new object-construction expression.
1785 ///
1786 /// By default, performs semantic analysis to build the new expression.
1787 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001788 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001789 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001790 CXXConstructorDecl *Constructor,
1791 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001792 MultiExprArg Args,
1793 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001794 CXXConstructExpr::ConstructionKind ConstructKind,
1795 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001796 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001797 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001798 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001799 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001800
Douglas Gregordb121ba2009-12-14 16:27:04 +00001801 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001802 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001803 RequiresZeroInit, ConstructKind,
1804 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001805 }
1806
1807 /// \brief Build a new object-construction expression.
1808 ///
1809 /// By default, performs semantic analysis to build the new expression.
1810 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001811 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1812 SourceLocation LParenLoc,
1813 MultiExprArg Args,
1814 SourceLocation RParenLoc) {
1815 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001816 LParenLoc,
1817 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001818 RParenLoc);
1819 }
1820
1821 /// \brief Build a new object-construction expression.
1822 ///
1823 /// By default, performs semantic analysis to build the new expression.
1824 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001825 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1826 SourceLocation LParenLoc,
1827 MultiExprArg Args,
1828 SourceLocation RParenLoc) {
1829 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001830 LParenLoc,
1831 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001832 RParenLoc);
1833 }
Mike Stump11289f42009-09-09 15:08:12 +00001834
Douglas Gregora16548e2009-08-11 05:31:07 +00001835 /// \brief Build a new member reference expression.
1836 ///
1837 /// By default, performs semantic analysis to build the new expression.
1838 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001839 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001840 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001841 bool IsArrow,
1842 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001843 NestedNameSpecifier *Qualifier,
1844 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001845 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001846 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001847 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001848 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001849 SS.setRange(QualifierRange);
1850 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001851
John McCallb268a282010-08-23 23:25:46 +00001852 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001853 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001854 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001855 MemberNameInfo,
1856 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001857 }
1858
John McCall10eae182009-11-30 22:42:35 +00001859 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001860 ///
1861 /// By default, performs semantic analysis to build the new expression.
1862 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001863 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001864 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001865 SourceLocation OperatorLoc,
1866 bool IsArrow,
1867 NestedNameSpecifier *Qualifier,
1868 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001869 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001870 LookupResult &R,
1871 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001872 CXXScopeSpec SS;
1873 SS.setRange(QualifierRange);
1874 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001875
John McCallb268a282010-08-23 23:25:46 +00001876 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001877 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001878 SS, FirstQualifierInScope,
1879 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001880 }
Mike Stump11289f42009-09-09 15:08:12 +00001881
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001882 /// \brief Build a new noexcept expression.
1883 ///
1884 /// By default, performs semantic analysis to build the new expression.
1885 /// Subclasses may override this routine to provide different behavior.
1886 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1887 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1888 }
1889
Douglas Gregora16548e2009-08-11 05:31:07 +00001890 /// \brief Build a new Objective-C @encode expression.
1891 ///
1892 /// By default, performs semantic analysis to build the new expression.
1893 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001894 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001895 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001896 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001897 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001898 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001899 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001900
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001901 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00001902 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001903 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00001904 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001905 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001906 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001907 MultiExprArg Args,
1908 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001909 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1910 ReceiverTypeInfo->getType(),
1911 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00001912 Sel, Method, LBracLoc, SelectorLoc,
1913 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001914 }
1915
1916 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00001917 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001918 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00001919 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001920 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001921 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001922 MultiExprArg Args,
1923 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00001924 return SemaRef.BuildInstanceMessage(Receiver,
1925 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001926 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00001927 Sel, Method, LBracLoc, SelectorLoc,
1928 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001929 }
1930
Douglas Gregord51d90d2010-04-26 20:11:03 +00001931 /// \brief Build a new Objective-C ivar reference expression.
1932 ///
1933 /// By default, performs semantic analysis to build the new expression.
1934 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001935 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001936 SourceLocation IvarLoc,
1937 bool IsArrow, bool IsFreeIvar) {
1938 // FIXME: We lose track of the IsFreeIvar bit.
1939 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001940 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001941 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1942 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001943 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001944 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00001945 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00001946 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001947 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001948 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001949
Douglas Gregord51d90d2010-04-26 20:11:03 +00001950 if (Result.get())
1951 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001952
John McCallb268a282010-08-23 23:25:46 +00001953 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001954 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001955 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001956 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001957 /*TemplateArgs=*/0);
1958 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001959
1960 /// \brief Build a new Objective-C property reference expression.
1961 ///
1962 /// By default, performs semantic analysis to build the new expression.
1963 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001964 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001965 ObjCPropertyDecl *Property,
1966 SourceLocation PropertyLoc) {
1967 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001968 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00001969 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1970 Sema::LookupMemberName);
1971 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00001972 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00001973 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00001974 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00001975 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001976 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001977
Douglas Gregor9faee212010-04-26 20:47:02 +00001978 if (Result.get())
1979 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001980
John McCallb268a282010-08-23 23:25:46 +00001981 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001982 /*FIXME:*/PropertyLoc, IsArrow,
1983 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001984 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001985 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001986 /*TemplateArgs=*/0);
1987 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001988
John McCallb7bd14f2010-12-02 01:19:52 +00001989 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001990 ///
1991 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00001992 /// Subclasses may override this routine to provide different behavior.
1993 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
1994 ObjCMethodDecl *Getter,
1995 ObjCMethodDecl *Setter,
1996 SourceLocation PropertyLoc) {
1997 // Since these expressions can only be value-dependent, we do not
1998 // need to perform semantic analysis again.
1999 return Owned(
2000 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2001 VK_LValue, OK_ObjCProperty,
2002 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002003 }
2004
Douglas Gregord51d90d2010-04-26 20:11:03 +00002005 /// \brief Build a new Objective-C "isa" expression.
2006 ///
2007 /// By default, performs semantic analysis to build the new expression.
2008 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002009 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002010 bool IsArrow) {
2011 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002012 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002013 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2014 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002015 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002016 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002017 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002018 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002019 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002020
Douglas Gregord51d90d2010-04-26 20:11:03 +00002021 if (Result.get())
2022 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002023
John McCallb268a282010-08-23 23:25:46 +00002024 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002025 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002026 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002027 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002028 /*TemplateArgs=*/0);
2029 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002030
Douglas Gregora16548e2009-08-11 05:31:07 +00002031 /// \brief Build a new shuffle vector 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 RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002036 MultiExprArg SubExprs,
2037 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002038 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002039 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002040 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2041 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2042 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2043 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002044
Douglas Gregora16548e2009-08-11 05:31:07 +00002045 // Build a reference to the __builtin_shufflevector builtin
2046 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00002047 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00002048 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00002049 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002050 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002051
2052 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002053 unsigned NumSubExprs = SubExprs.size();
2054 Expr **Subs = (Expr **)SubExprs.release();
2055 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2056 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002057 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002058 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002059 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002060 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002061
Douglas Gregora16548e2009-08-11 05:31:07 +00002062 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002063 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002064 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002065 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002066
Douglas Gregora16548e2009-08-11 05:31:07 +00002067 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002068 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002069 }
John McCall31f82722010-11-12 08:19:04 +00002070
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002071 /// \brief Build a new template argument pack expansion.
2072 ///
2073 /// By default, performs semantic analysis to build a new pack expansion
2074 /// for a template argument. Subclasses may override this routine to provide
2075 /// different behavior.
2076 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
2077 SourceLocation EllipsisLoc) {
2078 switch (Pattern.getArgument().getKind()) {
2079 case TemplateArgument::Expression:
2080 case TemplateArgument::Template:
2081 llvm_unreachable("Unsupported pack expansion of expressions/templates");
2082
2083 case TemplateArgument::Null:
2084 case TemplateArgument::Integral:
2085 case TemplateArgument::Declaration:
2086 case TemplateArgument::Pack:
2087 llvm_unreachable("Pack expansion pattern has no parameter packs");
2088
2089 case TemplateArgument::Type:
2090 if (TypeSourceInfo *Expansion
2091 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
2092 EllipsisLoc))
2093 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2094 Expansion);
2095 break;
2096 }
2097
2098 return TemplateArgumentLoc();
2099 }
2100
John McCall31f82722010-11-12 08:19:04 +00002101private:
2102 QualType TransformTypeInObjectScope(QualType T,
2103 QualType ObjectType,
2104 NamedDecl *FirstQualifierInScope,
2105 NestedNameSpecifier *Prefix);
2106
2107 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2108 QualType ObjectType,
2109 NamedDecl *FirstQualifierInScope,
2110 NestedNameSpecifier *Prefix);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002111};
Douglas Gregora16548e2009-08-11 05:31:07 +00002112
Douglas Gregorebe10102009-08-20 07:17:43 +00002113template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002114StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002115 if (!S)
2116 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002117
Douglas Gregorebe10102009-08-20 07:17:43 +00002118 switch (S->getStmtClass()) {
2119 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002120
Douglas Gregorebe10102009-08-20 07:17:43 +00002121 // Transform individual statement nodes
2122#define STMT(Node, Parent) \
2123 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2124#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002125#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002126
Douglas Gregorebe10102009-08-20 07:17:43 +00002127 // Transform expressions by calling TransformExpr.
2128#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002129#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002130#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002131#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002132 {
John McCalldadc5752010-08-24 06:29:42 +00002133 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002134 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002135 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002136
John McCallb268a282010-08-23 23:25:46 +00002137 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002138 }
Mike Stump11289f42009-09-09 15:08:12 +00002139 }
2140
John McCallc3007a22010-10-26 07:05:15 +00002141 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002142}
Mike Stump11289f42009-09-09 15:08:12 +00002143
2144
Douglas Gregore922c772009-08-04 22:27:00 +00002145template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002146ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002147 if (!E)
2148 return SemaRef.Owned(E);
2149
2150 switch (E->getStmtClass()) {
2151 case Stmt::NoStmtClass: break;
2152#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002153#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002154#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002155 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002156#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002157 }
2158
John McCallc3007a22010-10-26 07:05:15 +00002159 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002160}
2161
2162template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002163NestedNameSpecifier *
2164TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002165 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002166 QualType ObjectType,
2167 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002168 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002169
Douglas Gregorebe10102009-08-20 07:17:43 +00002170 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002171 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002172 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002173 ObjectType,
2174 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002175 if (!Prefix)
2176 return 0;
2177 }
Mike Stump11289f42009-09-09 15:08:12 +00002178
Douglas Gregor1135c352009-08-06 05:28:30 +00002179 switch (NNS->getKind()) {
2180 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002181 if (Prefix) {
2182 // The object type and qualifier-in-scope really apply to the
2183 // leftmost entity.
2184 ObjectType = QualType();
2185 FirstQualifierInScope = 0;
2186 }
2187
Mike Stump11289f42009-09-09 15:08:12 +00002188 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002189 "Identifier nested-name-specifier with no prefix or object type");
2190 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2191 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002192 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002193
2194 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002195 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002196 ObjectType,
2197 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002198
Douglas Gregor1135c352009-08-06 05:28:30 +00002199 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002200 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002201 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002202 getDerived().TransformDecl(Range.getBegin(),
2203 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002204 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002205 Prefix == NNS->getPrefix() &&
2206 NS == NNS->getAsNamespace())
2207 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002208
Douglas Gregor1135c352009-08-06 05:28:30 +00002209 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2210 }
Mike Stump11289f42009-09-09 15:08:12 +00002211
Douglas Gregor1135c352009-08-06 05:28:30 +00002212 case NestedNameSpecifier::Global:
2213 // There is no meaningful transformation that one could perform on the
2214 // global scope.
2215 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002216
Douglas Gregor1135c352009-08-06 05:28:30 +00002217 case NestedNameSpecifier::TypeSpecWithTemplate:
2218 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002219 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002220 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2221 ObjectType,
2222 FirstQualifierInScope,
2223 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002224 if (T.isNull())
2225 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002226
Douglas Gregor1135c352009-08-06 05:28:30 +00002227 if (!getDerived().AlwaysRebuild() &&
2228 Prefix == NNS->getPrefix() &&
2229 T == QualType(NNS->getAsType(), 0))
2230 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002231
2232 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2233 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002234 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002235 }
2236 }
Mike Stump11289f42009-09-09 15:08:12 +00002237
Douglas Gregor1135c352009-08-06 05:28:30 +00002238 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002239 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002240}
2241
2242template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002243DeclarationNameInfo
2244TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002245::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002246 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002247 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002248 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002249
2250 switch (Name.getNameKind()) {
2251 case DeclarationName::Identifier:
2252 case DeclarationName::ObjCZeroArgSelector:
2253 case DeclarationName::ObjCOneArgSelector:
2254 case DeclarationName::ObjCMultiArgSelector:
2255 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002256 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002257 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002258 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002259
Douglas Gregorf816bd72009-09-03 22:13:48 +00002260 case DeclarationName::CXXConstructorName:
2261 case DeclarationName::CXXDestructorName:
2262 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002263 TypeSourceInfo *NewTInfo;
2264 CanQualType NewCanTy;
2265 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002266 NewTInfo = getDerived().TransformType(OldTInfo);
2267 if (!NewTInfo)
2268 return DeclarationNameInfo();
2269 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002270 }
2271 else {
2272 NewTInfo = 0;
2273 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002274 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002275 if (NewT.isNull())
2276 return DeclarationNameInfo();
2277 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2278 }
Mike Stump11289f42009-09-09 15:08:12 +00002279
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002280 DeclarationName NewName
2281 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2282 NewCanTy);
2283 DeclarationNameInfo NewNameInfo(NameInfo);
2284 NewNameInfo.setName(NewName);
2285 NewNameInfo.setNamedTypeInfo(NewTInfo);
2286 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002287 }
Mike Stump11289f42009-09-09 15:08:12 +00002288 }
2289
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002290 assert(0 && "Unknown name kind.");
2291 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002292}
2293
2294template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002295TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002296TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002297 QualType ObjectType,
2298 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002299 SourceLocation Loc = getDerived().getBaseLocation();
2300
Douglas Gregor71dc5092009-08-06 06:41:21 +00002301 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002302 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002303 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002304 /*FIXME*/ SourceRange(Loc),
2305 ObjectType,
2306 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002307 if (!NNS)
2308 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002309
Douglas Gregor71dc5092009-08-06 06:41:21 +00002310 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002311 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002312 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002313 if (!TransTemplate)
2314 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002315
Douglas Gregor71dc5092009-08-06 06:41:21 +00002316 if (!getDerived().AlwaysRebuild() &&
2317 NNS == QTN->getQualifier() &&
2318 TransTemplate == Template)
2319 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002320
Douglas Gregor71dc5092009-08-06 06:41:21 +00002321 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2322 TransTemplate);
2323 }
Mike Stump11289f42009-09-09 15:08:12 +00002324
John McCalle66edc12009-11-24 19:00:30 +00002325 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002326 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002327 }
Mike Stump11289f42009-09-09 15:08:12 +00002328
Douglas Gregor71dc5092009-08-06 06:41:21 +00002329 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002330 NestedNameSpecifier *NNS = DTN->getQualifier();
2331 if (NNS) {
2332 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2333 /*FIXME:*/SourceRange(Loc),
2334 ObjectType,
2335 FirstQualifierInScope);
2336 if (!NNS) return TemplateName();
2337
2338 // These apply to the scope specifier, not the template.
2339 ObjectType = QualType();
2340 FirstQualifierInScope = 0;
2341 }
Mike Stump11289f42009-09-09 15:08:12 +00002342
Douglas Gregor71dc5092009-08-06 06:41:21 +00002343 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002344 NNS == DTN->getQualifier() &&
2345 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002346 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002347
Douglas Gregora5614c52010-09-08 23:56:00 +00002348 if (DTN->isIdentifier()) {
2349 // FIXME: Bad range
2350 SourceRange QualifierRange(getDerived().getBaseLocation());
2351 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2352 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002353 ObjectType,
2354 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002355 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002356
2357 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002358 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002359 }
Mike Stump11289f42009-09-09 15:08:12 +00002360
Douglas Gregor71dc5092009-08-06 06:41:21 +00002361 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002362 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002363 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002364 if (!TransTemplate)
2365 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002366
Douglas Gregor71dc5092009-08-06 06:41:21 +00002367 if (!getDerived().AlwaysRebuild() &&
2368 TransTemplate == Template)
2369 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002370
Douglas Gregor71dc5092009-08-06 06:41:21 +00002371 return TemplateName(TransTemplate);
2372 }
Mike Stump11289f42009-09-09 15:08:12 +00002373
John McCalle66edc12009-11-24 19:00:30 +00002374 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002375 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002376 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002377}
2378
2379template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002380void TreeTransform<Derived>::InventTemplateArgumentLoc(
2381 const TemplateArgument &Arg,
2382 TemplateArgumentLoc &Output) {
2383 SourceLocation Loc = getDerived().getBaseLocation();
2384 switch (Arg.getKind()) {
2385 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002386 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002387 break;
2388
2389 case TemplateArgument::Type:
2390 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002391 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002392
John McCall0ad16662009-10-29 08:12:44 +00002393 break;
2394
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002395 case TemplateArgument::Template:
2396 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2397 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002398
John McCall0ad16662009-10-29 08:12:44 +00002399 case TemplateArgument::Expression:
2400 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2401 break;
2402
2403 case TemplateArgument::Declaration:
2404 case TemplateArgument::Integral:
2405 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002406 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002407 break;
2408 }
2409}
2410
2411template<typename Derived>
2412bool TreeTransform<Derived>::TransformTemplateArgument(
2413 const TemplateArgumentLoc &Input,
2414 TemplateArgumentLoc &Output) {
2415 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002416 switch (Arg.getKind()) {
2417 case TemplateArgument::Null:
2418 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002419 Output = Input;
2420 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002421
Douglas Gregore922c772009-08-04 22:27:00 +00002422 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002423 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002424 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002425 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002426
2427 DI = getDerived().TransformType(DI);
2428 if (!DI) return true;
2429
2430 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2431 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002432 }
Mike Stump11289f42009-09-09 15:08:12 +00002433
Douglas Gregore922c772009-08-04 22:27:00 +00002434 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002435 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002436 DeclarationName Name;
2437 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2438 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002439 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002440 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002441 if (!D) return true;
2442
John McCall0d07eb32009-10-29 18:45:58 +00002443 Expr *SourceExpr = Input.getSourceDeclExpression();
2444 if (SourceExpr) {
2445 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002446 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002447 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002448 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002449 }
2450
2451 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002452 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002453 }
Mike Stump11289f42009-09-09 15:08:12 +00002454
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002455 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002456 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002457 TemplateName Template
2458 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2459 if (Template.isNull())
2460 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002461
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002462 Output = TemplateArgumentLoc(TemplateArgument(Template),
2463 Input.getTemplateQualifierRange(),
2464 Input.getTemplateNameLoc());
2465 return false;
2466 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002467
Douglas Gregore922c772009-08-04 22:27:00 +00002468 case TemplateArgument::Expression: {
2469 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002470 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002471 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002472
John McCall0ad16662009-10-29 08:12:44 +00002473 Expr *InputExpr = Input.getSourceExpression();
2474 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2475
John McCalldadc5752010-08-24 06:29:42 +00002476 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002477 = getDerived().TransformExpr(InputExpr);
2478 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002479 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002480 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002481 }
Mike Stump11289f42009-09-09 15:08:12 +00002482
Douglas Gregore922c772009-08-04 22:27:00 +00002483 case TemplateArgument::Pack: {
2484 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2485 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002486 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002487 AEnd = Arg.pack_end();
2488 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002489
John McCall0ad16662009-10-29 08:12:44 +00002490 // FIXME: preserve source information here when we start
2491 // caring about parameter packs.
2492
John McCall0d07eb32009-10-29 18:45:58 +00002493 TemplateArgumentLoc InputArg;
2494 TemplateArgumentLoc OutputArg;
2495 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2496 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002497 return true;
2498
John McCall0d07eb32009-10-29 18:45:58 +00002499 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002500 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002501
2502 TemplateArgument *TransformedArgsPtr
2503 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2504 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2505 TransformedArgsPtr);
2506 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2507 TransformedArgs.size()),
2508 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002509 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002510 }
2511 }
Mike Stump11289f42009-09-09 15:08:12 +00002512
Douglas Gregore922c772009-08-04 22:27:00 +00002513 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002514 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002515}
2516
Douglas Gregorfe921a72010-12-20 23:36:19 +00002517/// \brief Iterator adaptor that invents template argument location information
2518/// for each of the template arguments in its underlying iterator.
2519template<typename Derived, typename InputIterator>
2520class TemplateArgumentLocInventIterator {
2521 TreeTransform<Derived> &Self;
2522 InputIterator Iter;
2523
2524public:
2525 typedef TemplateArgumentLoc value_type;
2526 typedef TemplateArgumentLoc reference;
2527 typedef typename std::iterator_traits<InputIterator>::difference_type
2528 difference_type;
2529 typedef std::input_iterator_tag iterator_category;
2530
2531 class pointer {
2532 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002533
Douglas Gregorfe921a72010-12-20 23:36:19 +00002534 public:
2535 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2536
2537 const TemplateArgumentLoc *operator->() const { return &Arg; }
2538 };
2539
2540 TemplateArgumentLocInventIterator() { }
2541
2542 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2543 InputIterator Iter)
2544 : Self(Self), Iter(Iter) { }
2545
2546 TemplateArgumentLocInventIterator &operator++() {
2547 ++Iter;
2548 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002549 }
2550
Douglas Gregorfe921a72010-12-20 23:36:19 +00002551 TemplateArgumentLocInventIterator operator++(int) {
2552 TemplateArgumentLocInventIterator Old(*this);
2553 ++(*this);
2554 return Old;
2555 }
2556
2557 reference operator*() const {
2558 TemplateArgumentLoc Result;
2559 Self.InventTemplateArgumentLoc(*Iter, Result);
2560 return Result;
2561 }
2562
2563 pointer operator->() const { return pointer(**this); }
2564
2565 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2566 const TemplateArgumentLocInventIterator &Y) {
2567 return X.Iter == Y.Iter;
2568 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002569
Douglas Gregorfe921a72010-12-20 23:36:19 +00002570 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2571 const TemplateArgumentLocInventIterator &Y) {
2572 return X.Iter != Y.Iter;
2573 }
2574};
2575
Douglas Gregor42cafa82010-12-20 17:42:22 +00002576template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002577template<typename InputIterator>
2578bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2579 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002580 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002581 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002582 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002583 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002584
2585 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2586 // Unpack argument packs, which we translate them into separate
2587 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002588 // FIXME: We could do much better if we could guarantee that the
2589 // TemplateArgumentLocInfo for the pack expansion would be usable for
2590 // all of the template arguments in the argument pack.
2591 typedef TemplateArgumentLocInventIterator<Derived,
2592 TemplateArgument::pack_iterator>
2593 PackLocIterator;
2594 if (TransformTemplateArguments(PackLocIterator(*this,
2595 In.getArgument().pack_begin()),
2596 PackLocIterator(*this,
2597 In.getArgument().pack_end()),
2598 Outputs))
2599 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002600
2601 continue;
2602 }
2603
2604 if (In.getArgument().isPackExpansion()) {
2605 // We have a pack expansion, for which we will be substituting into
2606 // the pattern.
2607 SourceLocation Ellipsis;
2608 TemplateArgumentLoc Pattern
2609 = In.getPackExpansionPattern(Ellipsis, getSema().Context);
2610
2611 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2612 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2613 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2614
2615 // Determine whether the set of unexpanded parameter packs can and should
2616 // be expanded.
2617 bool Expand = true;
2618 unsigned NumExpansions = 0;
2619 if (getDerived().TryExpandParameterPacks(Ellipsis,
2620 Pattern.getSourceRange(),
2621 Unexpanded.data(),
2622 Unexpanded.size(),
2623 Expand, NumExpansions))
2624 return true;
2625
2626 if (!Expand) {
2627 // The transform has determined that we should perform a simple
2628 // transformation on the pack expansion, producing another pack
2629 // expansion.
2630 TemplateArgumentLoc OutPattern;
2631 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2632 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2633 return true;
2634
2635 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis);
2636 if (Out.getArgument().isNull())
2637 return true;
2638
2639 Outputs.addArgument(Out);
2640 continue;
2641 }
2642
2643 // The transform has determined that we should perform an elementwise
2644 // expansion of the pattern. Do so.
2645 for (unsigned I = 0; I != NumExpansions; ++I) {
2646 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2647
2648 if (getDerived().TransformTemplateArgument(Pattern, Out))
2649 return true;
2650
2651 Outputs.addArgument(Out);
2652 }
2653
2654 continue;
2655 }
2656
2657 // The simple case:
2658 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00002659 return true;
2660
2661 Outputs.addArgument(Out);
2662 }
2663
2664 return false;
2665
2666}
2667
Douglas Gregord6ff3322009-08-04 16:50:30 +00002668//===----------------------------------------------------------------------===//
2669// Type transformation
2670//===----------------------------------------------------------------------===//
2671
2672template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002673QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002674 if (getDerived().AlreadyTransformed(T))
2675 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002676
John McCall550e0c22009-10-21 00:40:46 +00002677 // Temporary workaround. All of these transformations should
2678 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002679 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002680 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002681
John McCall31f82722010-11-12 08:19:04 +00002682 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002683
John McCall550e0c22009-10-21 00:40:46 +00002684 if (!NewDI)
2685 return QualType();
2686
2687 return NewDI->getType();
2688}
2689
2690template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002691TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002692 if (getDerived().AlreadyTransformed(DI->getType()))
2693 return DI;
2694
2695 TypeLocBuilder TLB;
2696
2697 TypeLoc TL = DI->getTypeLoc();
2698 TLB.reserve(TL.getFullDataSize());
2699
John McCall31f82722010-11-12 08:19:04 +00002700 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00002701 if (Result.isNull())
2702 return 0;
2703
John McCallbcd03502009-12-07 02:54:59 +00002704 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002705}
2706
2707template<typename Derived>
2708QualType
John McCall31f82722010-11-12 08:19:04 +00002709TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00002710 switch (T.getTypeLocClass()) {
2711#define ABSTRACT_TYPELOC(CLASS, PARENT)
2712#define TYPELOC(CLASS, PARENT) \
2713 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00002714 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00002715#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002716 }
Mike Stump11289f42009-09-09 15:08:12 +00002717
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002718 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002719 return QualType();
2720}
2721
2722/// FIXME: By default, this routine adds type qualifiers only to types
2723/// that can have qualifiers, and silently suppresses those qualifiers
2724/// that are not permitted (e.g., qualifiers on reference or function
2725/// types). This is the right thing for template instantiation, but
2726/// probably not for other clients.
2727template<typename Derived>
2728QualType
2729TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002730 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002731 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002732
John McCall31f82722010-11-12 08:19:04 +00002733 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00002734 if (Result.isNull())
2735 return QualType();
2736
2737 // Silently suppress qualifiers if the result type can't be qualified.
2738 // FIXME: this is the right thing for template instantiation, but
2739 // probably not for other clients.
2740 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002741 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002742
John McCallcb0f89a2010-06-05 06:41:15 +00002743 if (!Quals.empty()) {
2744 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2745 TLB.push<QualifiedTypeLoc>(Result);
2746 // No location information to preserve.
2747 }
John McCall550e0c22009-10-21 00:40:46 +00002748
2749 return Result;
2750}
2751
John McCall31f82722010-11-12 08:19:04 +00002752/// \brief Transforms a type that was written in a scope specifier,
2753/// given an object type, the results of unqualified lookup, and
2754/// an already-instantiated prefix.
2755///
2756/// The object type is provided iff the scope specifier qualifies the
2757/// member of a dependent member-access expression. The prefix is
2758/// provided iff the the scope specifier in which this appears has a
2759/// prefix.
2760///
2761/// This is private to TreeTransform.
2762template<typename Derived>
2763QualType
2764TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
2765 QualType ObjectType,
2766 NamedDecl *UnqualLookup,
2767 NestedNameSpecifier *Prefix) {
2768 if (getDerived().AlreadyTransformed(T))
2769 return T;
2770
2771 TypeSourceInfo *TSI =
2772 SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
2773
2774 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
2775 UnqualLookup, Prefix);
2776 if (!TSI) return QualType();
2777 return TSI->getType();
2778}
2779
2780template<typename Derived>
2781TypeSourceInfo *
2782TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
2783 QualType ObjectType,
2784 NamedDecl *UnqualLookup,
2785 NestedNameSpecifier *Prefix) {
2786 // TODO: in some cases, we might be some verification to do here.
2787 if (ObjectType.isNull())
2788 return getDerived().TransformType(TSI);
2789
2790 QualType T = TSI->getType();
2791 if (getDerived().AlreadyTransformed(T))
2792 return TSI;
2793
2794 TypeLocBuilder TLB;
2795 QualType Result;
2796
2797 if (isa<TemplateSpecializationType>(T)) {
2798 TemplateSpecializationTypeLoc TL
2799 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2800
2801 TemplateName Template =
2802 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
2803 ObjectType, UnqualLookup);
2804 if (Template.isNull()) return 0;
2805
2806 Result = getDerived()
2807 .TransformTemplateSpecializationType(TLB, TL, Template);
2808 } else if (isa<DependentTemplateSpecializationType>(T)) {
2809 DependentTemplateSpecializationTypeLoc TL
2810 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2811
2812 Result = getDerived()
2813 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
2814 } else {
2815 // Nothing special needs to be done for these.
2816 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
2817 }
2818
2819 if (Result.isNull()) return 0;
2820 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
2821}
2822
John McCall550e0c22009-10-21 00:40:46 +00002823template <class TyLoc> static inline
2824QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2825 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2826 NewT.setNameLoc(T.getNameLoc());
2827 return T.getType();
2828}
2829
John McCall550e0c22009-10-21 00:40:46 +00002830template<typename Derived>
2831QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002832 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002833 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2834 NewT.setBuiltinLoc(T.getBuiltinLoc());
2835 if (T.needsExtraLocalData())
2836 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2837 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002838}
Mike Stump11289f42009-09-09 15:08:12 +00002839
Douglas Gregord6ff3322009-08-04 16:50:30 +00002840template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002841QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002842 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00002843 // FIXME: recurse?
2844 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002845}
Mike Stump11289f42009-09-09 15:08:12 +00002846
Douglas Gregord6ff3322009-08-04 16:50:30 +00002847template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002848QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002849 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002850 QualType PointeeType
2851 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002852 if (PointeeType.isNull())
2853 return QualType();
2854
2855 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002856 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002857 // A dependent pointer type 'T *' has is being transformed such
2858 // that an Objective-C class type is being replaced for 'T'. The
2859 // resulting pointer type is an ObjCObjectPointerType, not a
2860 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002861 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002862
John McCall8b07ec22010-05-15 11:32:37 +00002863 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2864 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002865 return Result;
2866 }
John McCall31f82722010-11-12 08:19:04 +00002867
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002868 if (getDerived().AlwaysRebuild() ||
2869 PointeeType != TL.getPointeeLoc().getType()) {
2870 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2871 if (Result.isNull())
2872 return QualType();
2873 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002874
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002875 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2876 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002877 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002878}
Mike Stump11289f42009-09-09 15:08:12 +00002879
2880template<typename Derived>
2881QualType
John McCall550e0c22009-10-21 00:40:46 +00002882TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002883 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002884 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002885 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2886 if (PointeeType.isNull())
2887 return QualType();
2888
2889 QualType Result = TL.getType();
2890 if (getDerived().AlwaysRebuild() ||
2891 PointeeType != TL.getPointeeLoc().getType()) {
2892 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002893 TL.getSigilLoc());
2894 if (Result.isNull())
2895 return QualType();
2896 }
2897
Douglas Gregor049211a2010-04-22 16:50:51 +00002898 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002899 NewT.setSigilLoc(TL.getSigilLoc());
2900 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002901}
2902
John McCall70dd5f62009-10-30 00:06:24 +00002903/// Transforms a reference type. Note that somewhat paradoxically we
2904/// don't care whether the type itself is an l-value type or an r-value
2905/// type; we only care if the type was *written* as an l-value type
2906/// or an r-value type.
2907template<typename Derived>
2908QualType
2909TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002910 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002911 const ReferenceType *T = TL.getTypePtr();
2912
2913 // Note that this works with the pointee-as-written.
2914 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2915 if (PointeeType.isNull())
2916 return QualType();
2917
2918 QualType Result = TL.getType();
2919 if (getDerived().AlwaysRebuild() ||
2920 PointeeType != T->getPointeeTypeAsWritten()) {
2921 Result = getDerived().RebuildReferenceType(PointeeType,
2922 T->isSpelledAsLValue(),
2923 TL.getSigilLoc());
2924 if (Result.isNull())
2925 return QualType();
2926 }
2927
2928 // r-value references can be rebuilt as l-value references.
2929 ReferenceTypeLoc NewTL;
2930 if (isa<LValueReferenceType>(Result))
2931 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2932 else
2933 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2934 NewTL.setSigilLoc(TL.getSigilLoc());
2935
2936 return Result;
2937}
2938
Mike Stump11289f42009-09-09 15:08:12 +00002939template<typename Derived>
2940QualType
John McCall550e0c22009-10-21 00:40:46 +00002941TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002942 LValueReferenceTypeLoc TL) {
2943 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002944}
2945
Mike Stump11289f42009-09-09 15:08:12 +00002946template<typename Derived>
2947QualType
John McCall550e0c22009-10-21 00:40:46 +00002948TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002949 RValueReferenceTypeLoc TL) {
2950 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002951}
Mike Stump11289f42009-09-09 15:08:12 +00002952
Douglas Gregord6ff3322009-08-04 16:50:30 +00002953template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002954QualType
John McCall550e0c22009-10-21 00:40:46 +00002955TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002956 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002957 MemberPointerType *T = TL.getTypePtr();
2958
2959 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002960 if (PointeeType.isNull())
2961 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002962
John McCall550e0c22009-10-21 00:40:46 +00002963 // TODO: preserve source information for this.
2964 QualType ClassType
2965 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002966 if (ClassType.isNull())
2967 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002968
John McCall550e0c22009-10-21 00:40:46 +00002969 QualType Result = TL.getType();
2970 if (getDerived().AlwaysRebuild() ||
2971 PointeeType != T->getPointeeType() ||
2972 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002973 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2974 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002975 if (Result.isNull())
2976 return QualType();
2977 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002978
John McCall550e0c22009-10-21 00:40:46 +00002979 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2980 NewTL.setSigilLoc(TL.getSigilLoc());
2981
2982 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002983}
2984
Mike Stump11289f42009-09-09 15:08:12 +00002985template<typename Derived>
2986QualType
John McCall550e0c22009-10-21 00:40:46 +00002987TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002988 ConstantArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00002989 ConstantArrayType *T = TL.getTypePtr();
2990 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002991 if (ElementType.isNull())
2992 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002993
John McCall550e0c22009-10-21 00:40:46 +00002994 QualType Result = TL.getType();
2995 if (getDerived().AlwaysRebuild() ||
2996 ElementType != T->getElementType()) {
2997 Result = getDerived().RebuildConstantArrayType(ElementType,
2998 T->getSizeModifier(),
2999 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003000 T->getIndexTypeCVRQualifiers(),
3001 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003002 if (Result.isNull())
3003 return QualType();
3004 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003005
John McCall550e0c22009-10-21 00:40:46 +00003006 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3007 NewTL.setLBracketLoc(TL.getLBracketLoc());
3008 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003009
John McCall550e0c22009-10-21 00:40:46 +00003010 Expr *Size = TL.getSizeExpr();
3011 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003012 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003013 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3014 }
3015 NewTL.setSizeExpr(Size);
3016
3017 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003018}
Mike Stump11289f42009-09-09 15:08:12 +00003019
Douglas Gregord6ff3322009-08-04 16:50:30 +00003020template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003021QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003022 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003023 IncompleteArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003024 IncompleteArrayType *T = TL.getTypePtr();
3025 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003026 if (ElementType.isNull())
3027 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003028
John McCall550e0c22009-10-21 00:40:46 +00003029 QualType Result = TL.getType();
3030 if (getDerived().AlwaysRebuild() ||
3031 ElementType != T->getElementType()) {
3032 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003033 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003034 T->getIndexTypeCVRQualifiers(),
3035 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003036 if (Result.isNull())
3037 return QualType();
3038 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003039
John McCall550e0c22009-10-21 00:40:46 +00003040 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3041 NewTL.setLBracketLoc(TL.getLBracketLoc());
3042 NewTL.setRBracketLoc(TL.getRBracketLoc());
3043 NewTL.setSizeExpr(0);
3044
3045 return Result;
3046}
3047
3048template<typename Derived>
3049QualType
3050TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003051 VariableArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003052 VariableArrayType *T = TL.getTypePtr();
3053 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3054 if (ElementType.isNull())
3055 return QualType();
3056
3057 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003058 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003059
John McCalldadc5752010-08-24 06:29:42 +00003060 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003061 = getDerived().TransformExpr(T->getSizeExpr());
3062 if (SizeResult.isInvalid())
3063 return QualType();
3064
John McCallb268a282010-08-23 23:25:46 +00003065 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003066
3067 QualType Result = TL.getType();
3068 if (getDerived().AlwaysRebuild() ||
3069 ElementType != T->getElementType() ||
3070 Size != T->getSizeExpr()) {
3071 Result = getDerived().RebuildVariableArrayType(ElementType,
3072 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003073 Size,
John McCall550e0c22009-10-21 00:40:46 +00003074 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003075 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003076 if (Result.isNull())
3077 return QualType();
3078 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003079
John McCall550e0c22009-10-21 00:40:46 +00003080 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3081 NewTL.setLBracketLoc(TL.getLBracketLoc());
3082 NewTL.setRBracketLoc(TL.getRBracketLoc());
3083 NewTL.setSizeExpr(Size);
3084
3085 return Result;
3086}
3087
3088template<typename Derived>
3089QualType
3090TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003091 DependentSizedArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003092 DependentSizedArrayType *T = TL.getTypePtr();
3093 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3094 if (ElementType.isNull())
3095 return QualType();
3096
3097 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003098 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003099
John McCalldadc5752010-08-24 06:29:42 +00003100 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003101 = getDerived().TransformExpr(T->getSizeExpr());
3102 if (SizeResult.isInvalid())
3103 return QualType();
3104
3105 Expr *Size = static_cast<Expr*>(SizeResult.get());
3106
3107 QualType Result = TL.getType();
3108 if (getDerived().AlwaysRebuild() ||
3109 ElementType != T->getElementType() ||
3110 Size != T->getSizeExpr()) {
3111 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3112 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003113 Size,
John McCall550e0c22009-10-21 00:40:46 +00003114 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003115 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003116 if (Result.isNull())
3117 return QualType();
3118 }
3119 else SizeResult.take();
3120
3121 // We might have any sort of array type now, but fortunately they
3122 // all have the same location layout.
3123 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3124 NewTL.setLBracketLoc(TL.getLBracketLoc());
3125 NewTL.setRBracketLoc(TL.getRBracketLoc());
3126 NewTL.setSizeExpr(Size);
3127
3128 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003129}
Mike Stump11289f42009-09-09 15:08:12 +00003130
3131template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003132QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003133 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003134 DependentSizedExtVectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003135 DependentSizedExtVectorType *T = TL.getTypePtr();
3136
3137 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003138 QualType ElementType = getDerived().TransformType(T->getElementType());
3139 if (ElementType.isNull())
3140 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003141
Douglas Gregore922c772009-08-04 22:27:00 +00003142 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003143 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003144
John McCalldadc5752010-08-24 06:29:42 +00003145 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003146 if (Size.isInvalid())
3147 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003148
John McCall550e0c22009-10-21 00:40:46 +00003149 QualType Result = TL.getType();
3150 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003151 ElementType != T->getElementType() ||
3152 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003153 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003154 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003155 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003156 if (Result.isNull())
3157 return QualType();
3158 }
John McCall550e0c22009-10-21 00:40:46 +00003159
3160 // Result might be dependent or not.
3161 if (isa<DependentSizedExtVectorType>(Result)) {
3162 DependentSizedExtVectorTypeLoc NewTL
3163 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3164 NewTL.setNameLoc(TL.getNameLoc());
3165 } else {
3166 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3167 NewTL.setNameLoc(TL.getNameLoc());
3168 }
3169
3170 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003171}
Mike Stump11289f42009-09-09 15:08:12 +00003172
3173template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003174QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003175 VectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003176 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003177 QualType ElementType = getDerived().TransformType(T->getElementType());
3178 if (ElementType.isNull())
3179 return QualType();
3180
John McCall550e0c22009-10-21 00:40:46 +00003181 QualType Result = TL.getType();
3182 if (getDerived().AlwaysRebuild() ||
3183 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003184 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003185 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003186 if (Result.isNull())
3187 return QualType();
3188 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003189
John McCall550e0c22009-10-21 00:40:46 +00003190 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3191 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003192
John McCall550e0c22009-10-21 00:40:46 +00003193 return Result;
3194}
3195
3196template<typename Derived>
3197QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003198 ExtVectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003199 VectorType *T = TL.getTypePtr();
3200 QualType ElementType = getDerived().TransformType(T->getElementType());
3201 if (ElementType.isNull())
3202 return QualType();
3203
3204 QualType Result = TL.getType();
3205 if (getDerived().AlwaysRebuild() ||
3206 ElementType != T->getElementType()) {
3207 Result = getDerived().RebuildExtVectorType(ElementType,
3208 T->getNumElements(),
3209 /*FIXME*/ SourceLocation());
3210 if (Result.isNull())
3211 return QualType();
3212 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003213
John McCall550e0c22009-10-21 00:40:46 +00003214 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3215 NewTL.setNameLoc(TL.getNameLoc());
3216
3217 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003218}
Mike Stump11289f42009-09-09 15:08:12 +00003219
3220template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003221ParmVarDecl *
3222TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
3223 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
3224 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
3225 if (!NewDI)
3226 return 0;
3227
3228 if (NewDI == OldDI)
3229 return OldParm;
3230 else
3231 return ParmVarDecl::Create(SemaRef.Context,
3232 OldParm->getDeclContext(),
3233 OldParm->getLocation(),
3234 OldParm->getIdentifier(),
3235 NewDI->getType(),
3236 NewDI,
3237 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003238 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003239 /* DefArg */ NULL);
3240}
3241
3242template<typename Derived>
3243bool TreeTransform<Derived>::
3244 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
3245 llvm::SmallVectorImpl<QualType> &PTypes,
3246 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
3247 FunctionProtoType *T = TL.getTypePtr();
3248
3249 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3250 ParmVarDecl *OldParm = TL.getArg(i);
3251
3252 QualType NewType;
3253 ParmVarDecl *NewParm;
3254
3255 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00003256 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
3257 if (!NewParm)
3258 return true;
3259 NewType = NewParm->getType();
3260
3261 // Deal with the possibility that we don't have a parameter
3262 // declaration for this parameter.
3263 } else {
3264 NewParm = 0;
3265
3266 QualType OldType = T->getArgType(i);
3267 NewType = getDerived().TransformType(OldType);
3268 if (NewType.isNull())
3269 return true;
3270 }
3271
3272 PTypes.push_back(NewType);
3273 PVars.push_back(NewParm);
3274 }
3275
3276 return false;
3277}
3278
3279template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003280QualType
John McCall550e0c22009-10-21 00:40:46 +00003281TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003282 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003283 // Transform the parameters and return type.
3284 //
3285 // We instantiate in source order, with the return type first followed by
3286 // the parameters, because users tend to expect this (even if they shouldn't
3287 // rely on it!).
3288 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003289 // When the function has a trailing return type, we instantiate the
3290 // parameters before the return type, since the return type can then refer
3291 // to the parameters themselves (via decltype, sizeof, etc.).
3292 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003293 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003294 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor14cf7522010-04-30 18:55:50 +00003295 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003296
Douglas Gregor7fb25412010-10-01 18:44:50 +00003297 QualType ResultType;
3298
3299 if (TL.getTrailingReturn()) {
3300 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3301 return QualType();
3302
3303 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3304 if (ResultType.isNull())
3305 return QualType();
3306 }
3307 else {
3308 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3309 if (ResultType.isNull())
3310 return QualType();
3311
3312 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3313 return QualType();
3314 }
3315
John McCall550e0c22009-10-21 00:40:46 +00003316 QualType Result = TL.getType();
3317 if (getDerived().AlwaysRebuild() ||
3318 ResultType != T->getResultType() ||
3319 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3320 Result = getDerived().RebuildFunctionProtoType(ResultType,
3321 ParamTypes.data(),
3322 ParamTypes.size(),
3323 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003324 T->getTypeQuals(),
3325 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003326 if (Result.isNull())
3327 return QualType();
3328 }
Mike Stump11289f42009-09-09 15:08:12 +00003329
John McCall550e0c22009-10-21 00:40:46 +00003330 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3331 NewTL.setLParenLoc(TL.getLParenLoc());
3332 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003333 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003334 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3335 NewTL.setArg(i, ParamDecls[i]);
3336
3337 return Result;
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>
3341QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003342 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003343 FunctionNoProtoTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003344 FunctionNoProtoType *T = TL.getTypePtr();
3345 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3346 if (ResultType.isNull())
3347 return QualType();
3348
3349 QualType Result = TL.getType();
3350 if (getDerived().AlwaysRebuild() ||
3351 ResultType != T->getResultType())
3352 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3353
3354 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3355 NewTL.setLParenLoc(TL.getLParenLoc());
3356 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003357 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003358
3359 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003360}
Mike Stump11289f42009-09-09 15:08:12 +00003361
John McCallb96ec562009-12-04 22:46:56 +00003362template<typename Derived> QualType
3363TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003364 UnresolvedUsingTypeLoc TL) {
John McCallb96ec562009-12-04 22:46:56 +00003365 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003366 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003367 if (!D)
3368 return QualType();
3369
3370 QualType Result = TL.getType();
3371 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3372 Result = getDerived().RebuildUnresolvedUsingType(D);
3373 if (Result.isNull())
3374 return QualType();
3375 }
3376
3377 // We might get an arbitrary type spec type back. We should at
3378 // least always get a type spec type, though.
3379 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3380 NewTL.setNameLoc(TL.getNameLoc());
3381
3382 return Result;
3383}
3384
Douglas Gregord6ff3322009-08-04 16:50:30 +00003385template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003386QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003387 TypedefTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003388 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003389 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003390 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3391 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003392 if (!Typedef)
3393 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003394
John McCall550e0c22009-10-21 00:40:46 +00003395 QualType Result = TL.getType();
3396 if (getDerived().AlwaysRebuild() ||
3397 Typedef != T->getDecl()) {
3398 Result = getDerived().RebuildTypedefType(Typedef);
3399 if (Result.isNull())
3400 return QualType();
3401 }
Mike Stump11289f42009-09-09 15:08:12 +00003402
John McCall550e0c22009-10-21 00:40:46 +00003403 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3404 NewTL.setNameLoc(TL.getNameLoc());
3405
3406 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003407}
Mike Stump11289f42009-09-09 15:08:12 +00003408
Douglas Gregord6ff3322009-08-04 16:50:30 +00003409template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003410QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003411 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003412 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003413 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003414
John McCalldadc5752010-08-24 06:29:42 +00003415 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003416 if (E.isInvalid())
3417 return QualType();
3418
John McCall550e0c22009-10-21 00:40:46 +00003419 QualType Result = TL.getType();
3420 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003421 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003422 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003423 if (Result.isNull())
3424 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003425 }
John McCall550e0c22009-10-21 00:40:46 +00003426 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003427
John McCall550e0c22009-10-21 00:40:46 +00003428 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003429 NewTL.setTypeofLoc(TL.getTypeofLoc());
3430 NewTL.setLParenLoc(TL.getLParenLoc());
3431 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003432
3433 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003434}
Mike Stump11289f42009-09-09 15:08:12 +00003435
3436template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003437QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003438 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003439 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3440 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3441 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003442 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003443
John McCall550e0c22009-10-21 00:40:46 +00003444 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003445 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3446 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003447 if (Result.isNull())
3448 return QualType();
3449 }
Mike Stump11289f42009-09-09 15:08:12 +00003450
John McCall550e0c22009-10-21 00:40:46 +00003451 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003452 NewTL.setTypeofLoc(TL.getTypeofLoc());
3453 NewTL.setLParenLoc(TL.getLParenLoc());
3454 NewTL.setRParenLoc(TL.getRParenLoc());
3455 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003456
3457 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003458}
Mike Stump11289f42009-09-09 15:08:12 +00003459
3460template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003461QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003462 DecltypeTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003463 DecltypeType *T = TL.getTypePtr();
3464
Douglas Gregore922c772009-08-04 22:27:00 +00003465 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003466 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003467
John McCalldadc5752010-08-24 06:29:42 +00003468 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003469 if (E.isInvalid())
3470 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003471
John McCall550e0c22009-10-21 00:40:46 +00003472 QualType Result = TL.getType();
3473 if (getDerived().AlwaysRebuild() ||
3474 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003475 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003476 if (Result.isNull())
3477 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003478 }
John McCall550e0c22009-10-21 00:40:46 +00003479 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003480
John McCall550e0c22009-10-21 00:40:46 +00003481 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3482 NewTL.setNameLoc(TL.getNameLoc());
3483
3484 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003485}
3486
3487template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003488QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003489 RecordTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003490 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003491 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003492 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3493 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003494 if (!Record)
3495 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003496
John McCall550e0c22009-10-21 00:40:46 +00003497 QualType Result = TL.getType();
3498 if (getDerived().AlwaysRebuild() ||
3499 Record != T->getDecl()) {
3500 Result = getDerived().RebuildRecordType(Record);
3501 if (Result.isNull())
3502 return QualType();
3503 }
Mike Stump11289f42009-09-09 15:08:12 +00003504
John McCall550e0c22009-10-21 00:40:46 +00003505 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3506 NewTL.setNameLoc(TL.getNameLoc());
3507
3508 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003509}
Mike Stump11289f42009-09-09 15:08:12 +00003510
3511template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003512QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003513 EnumTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003514 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003515 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003516 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3517 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003518 if (!Enum)
3519 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003520
John McCall550e0c22009-10-21 00:40:46 +00003521 QualType Result = TL.getType();
3522 if (getDerived().AlwaysRebuild() ||
3523 Enum != T->getDecl()) {
3524 Result = getDerived().RebuildEnumType(Enum);
3525 if (Result.isNull())
3526 return QualType();
3527 }
Mike Stump11289f42009-09-09 15:08:12 +00003528
John McCall550e0c22009-10-21 00:40:46 +00003529 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3530 NewTL.setNameLoc(TL.getNameLoc());
3531
3532 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003533}
John McCallfcc33b02009-09-05 00:15:47 +00003534
John McCalle78aac42010-03-10 03:28:59 +00003535template<typename Derived>
3536QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3537 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003538 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00003539 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3540 TL.getTypePtr()->getDecl());
3541 if (!D) return QualType();
3542
3543 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3544 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3545 return T;
3546}
3547
Mike Stump11289f42009-09-09 15:08:12 +00003548
Douglas Gregord6ff3322009-08-04 16:50:30 +00003549template<typename Derived>
3550QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003551 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003552 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003553 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003554}
3555
Mike Stump11289f42009-09-09 15:08:12 +00003556template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003557QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003558 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003559 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003560 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003561}
3562
3563template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003564QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003565 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003566 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00003567 const TemplateSpecializationType *T = TL.getTypePtr();
3568
Mike Stump11289f42009-09-09 15:08:12 +00003569 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00003570 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003571 if (Template.isNull())
3572 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003573
John McCall31f82722010-11-12 08:19:04 +00003574 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
3575}
3576
Douglas Gregorfe921a72010-12-20 23:36:19 +00003577namespace {
3578 /// \brief Simple iterator that traverses the template arguments in a
3579 /// container that provides a \c getArgLoc() member function.
3580 ///
3581 /// This iterator is intended to be used with the iterator form of
3582 /// \c TreeTransform<Derived>::TransformTemplateArguments().
3583 template<typename ArgLocContainer>
3584 class TemplateArgumentLocContainerIterator {
3585 ArgLocContainer *Container;
3586 unsigned Index;
3587
3588 public:
3589 typedef TemplateArgumentLoc value_type;
3590 typedef TemplateArgumentLoc reference;
3591 typedef int difference_type;
3592 typedef std::input_iterator_tag iterator_category;
3593
3594 class pointer {
3595 TemplateArgumentLoc Arg;
3596
3597 public:
3598 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3599
3600 const TemplateArgumentLoc *operator->() const {
3601 return &Arg;
3602 }
3603 };
3604
3605
3606 TemplateArgumentLocContainerIterator() {}
3607
3608 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
3609 unsigned Index)
3610 : Container(&Container), Index(Index) { }
3611
3612 TemplateArgumentLocContainerIterator &operator++() {
3613 ++Index;
3614 return *this;
3615 }
3616
3617 TemplateArgumentLocContainerIterator operator++(int) {
3618 TemplateArgumentLocContainerIterator Old(*this);
3619 ++(*this);
3620 return Old;
3621 }
3622
3623 TemplateArgumentLoc operator*() const {
3624 return Container->getArgLoc(Index);
3625 }
3626
3627 pointer operator->() const {
3628 return pointer(Container->getArgLoc(Index));
3629 }
3630
3631 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
3632 TemplateArgumentLocContainerIterator &Y) {
3633 return X.Container == Y.Container && X.Index == Y.Index;
3634 }
3635
3636 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
3637 TemplateArgumentLocContainerIterator &Y) {
3638 return !(X == Y);
3639 }
3640 };
3641}
3642
3643
John McCall31f82722010-11-12 08:19:04 +00003644template <typename Derived>
3645QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3646 TypeLocBuilder &TLB,
3647 TemplateSpecializationTypeLoc TL,
3648 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00003649 TemplateArgumentListInfo NewTemplateArgs;
3650 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3651 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00003652 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
3653 ArgIterator;
3654 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
3655 ArgIterator(TL, TL.getNumArgs()),
3656 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003657 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003658
John McCall0ad16662009-10-29 08:12:44 +00003659 // FIXME: maybe don't rebuild if all the template arguments are the same.
3660
3661 QualType Result =
3662 getDerived().RebuildTemplateSpecializationType(Template,
3663 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003664 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003665
3666 if (!Result.isNull()) {
3667 TemplateSpecializationTypeLoc NewTL
3668 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3669 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3670 NewTL.setLAngleLoc(TL.getLAngleLoc());
3671 NewTL.setRAngleLoc(TL.getRAngleLoc());
3672 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3673 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003674 }
Mike Stump11289f42009-09-09 15:08:12 +00003675
John McCall0ad16662009-10-29 08:12:44 +00003676 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003677}
Mike Stump11289f42009-09-09 15:08:12 +00003678
3679template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003680QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003681TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003682 ElaboratedTypeLoc TL) {
Abramo Bagnara6150c882010-05-11 21:36:43 +00003683 ElaboratedType *T = TL.getTypePtr();
3684
3685 NestedNameSpecifier *NNS = 0;
3686 // NOTE: the qualifier in an ElaboratedType is optional.
3687 if (T->getQualifier() != 0) {
3688 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003689 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00003690 if (!NNS)
3691 return QualType();
3692 }
Mike Stump11289f42009-09-09 15:08:12 +00003693
John McCall31f82722010-11-12 08:19:04 +00003694 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3695 if (NamedT.isNull())
3696 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003697
John McCall550e0c22009-10-21 00:40:46 +00003698 QualType Result = TL.getType();
3699 if (getDerived().AlwaysRebuild() ||
3700 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003701 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00003702 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
3703 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003704 if (Result.isNull())
3705 return QualType();
3706 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003707
Abramo Bagnara6150c882010-05-11 21:36:43 +00003708 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003709 NewTL.setKeywordLoc(TL.getKeywordLoc());
3710 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003711
3712 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003713}
Mike Stump11289f42009-09-09 15:08:12 +00003714
3715template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00003716QualType
3717TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
3718 ParenTypeLoc TL) {
3719 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
3720 if (Inner.isNull())
3721 return QualType();
3722
3723 QualType Result = TL.getType();
3724 if (getDerived().AlwaysRebuild() ||
3725 Inner != TL.getInnerLoc().getType()) {
3726 Result = getDerived().RebuildParenType(Inner);
3727 if (Result.isNull())
3728 return QualType();
3729 }
3730
3731 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
3732 NewTL.setLParenLoc(TL.getLParenLoc());
3733 NewTL.setRParenLoc(TL.getRParenLoc());
3734 return Result;
3735}
3736
3737template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003738QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003739 DependentNameTypeLoc TL) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003740 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003741
Douglas Gregord6ff3322009-08-04 16:50:30 +00003742 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003743 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003744 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003745 if (!NNS)
3746 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003747
John McCallc392f372010-06-11 00:33:02 +00003748 QualType Result
3749 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3750 T->getIdentifier(),
3751 TL.getKeywordLoc(),
3752 TL.getQualifierRange(),
3753 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003754 if (Result.isNull())
3755 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003756
Abramo Bagnarad7548482010-05-19 21:37:53 +00003757 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3758 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003759 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3760
Abramo Bagnarad7548482010-05-19 21:37:53 +00003761 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3762 NewTL.setKeywordLoc(TL.getKeywordLoc());
3763 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003764 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003765 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3766 NewTL.setKeywordLoc(TL.getKeywordLoc());
3767 NewTL.setQualifierRange(TL.getQualifierRange());
3768 NewTL.setNameLoc(TL.getNameLoc());
3769 }
John McCall550e0c22009-10-21 00:40:46 +00003770 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003771}
Mike Stump11289f42009-09-09 15:08:12 +00003772
Douglas Gregord6ff3322009-08-04 16:50:30 +00003773template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003774QualType TreeTransform<Derived>::
3775 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003776 DependentTemplateSpecializationTypeLoc TL) {
John McCallc392f372010-06-11 00:33:02 +00003777 DependentTemplateSpecializationType *T = TL.getTypePtr();
3778
3779 NestedNameSpecifier *NNS
3780 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003781 TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003782 if (!NNS)
3783 return QualType();
3784
John McCall31f82722010-11-12 08:19:04 +00003785 return getDerived()
3786 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
3787}
3788
3789template<typename Derived>
3790QualType TreeTransform<Derived>::
3791 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3792 DependentTemplateSpecializationTypeLoc TL,
3793 NestedNameSpecifier *NNS) {
3794 DependentTemplateSpecializationType *T = TL.getTypePtr();
3795
John McCallc392f372010-06-11 00:33:02 +00003796 TemplateArgumentListInfo NewTemplateArgs;
3797 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3798 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00003799
3800 typedef TemplateArgumentLocContainerIterator<
3801 DependentTemplateSpecializationTypeLoc> ArgIterator;
3802 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
3803 ArgIterator(TL, TL.getNumArgs()),
3804 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003805 return QualType();
John McCallc392f372010-06-11 00:33:02 +00003806
Douglas Gregora5614c52010-09-08 23:56:00 +00003807 QualType Result
3808 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
3809 NNS,
3810 TL.getQualifierRange(),
3811 T->getIdentifier(),
3812 TL.getNameLoc(),
3813 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00003814 if (Result.isNull())
3815 return QualType();
3816
3817 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3818 QualType NamedT = ElabT->getNamedType();
3819
3820 // Copy information relevant to the template specialization.
3821 TemplateSpecializationTypeLoc NamedTL
3822 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3823 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3824 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3825 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3826 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3827
3828 // Copy information relevant to the elaborated type.
3829 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3830 NewTL.setKeywordLoc(TL.getKeywordLoc());
3831 NewTL.setQualifierRange(TL.getQualifierRange());
3832 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00003833 TypeLoc NewTL(Result, TL.getOpaqueData());
3834 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00003835 }
3836 return Result;
3837}
3838
3839template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00003840QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
3841 PackExpansionTypeLoc TL) {
3842 // FIXME: Implement!
3843 getSema().Diag(TL.getEllipsisLoc(),
3844 diag::err_pack_expansion_instantiation_unsupported);
3845 return QualType();
3846}
3847
3848template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003849QualType
3850TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003851 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003852 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003853 TLB.pushFullCopy(TL);
3854 return TL.getType();
3855}
3856
3857template<typename Derived>
3858QualType
3859TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003860 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00003861 // ObjCObjectType is never dependent.
3862 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003863 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003864}
Mike Stump11289f42009-09-09 15:08:12 +00003865
3866template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003867QualType
3868TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003869 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003870 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003871 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003872 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003873}
3874
Douglas Gregord6ff3322009-08-04 16:50:30 +00003875//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003876// Statement transformation
3877//===----------------------------------------------------------------------===//
3878template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003879StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003880TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00003881 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003882}
3883
3884template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003885StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00003886TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3887 return getDerived().TransformCompoundStmt(S, false);
3888}
3889
3890template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003891StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003892TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003893 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00003894 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00003895 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00003896 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00003897 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3898 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00003899 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00003900 if (Result.isInvalid()) {
3901 // Immediately fail if this was a DeclStmt, since it's very
3902 // likely that this will cause problems for future statements.
3903 if (isa<DeclStmt>(*B))
3904 return StmtError();
3905
3906 // Otherwise, just keep processing substatements and fail later.
3907 SubStmtInvalid = true;
3908 continue;
3909 }
Mike Stump11289f42009-09-09 15:08:12 +00003910
Douglas Gregorebe10102009-08-20 07:17:43 +00003911 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3912 Statements.push_back(Result.takeAs<Stmt>());
3913 }
Mike Stump11289f42009-09-09 15:08:12 +00003914
John McCall1ababa62010-08-27 19:56:05 +00003915 if (SubStmtInvalid)
3916 return StmtError();
3917
Douglas Gregorebe10102009-08-20 07:17:43 +00003918 if (!getDerived().AlwaysRebuild() &&
3919 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00003920 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00003921
3922 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3923 move_arg(Statements),
3924 S->getRBracLoc(),
3925 IsStmtExpr);
3926}
Mike Stump11289f42009-09-09 15:08:12 +00003927
Douglas Gregorebe10102009-08-20 07:17:43 +00003928template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003929StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003930TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003931 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00003932 {
3933 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00003934 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003935
Eli Friedman06577382009-11-19 03:14:00 +00003936 // Transform the left-hand case value.
3937 LHS = getDerived().TransformExpr(S->getLHS());
3938 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003939 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003940
Eli Friedman06577382009-11-19 03:14:00 +00003941 // Transform the right-hand case value (for the GNU case-range extension).
3942 RHS = getDerived().TransformExpr(S->getRHS());
3943 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003944 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00003945 }
Mike Stump11289f42009-09-09 15:08:12 +00003946
Douglas Gregorebe10102009-08-20 07:17:43 +00003947 // Build the case statement.
3948 // Case statements are always rebuilt so that they will attached to their
3949 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00003950 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00003951 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003952 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00003953 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003954 S->getColonLoc());
3955 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003956 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003957
Douglas Gregorebe10102009-08-20 07:17:43 +00003958 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00003959 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003960 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003961 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003962
Douglas Gregorebe10102009-08-20 07:17:43 +00003963 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00003964 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003965}
3966
3967template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003968StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003969TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003970 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00003971 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003972 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003973 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003974
Douglas Gregorebe10102009-08-20 07:17:43 +00003975 // Default statements are always rebuilt
3976 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00003977 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00003978}
Mike Stump11289f42009-09-09 15:08:12 +00003979
Douglas Gregorebe10102009-08-20 07:17:43 +00003980template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003981StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003982TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00003983 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00003984 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003985 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003986
Douglas Gregorebe10102009-08-20 07:17:43 +00003987 // FIXME: Pass the real colon location in.
3988 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3989 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +00003990 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregorebe10102009-08-20 07:17:43 +00003991}
Mike Stump11289f42009-09-09 15:08:12 +00003992
Douglas Gregorebe10102009-08-20 07:17:43 +00003993template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003994StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003995TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003996 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00003997 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00003998 VarDecl *ConditionVar = 0;
3999 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004000 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004001 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004002 getDerived().TransformDefinition(
4003 S->getConditionVariable()->getLocation(),
4004 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004005 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004006 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004007 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004008 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004009
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004010 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004011 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004012
4013 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004014 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004015 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4016 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004017 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004018 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004019
John McCallb268a282010-08-23 23:25:46 +00004020 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004021 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004022 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004023
John McCallb268a282010-08-23 23:25:46 +00004024 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4025 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004026 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004027
Douglas Gregorebe10102009-08-20 07:17:43 +00004028 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004029 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004030 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004031 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004032
Douglas Gregorebe10102009-08-20 07:17:43 +00004033 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004034 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004035 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004036 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004037
Douglas Gregorebe10102009-08-20 07:17:43 +00004038 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004039 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004040 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004041 Then.get() == S->getThen() &&
4042 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004043 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004044
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004045 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004046 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004047 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004048}
4049
4050template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004051StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004052TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004053 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004054 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004055 VarDecl *ConditionVar = 0;
4056 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004057 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004058 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004059 getDerived().TransformDefinition(
4060 S->getConditionVariable()->getLocation(),
4061 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004062 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004063 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004064 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004065 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004066
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004067 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004068 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004069 }
Mike Stump11289f42009-09-09 15:08:12 +00004070
Douglas Gregorebe10102009-08-20 07:17:43 +00004071 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004072 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004073 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004074 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004075 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004076 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004077
Douglas Gregorebe10102009-08-20 07:17:43 +00004078 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004079 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004080 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004081 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004082
Douglas Gregorebe10102009-08-20 07:17:43 +00004083 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004084 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4085 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004086}
Mike Stump11289f42009-09-09 15:08:12 +00004087
Douglas Gregorebe10102009-08-20 07:17:43 +00004088template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004089StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004090TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004091 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004092 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004093 VarDecl *ConditionVar = 0;
4094 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004095 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004096 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004097 getDerived().TransformDefinition(
4098 S->getConditionVariable()->getLocation(),
4099 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004100 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004101 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004102 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004103 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004104
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004105 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004106 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004107
4108 if (S->getCond()) {
4109 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004110 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4111 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004112 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004113 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004114 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004115 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004116 }
Mike Stump11289f42009-09-09 15:08:12 +00004117
John McCallb268a282010-08-23 23:25:46 +00004118 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4119 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004120 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004121
Douglas Gregorebe10102009-08-20 07:17:43 +00004122 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004123 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004124 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004125 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004126
Douglas Gregorebe10102009-08-20 07:17:43 +00004127 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004128 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004129 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004130 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004131 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004132
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004133 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004134 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004135}
Mike Stump11289f42009-09-09 15:08:12 +00004136
Douglas Gregorebe10102009-08-20 07:17:43 +00004137template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004138StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004139TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004140 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004141 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004142 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004143 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004144
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004145 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004146 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004147 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004148 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004149
Douglas Gregorebe10102009-08-20 07:17:43 +00004150 if (!getDerived().AlwaysRebuild() &&
4151 Cond.get() == S->getCond() &&
4152 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004153 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004154
John McCallb268a282010-08-23 23:25:46 +00004155 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4156 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004157 S->getRParenLoc());
4158}
Mike Stump11289f42009-09-09 15:08:12 +00004159
Douglas Gregorebe10102009-08-20 07:17:43 +00004160template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004161StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004162TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004163 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004164 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004165 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004166 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004167
Douglas Gregorebe10102009-08-20 07:17:43 +00004168 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004169 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004170 VarDecl *ConditionVar = 0;
4171 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004172 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004173 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004174 getDerived().TransformDefinition(
4175 S->getConditionVariable()->getLocation(),
4176 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004177 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004178 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004179 } else {
4180 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004181
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004182 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004183 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004184
4185 if (S->getCond()) {
4186 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004187 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4188 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004189 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004190 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004191
John McCallb268a282010-08-23 23:25:46 +00004192 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004193 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004194 }
Mike Stump11289f42009-09-09 15:08:12 +00004195
John McCallb268a282010-08-23 23:25:46 +00004196 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4197 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004198 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004199
Douglas Gregorebe10102009-08-20 07:17:43 +00004200 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00004201 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00004202 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004203 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004204
John McCallb268a282010-08-23 23:25:46 +00004205 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4206 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004207 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004208
Douglas Gregorebe10102009-08-20 07:17:43 +00004209 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004210 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004211 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004212 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004213
Douglas Gregorebe10102009-08-20 07:17:43 +00004214 if (!getDerived().AlwaysRebuild() &&
4215 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00004216 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004217 Inc.get() == S->getInc() &&
4218 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004219 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004220
Douglas Gregorebe10102009-08-20 07:17:43 +00004221 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004222 Init.get(), FullCond, ConditionVar,
4223 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004224}
4225
4226template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004227StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004228TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004229 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00004230 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004231 S->getLabel());
4232}
4233
4234template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004235StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004236TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004237 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00004238 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004239 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004240
Douglas Gregorebe10102009-08-20 07:17:43 +00004241 if (!getDerived().AlwaysRebuild() &&
4242 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00004243 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004244
4245 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00004246 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004247}
4248
4249template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004250StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004251TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004252 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004253}
Mike Stump11289f42009-09-09 15:08:12 +00004254
Douglas Gregorebe10102009-08-20 07:17:43 +00004255template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004256StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004257TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004258 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004259}
Mike Stump11289f42009-09-09 15:08:12 +00004260
Douglas Gregorebe10102009-08-20 07:17:43 +00004261template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004262StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004263TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004264 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00004265 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004266 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004267
Mike Stump11289f42009-09-09 15:08:12 +00004268 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00004269 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00004270 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004271}
Mike Stump11289f42009-09-09 15:08:12 +00004272
Douglas Gregorebe10102009-08-20 07:17:43 +00004273template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004274StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004275TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004276 bool DeclChanged = false;
4277 llvm::SmallVector<Decl *, 4> Decls;
4278 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4279 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00004280 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4281 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00004282 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00004283 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004284
Douglas Gregorebe10102009-08-20 07:17:43 +00004285 if (Transformed != *D)
4286 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00004287
Douglas Gregorebe10102009-08-20 07:17:43 +00004288 Decls.push_back(Transformed);
4289 }
Mike Stump11289f42009-09-09 15:08:12 +00004290
Douglas Gregorebe10102009-08-20 07:17:43 +00004291 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00004292 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004293
4294 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004295 S->getStartLoc(), S->getEndLoc());
4296}
Mike Stump11289f42009-09-09 15:08:12 +00004297
Douglas Gregorebe10102009-08-20 07:17:43 +00004298template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004299StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004300TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004301 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCallc3007a22010-10-26 07:05:15 +00004302 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004303}
4304
4305template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004306StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004307TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004308
John McCall37ad5512010-08-23 06:44:23 +00004309 ASTOwningVector<Expr*> Constraints(getSema());
4310 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00004311 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00004312
John McCalldadc5752010-08-24 06:29:42 +00004313 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00004314 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004315
4316 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004317
Anders Carlssonaaeef072010-01-24 05:50:09 +00004318 // Go through the outputs.
4319 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004320 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004321
Anders Carlssonaaeef072010-01-24 05:50:09 +00004322 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004323 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004324
Anders Carlssonaaeef072010-01-24 05:50:09 +00004325 // Transform the output expr.
4326 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004327 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004328 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004329 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004330
Anders Carlssonaaeef072010-01-24 05:50:09 +00004331 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004332
John McCallb268a282010-08-23 23:25:46 +00004333 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004334 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004335
Anders Carlssonaaeef072010-01-24 05:50:09 +00004336 // Go through the inputs.
4337 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004338 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004339
Anders Carlssonaaeef072010-01-24 05:50:09 +00004340 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004341 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004342
Anders Carlssonaaeef072010-01-24 05:50:09 +00004343 // Transform the input expr.
4344 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004345 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004346 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004347 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004348
Anders Carlssonaaeef072010-01-24 05:50:09 +00004349 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004350
John McCallb268a282010-08-23 23:25:46 +00004351 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004352 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004353
Anders Carlssonaaeef072010-01-24 05:50:09 +00004354 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00004355 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004356
4357 // Go through the clobbers.
4358 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00004359 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00004360
4361 // No need to transform the asm string literal.
4362 AsmString = SemaRef.Owned(S->getAsmString());
4363
4364 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4365 S->isSimple(),
4366 S->isVolatile(),
4367 S->getNumOutputs(),
4368 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00004369 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004370 move_arg(Constraints),
4371 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00004372 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004373 move_arg(Clobbers),
4374 S->getRParenLoc(),
4375 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00004376}
4377
4378
4379template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004380StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004381TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004382 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00004383 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004384 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004385 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004386
Douglas Gregor96c79492010-04-23 22:50:49 +00004387 // Transform the @catch statements (if present).
4388 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004389 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00004390 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004391 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00004392 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004393 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00004394 if (Catch.get() != S->getCatchStmt(I))
4395 AnyCatchChanged = true;
4396 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004397 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004398
Douglas Gregor306de2f2010-04-22 23:59:56 +00004399 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00004400 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00004401 if (S->getFinallyStmt()) {
4402 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4403 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004404 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00004405 }
4406
4407 // If nothing changed, just retain this statement.
4408 if (!getDerived().AlwaysRebuild() &&
4409 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00004410 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00004411 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00004412 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004413
Douglas Gregor306de2f2010-04-22 23:59:56 +00004414 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00004415 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4416 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004417}
Mike Stump11289f42009-09-09 15:08:12 +00004418
Douglas Gregorebe10102009-08-20 07:17:43 +00004419template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004420StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004421TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004422 // Transform the @catch parameter, if there is one.
4423 VarDecl *Var = 0;
4424 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4425 TypeSourceInfo *TSInfo = 0;
4426 if (FromVar->getTypeSourceInfo()) {
4427 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4428 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004429 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004430 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004431
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004432 QualType T;
4433 if (TSInfo)
4434 T = TSInfo->getType();
4435 else {
4436 T = getDerived().TransformType(FromVar->getType());
4437 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004438 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004439 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004440
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004441 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4442 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00004443 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004444 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004445
John McCalldadc5752010-08-24 06:29:42 +00004446 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004447 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004448 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004449
4450 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004451 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004452 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004453}
Mike Stump11289f42009-09-09 15:08:12 +00004454
Douglas Gregorebe10102009-08-20 07:17:43 +00004455template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004456StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004457TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004458 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004459 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004460 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004461 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004462
Douglas Gregor306de2f2010-04-22 23:59:56 +00004463 // If nothing changed, just retain this statement.
4464 if (!getDerived().AlwaysRebuild() &&
4465 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00004466 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00004467
4468 // Build a new statement.
4469 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004470 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004471}
Mike Stump11289f42009-09-09 15:08:12 +00004472
Douglas Gregorebe10102009-08-20 07:17:43 +00004473template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004474StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004475TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004476 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00004477 if (S->getThrowExpr()) {
4478 Operand = getDerived().TransformExpr(S->getThrowExpr());
4479 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004480 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00004481 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004482
Douglas Gregor2900c162010-04-22 21:44:01 +00004483 if (!getDerived().AlwaysRebuild() &&
4484 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00004485 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004486
John McCallb268a282010-08-23 23:25:46 +00004487 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004488}
Mike Stump11289f42009-09-09 15:08:12 +00004489
Douglas Gregorebe10102009-08-20 07:17:43 +00004490template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004491StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004492TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004493 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004494 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00004495 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00004496 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004497 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004498
Douglas Gregor6148de72010-04-22 22:01:21 +00004499 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004500 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00004501 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004502 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004503
Douglas Gregor6148de72010-04-22 22:01:21 +00004504 // If nothing change, just retain the current statement.
4505 if (!getDerived().AlwaysRebuild() &&
4506 Object.get() == S->getSynchExpr() &&
4507 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00004508 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00004509
4510 // Build a new statement.
4511 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00004512 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004513}
4514
4515template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004516StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004517TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004518 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004519 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00004520 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004521 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004522 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004523
Douglas Gregorf68a5082010-04-22 23:10:45 +00004524 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00004525 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004526 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004527 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004528
Douglas Gregorf68a5082010-04-22 23:10:45 +00004529 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004530 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004531 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004532 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004533
Douglas Gregorf68a5082010-04-22 23:10:45 +00004534 // If nothing changed, just retain this statement.
4535 if (!getDerived().AlwaysRebuild() &&
4536 Element.get() == S->getElement() &&
4537 Collection.get() == S->getCollection() &&
4538 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004539 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004540
Douglas Gregorf68a5082010-04-22 23:10:45 +00004541 // Build a new statement.
4542 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4543 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00004544 Element.get(),
4545 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00004546 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004547 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004548}
4549
4550
4551template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004552StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004553TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4554 // Transform the exception declaration, if any.
4555 VarDecl *Var = 0;
4556 if (S->getExceptionDecl()) {
4557 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004558 TypeSourceInfo *T = getDerived().TransformType(
4559 ExceptionDecl->getTypeSourceInfo());
4560 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00004561 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004562
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004563 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00004564 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004565 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00004566 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00004567 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004568 }
Mike Stump11289f42009-09-09 15:08:12 +00004569
Douglas Gregorebe10102009-08-20 07:17:43 +00004570 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00004571 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004572 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004573 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004574
Douglas Gregorebe10102009-08-20 07:17:43 +00004575 if (!getDerived().AlwaysRebuild() &&
4576 !Var &&
4577 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00004578 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004579
4580 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4581 Var,
John McCallb268a282010-08-23 23:25:46 +00004582 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004583}
Mike Stump11289f42009-09-09 15:08:12 +00004584
Douglas Gregorebe10102009-08-20 07:17:43 +00004585template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004586StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004587TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4588 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00004589 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004590 = getDerived().TransformCompoundStmt(S->getTryBlock());
4591 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004592 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004593
Douglas Gregorebe10102009-08-20 07:17:43 +00004594 // Transform the handlers.
4595 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004596 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00004597 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004598 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004599 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4600 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004601 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004602
Douglas Gregorebe10102009-08-20 07:17:43 +00004603 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4604 Handlers.push_back(Handler.takeAs<Stmt>());
4605 }
Mike Stump11289f42009-09-09 15:08:12 +00004606
Douglas Gregorebe10102009-08-20 07:17:43 +00004607 if (!getDerived().AlwaysRebuild() &&
4608 TryBlock.get() == S->getTryBlock() &&
4609 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00004610 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004611
John McCallb268a282010-08-23 23:25:46 +00004612 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00004613 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004614}
Mike Stump11289f42009-09-09 15:08:12 +00004615
Douglas Gregorebe10102009-08-20 07:17:43 +00004616//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004617// Expression transformation
4618//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004619template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004620ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004621TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00004622 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004623}
Mike Stump11289f42009-09-09 15:08:12 +00004624
4625template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004626ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004627TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004628 NestedNameSpecifier *Qualifier = 0;
4629 if (E->getQualifier()) {
4630 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004631 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004632 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00004633 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004634 }
John McCallce546572009-12-08 09:08:17 +00004635
4636 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004637 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4638 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004639 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00004640 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004641
John McCall815039a2010-08-17 21:27:17 +00004642 DeclarationNameInfo NameInfo = E->getNameInfo();
4643 if (NameInfo.getName()) {
4644 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4645 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00004646 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00004647 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004648
4649 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004650 Qualifier == E->getQualifier() &&
4651 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004652 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00004653 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004654
4655 // Mark it referenced in the new context regardless.
4656 // FIXME: this is a bit instantiation-specific.
4657 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4658
John McCallc3007a22010-10-26 07:05:15 +00004659 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004660 }
John McCallce546572009-12-08 09:08:17 +00004661
4662 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00004663 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004664 TemplateArgs = &TransArgs;
4665 TransArgs.setLAngleLoc(E->getLAngleLoc());
4666 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00004667 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
4668 E->getNumTemplateArgs(),
4669 TransArgs))
4670 return ExprError();
John McCallce546572009-12-08 09:08:17 +00004671 }
4672
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004673 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004674 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004675}
Mike Stump11289f42009-09-09 15:08:12 +00004676
Douglas Gregora16548e2009-08-11 05:31:07 +00004677template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004678ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004679TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004680 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004681}
Mike Stump11289f42009-09-09 15:08:12 +00004682
Douglas Gregora16548e2009-08-11 05:31:07 +00004683template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004684ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004685TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004686 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004687}
Mike Stump11289f42009-09-09 15:08:12 +00004688
Douglas Gregora16548e2009-08-11 05:31:07 +00004689template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004690ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004691TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004692 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004693}
Mike Stump11289f42009-09-09 15:08:12 +00004694
Douglas Gregora16548e2009-08-11 05:31:07 +00004695template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004696ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004697TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004698 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004699}
Mike Stump11289f42009-09-09 15:08:12 +00004700
Douglas Gregora16548e2009-08-11 05:31:07 +00004701template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004702ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004703TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004704 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004705}
4706
4707template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004708ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004709TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004710 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004711 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004712 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004713
Douglas Gregora16548e2009-08-11 05:31:07 +00004714 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004715 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004716
John McCallb268a282010-08-23 23:25:46 +00004717 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004718 E->getRParen());
4719}
4720
Mike Stump11289f42009-09-09 15:08:12 +00004721template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004722ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004723TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004724 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004725 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004726 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004727
Douglas Gregora16548e2009-08-11 05:31:07 +00004728 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004729 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004730
Douglas Gregora16548e2009-08-11 05:31:07 +00004731 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4732 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004733 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004734}
Mike Stump11289f42009-09-09 15:08:12 +00004735
Douglas Gregora16548e2009-08-11 05:31:07 +00004736template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004737ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004738TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4739 // Transform the type.
4740 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4741 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00004742 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004743
Douglas Gregor882211c2010-04-28 22:16:22 +00004744 // Transform all of the components into components similar to what the
4745 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004746 // FIXME: It would be slightly more efficient in the non-dependent case to
4747 // just map FieldDecls, rather than requiring the rebuilder to look for
4748 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004749 // template code that we don't care.
4750 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00004751 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00004752 typedef OffsetOfExpr::OffsetOfNode Node;
4753 llvm::SmallVector<Component, 4> Components;
4754 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4755 const Node &ON = E->getComponent(I);
4756 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004757 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004758 Comp.LocStart = ON.getRange().getBegin();
4759 Comp.LocEnd = ON.getRange().getEnd();
4760 switch (ON.getKind()) {
4761 case Node::Array: {
4762 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00004763 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00004764 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004765 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004766
Douglas Gregor882211c2010-04-28 22:16:22 +00004767 ExprChanged = ExprChanged || Index.get() != FromIndex;
4768 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00004769 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00004770 break;
4771 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004772
Douglas Gregor882211c2010-04-28 22:16:22 +00004773 case Node::Field:
4774 case Node::Identifier:
4775 Comp.isBrackets = false;
4776 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004777 if (!Comp.U.IdentInfo)
4778 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004779
Douglas Gregor882211c2010-04-28 22:16:22 +00004780 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004781
Douglas Gregord1702062010-04-29 00:18:15 +00004782 case Node::Base:
4783 // Will be recomputed during the rebuild.
4784 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004785 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004786
Douglas Gregor882211c2010-04-28 22:16:22 +00004787 Components.push_back(Comp);
4788 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004789
Douglas Gregor882211c2010-04-28 22:16:22 +00004790 // If nothing changed, retain the existing expression.
4791 if (!getDerived().AlwaysRebuild() &&
4792 Type == E->getTypeSourceInfo() &&
4793 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00004794 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004795
Douglas Gregor882211c2010-04-28 22:16:22 +00004796 // Build a new offsetof expression.
4797 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4798 Components.data(), Components.size(),
4799 E->getRParenLoc());
4800}
4801
4802template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004803ExprResult
John McCall8d69a212010-11-15 23:31:06 +00004804TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
4805 assert(getDerived().AlreadyTransformed(E->getType()) &&
4806 "opaque value expression requires transformation");
4807 return SemaRef.Owned(E);
4808}
4809
4810template<typename Derived>
4811ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004812TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004813 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004814 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004815
John McCallbcd03502009-12-07 02:54:59 +00004816 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004817 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004818 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004819
John McCall4c98fd82009-11-04 07:28:41 +00004820 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00004821 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004822
John McCall4c98fd82009-11-04 07:28:41 +00004823 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004824 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004825 E->getSourceRange());
4826 }
Mike Stump11289f42009-09-09 15:08:12 +00004827
John McCalldadc5752010-08-24 06:29:42 +00004828 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00004829 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004830 // C++0x [expr.sizeof]p1:
4831 // The operand is either an expression, which is an unevaluated operand
4832 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00004833 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004834
Douglas Gregora16548e2009-08-11 05:31:07 +00004835 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4836 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004837 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004838
Douglas Gregora16548e2009-08-11 05:31:07 +00004839 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00004840 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004841 }
Mike Stump11289f42009-09-09 15:08:12 +00004842
John McCallb268a282010-08-23 23:25:46 +00004843 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004844 E->isSizeOf(),
4845 E->getSourceRange());
4846}
Mike Stump11289f42009-09-09 15:08:12 +00004847
Douglas Gregora16548e2009-08-11 05:31:07 +00004848template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004849ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004850TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004851 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004852 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004853 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004854
John McCalldadc5752010-08-24 06:29:42 +00004855 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004856 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004857 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004858
4859
Douglas Gregora16548e2009-08-11 05:31:07 +00004860 if (!getDerived().AlwaysRebuild() &&
4861 LHS.get() == E->getLHS() &&
4862 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004863 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004864
John McCallb268a282010-08-23 23:25:46 +00004865 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004866 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00004867 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004868 E->getRBracketLoc());
4869}
Mike Stump11289f42009-09-09 15:08:12 +00004870
4871template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004872ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004873TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004874 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00004875 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00004876 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004877 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004878
4879 // Transform arguments.
4880 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004881 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00004882 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004883 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00004884 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004885 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004886
Mike Stump11289f42009-09-09 15:08:12 +00004887 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00004888 Args.push_back(Arg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004889 }
Mike Stump11289f42009-09-09 15:08:12 +00004890
Douglas Gregora16548e2009-08-11 05:31:07 +00004891 if (!getDerived().AlwaysRebuild() &&
4892 Callee.get() == E->getCallee() &&
4893 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00004894 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004895
Douglas Gregora16548e2009-08-11 05:31:07 +00004896 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004897 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004898 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00004899 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004900 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00004901 E->getRParenLoc());
4902}
Mike Stump11289f42009-09-09 15:08:12 +00004903
4904template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004905ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004906TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004907 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00004908 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004909 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004910
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004911 NestedNameSpecifier *Qualifier = 0;
4912 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004913 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004914 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004915 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004916 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00004917 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004918 }
Mike Stump11289f42009-09-09 15:08:12 +00004919
Eli Friedman2cfcef62009-12-04 06:40:45 +00004920 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004921 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4922 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004923 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00004924 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004925
John McCall16df1e52010-03-30 21:47:33 +00004926 NamedDecl *FoundDecl = E->getFoundDecl();
4927 if (FoundDecl == E->getMemberDecl()) {
4928 FoundDecl = Member;
4929 } else {
4930 FoundDecl = cast_or_null<NamedDecl>(
4931 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4932 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00004933 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00004934 }
4935
Douglas Gregora16548e2009-08-11 05:31:07 +00004936 if (!getDerived().AlwaysRebuild() &&
4937 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004938 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004939 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004940 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00004941 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004942
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004943 // Mark it referenced in the new context regardless.
4944 // FIXME: this is a bit instantiation-specific.
4945 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00004946 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004947 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004948
John McCall6b51f282009-11-23 01:53:49 +00004949 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00004950 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00004951 TransArgs.setLAngleLoc(E->getLAngleLoc());
4952 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00004953 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
4954 E->getNumTemplateArgs(),
4955 TransArgs))
4956 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004957 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004958
Douglas Gregora16548e2009-08-11 05:31:07 +00004959 // FIXME: Bogus source location for the operator
4960 SourceLocation FakeOperatorLoc
4961 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4962
John McCall38836f02010-01-15 08:34:02 +00004963 // FIXME: to do this check properly, we will need to preserve the
4964 // first-qualifier-in-scope here, just in case we had a dependent
4965 // base (and therefore couldn't do the check) and a
4966 // nested-name-qualifier (and therefore could do the lookup).
4967 NamedDecl *FirstQualifierInScope = 0;
4968
John McCallb268a282010-08-23 23:25:46 +00004969 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00004970 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004971 Qualifier,
4972 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004973 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004974 Member,
John McCall16df1e52010-03-30 21:47:33 +00004975 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00004976 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00004977 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004978 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004979}
Mike Stump11289f42009-09-09 15:08:12 +00004980
Douglas Gregora16548e2009-08-11 05:31:07 +00004981template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004982ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004983TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004984 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004985 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004986 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004987
John McCalldadc5752010-08-24 06:29:42 +00004988 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004989 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004990 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004991
Douglas Gregora16548e2009-08-11 05:31:07 +00004992 if (!getDerived().AlwaysRebuild() &&
4993 LHS.get() == E->getLHS() &&
4994 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004995 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004996
Douglas Gregora16548e2009-08-11 05:31:07 +00004997 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004998 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004999}
5000
Mike Stump11289f42009-09-09 15:08:12 +00005001template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005002ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005003TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005004 CompoundAssignOperator *E) {
5005 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005006}
Mike Stump11289f42009-09-09 15:08:12 +00005007
Douglas Gregora16548e2009-08-11 05:31:07 +00005008template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005009ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005010TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005011 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005012 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005013 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005014
John McCalldadc5752010-08-24 06:29:42 +00005015 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005016 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005017 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005018
John McCalldadc5752010-08-24 06:29:42 +00005019 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005020 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005021 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005022
Douglas Gregora16548e2009-08-11 05:31:07 +00005023 if (!getDerived().AlwaysRebuild() &&
5024 Cond.get() == E->getCond() &&
5025 LHS.get() == E->getLHS() &&
5026 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005027 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005028
John McCallb268a282010-08-23 23:25:46 +00005029 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005030 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005031 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005032 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005033 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005034}
Mike Stump11289f42009-09-09 15:08:12 +00005035
5036template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005037ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005038TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005039 // Implicit casts are eliminated during transformation, since they
5040 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005041 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005042}
Mike Stump11289f42009-09-09 15:08:12 +00005043
Douglas Gregora16548e2009-08-11 05:31:07 +00005044template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005045ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005046TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005047 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5048 if (!Type)
5049 return ExprError();
5050
John McCalldadc5752010-08-24 06:29:42 +00005051 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005052 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005053 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005054 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005055
Douglas Gregora16548e2009-08-11 05:31:07 +00005056 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005057 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005058 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005059 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005060
John McCall97513962010-01-15 18:39:57 +00005061 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005062 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005063 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005064 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005065}
Mike Stump11289f42009-09-09 15:08:12 +00005066
Douglas Gregora16548e2009-08-11 05:31:07 +00005067template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005068ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005069TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005070 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5071 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5072 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005073 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005074
John McCalldadc5752010-08-24 06:29:42 +00005075 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005076 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005077 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005078
Douglas Gregora16548e2009-08-11 05:31:07 +00005079 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005080 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005081 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005082 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005083
John McCall5d7aa7f2010-01-19 22:33:45 +00005084 // Note: the expression type doesn't necessarily match the
5085 // type-as-written, but that's okay, because it should always be
5086 // derivable from the initializer.
5087
John McCalle15bbff2010-01-18 19:35:47 +00005088 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005089 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005090 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005091}
Mike Stump11289f42009-09-09 15:08:12 +00005092
Douglas Gregora16548e2009-08-11 05:31:07 +00005093template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005094ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005095TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005096 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005097 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005098 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005099
Douglas Gregora16548e2009-08-11 05:31:07 +00005100 if (!getDerived().AlwaysRebuild() &&
5101 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00005102 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005103
Douglas Gregora16548e2009-08-11 05:31:07 +00005104 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005105 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005106 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005107 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005108 E->getAccessorLoc(),
5109 E->getAccessor());
5110}
Mike Stump11289f42009-09-09 15:08:12 +00005111
Douglas Gregora16548e2009-08-11 05:31:07 +00005112template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005113ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005114TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005115 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005116
John McCall37ad5512010-08-23 06:44:23 +00005117 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005118 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005119 ExprResult Init = getDerived().TransformExpr(E->getInit(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005120 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005121 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005122
Douglas Gregora16548e2009-08-11 05:31:07 +00005123 InitChanged = InitChanged || Init.get() != E->getInit(I);
John McCallb268a282010-08-23 23:25:46 +00005124 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005125 }
Mike Stump11289f42009-09-09 15:08:12 +00005126
Douglas Gregora16548e2009-08-11 05:31:07 +00005127 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005128 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005129
Douglas Gregora16548e2009-08-11 05:31:07 +00005130 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005131 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005132}
Mike Stump11289f42009-09-09 15:08:12 +00005133
Douglas Gregora16548e2009-08-11 05:31:07 +00005134template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005135ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005136TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005137 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005138
Douglas Gregorebe10102009-08-20 07:17:43 +00005139 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005140 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005141 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005142 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005143
Douglas Gregorebe10102009-08-20 07:17:43 +00005144 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005145 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005146 bool ExprChanged = false;
5147 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5148 DEnd = E->designators_end();
5149 D != DEnd; ++D) {
5150 if (D->isFieldDesignator()) {
5151 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5152 D->getDotLoc(),
5153 D->getFieldLoc()));
5154 continue;
5155 }
Mike Stump11289f42009-09-09 15:08:12 +00005156
Douglas Gregora16548e2009-08-11 05:31:07 +00005157 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005158 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005159 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005160 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005161
5162 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005163 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005164
Douglas Gregora16548e2009-08-11 05:31:07 +00005165 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5166 ArrayExprs.push_back(Index.release());
5167 continue;
5168 }
Mike Stump11289f42009-09-09 15:08:12 +00005169
Douglas Gregora16548e2009-08-11 05:31:07 +00005170 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00005171 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00005172 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5173 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005174 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005175
John McCalldadc5752010-08-24 06:29:42 +00005176 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005177 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005178 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005179
5180 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005181 End.get(),
5182 D->getLBracketLoc(),
5183 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005184
Douglas Gregora16548e2009-08-11 05:31:07 +00005185 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5186 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00005187
Douglas Gregora16548e2009-08-11 05:31:07 +00005188 ArrayExprs.push_back(Start.release());
5189 ArrayExprs.push_back(End.release());
5190 }
Mike Stump11289f42009-09-09 15:08:12 +00005191
Douglas Gregora16548e2009-08-11 05:31:07 +00005192 if (!getDerived().AlwaysRebuild() &&
5193 Init.get() == E->getInit() &&
5194 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005195 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005196
Douglas Gregora16548e2009-08-11 05:31:07 +00005197 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5198 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005199 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005200}
Mike Stump11289f42009-09-09 15:08:12 +00005201
Douglas Gregora16548e2009-08-11 05:31:07 +00005202template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005203ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005204TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005205 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00005206 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005207
Douglas Gregor3da3c062009-10-28 00:29:27 +00005208 // FIXME: Will we ever have proper type location here? Will we actually
5209 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00005210 QualType T = getDerived().TransformType(E->getType());
5211 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005212 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005213
Douglas Gregora16548e2009-08-11 05:31:07 +00005214 if (!getDerived().AlwaysRebuild() &&
5215 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005216 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005217
Douglas Gregora16548e2009-08-11 05:31:07 +00005218 return getDerived().RebuildImplicitValueInitExpr(T);
5219}
Mike Stump11289f42009-09-09 15:08:12 +00005220
Douglas Gregora16548e2009-08-11 05:31:07 +00005221template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005222ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005223TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00005224 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5225 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005226 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005227
John McCalldadc5752010-08-24 06:29:42 +00005228 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005229 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005230 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005231
Douglas Gregora16548e2009-08-11 05:31:07 +00005232 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00005233 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005234 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005235 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005236
John McCallb268a282010-08-23 23:25:46 +00005237 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00005238 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005239}
5240
5241template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005242ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005243TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005244 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005245 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005246 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005247 ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005248 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005249 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005250
Douglas Gregora16548e2009-08-11 05:31:07 +00005251 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00005252 Inits.push_back(Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005253 }
Mike Stump11289f42009-09-09 15:08:12 +00005254
Douglas Gregora16548e2009-08-11 05:31:07 +00005255 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5256 move_arg(Inits),
5257 E->getRParenLoc());
5258}
Mike Stump11289f42009-09-09 15:08:12 +00005259
Douglas Gregora16548e2009-08-11 05:31:07 +00005260/// \brief Transform an address-of-label expression.
5261///
5262/// By default, the transformation of an address-of-label expression always
5263/// rebuilds the expression, so that the label identifier can be resolved to
5264/// the corresponding label statement by semantic analysis.
5265template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005266ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005267TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005268 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
5269 E->getLabel());
5270}
Mike Stump11289f42009-09-09 15:08:12 +00005271
5272template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005273ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005274TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005275 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00005276 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5277 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005278 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005279
Douglas Gregora16548e2009-08-11 05:31:07 +00005280 if (!getDerived().AlwaysRebuild() &&
5281 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00005282 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005283
5284 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005285 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005286 E->getRParenLoc());
5287}
Mike Stump11289f42009-09-09 15:08:12 +00005288
Douglas Gregora16548e2009-08-11 05:31:07 +00005289template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005290ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005291TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005292 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005293 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005294 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005295
John McCalldadc5752010-08-24 06:29:42 +00005296 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005297 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005298 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005299
John McCalldadc5752010-08-24 06:29:42 +00005300 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005301 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005302 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005303
Douglas Gregora16548e2009-08-11 05:31:07 +00005304 if (!getDerived().AlwaysRebuild() &&
5305 Cond.get() == E->getCond() &&
5306 LHS.get() == E->getLHS() &&
5307 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005308 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005309
Douglas Gregora16548e2009-08-11 05:31:07 +00005310 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00005311 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005312 E->getRParenLoc());
5313}
Mike Stump11289f42009-09-09 15:08:12 +00005314
Douglas Gregora16548e2009-08-11 05:31:07 +00005315template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005316ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005317TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005318 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005319}
5320
5321template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005322ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005323TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005324 switch (E->getOperator()) {
5325 case OO_New:
5326 case OO_Delete:
5327 case OO_Array_New:
5328 case OO_Array_Delete:
5329 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00005330 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005331
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005332 case OO_Call: {
5333 // This is a call to an object's operator().
5334 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5335
5336 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00005337 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005338 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005339 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005340
5341 // FIXME: Poor location information
5342 SourceLocation FakeLParenLoc
5343 = SemaRef.PP.getLocForEndOfToken(
5344 static_cast<Expr *>(Object.get())->getLocEnd());
5345
5346 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00005347 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005348 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00005349 if (getDerived().DropCallArgument(E->getArg(I)))
5350 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005351
John McCalldadc5752010-08-24 06:29:42 +00005352 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005353 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005354 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005355
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005356 Args.push_back(Arg.release());
5357 }
5358
John McCallb268a282010-08-23 23:25:46 +00005359 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005360 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005361 E->getLocEnd());
5362 }
5363
5364#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5365 case OO_##Name:
5366#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5367#include "clang/Basic/OperatorKinds.def"
5368 case OO_Subscript:
5369 // Handled below.
5370 break;
5371
5372 case OO_Conditional:
5373 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00005374 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005375
5376 case OO_None:
5377 case NUM_OVERLOADED_OPERATORS:
5378 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00005379 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005380 }
5381
John McCalldadc5752010-08-24 06:29:42 +00005382 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005383 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005384 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005385
John McCalldadc5752010-08-24 06:29:42 +00005386 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005387 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005388 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005389
John McCalldadc5752010-08-24 06:29:42 +00005390 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00005391 if (E->getNumArgs() == 2) {
5392 Second = getDerived().TransformExpr(E->getArg(1));
5393 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005394 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005395 }
Mike Stump11289f42009-09-09 15:08:12 +00005396
Douglas Gregora16548e2009-08-11 05:31:07 +00005397 if (!getDerived().AlwaysRebuild() &&
5398 Callee.get() == E->getCallee() &&
5399 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005400 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00005401 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005402
Douglas Gregora16548e2009-08-11 05:31:07 +00005403 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5404 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005405 Callee.get(),
5406 First.get(),
5407 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005408}
Mike Stump11289f42009-09-09 15:08:12 +00005409
Douglas Gregora16548e2009-08-11 05:31:07 +00005410template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005411ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005412TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5413 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005414}
Mike Stump11289f42009-09-09 15:08:12 +00005415
Douglas Gregora16548e2009-08-11 05:31:07 +00005416template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005417ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005418TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005419 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5420 if (!Type)
5421 return ExprError();
5422
John McCalldadc5752010-08-24 06:29:42 +00005423 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005424 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005425 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005426 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005427
Douglas Gregora16548e2009-08-11 05:31:07 +00005428 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005429 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005430 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005431 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005432
Douglas Gregora16548e2009-08-11 05:31:07 +00005433 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005434 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005435 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5436 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5437 SourceLocation FakeRParenLoc
5438 = SemaRef.PP.getLocForEndOfToken(
5439 E->getSubExpr()->getSourceRange().getEnd());
5440 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005441 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005442 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005443 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005444 FakeRAngleLoc,
5445 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005446 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005447 FakeRParenLoc);
5448}
Mike Stump11289f42009-09-09 15:08:12 +00005449
Douglas Gregora16548e2009-08-11 05:31:07 +00005450template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005451ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005452TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5453 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005454}
Mike Stump11289f42009-09-09 15:08:12 +00005455
5456template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005457ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005458TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5459 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005460}
5461
Douglas Gregora16548e2009-08-11 05:31:07 +00005462template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005463ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005464TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005465 CXXReinterpretCastExpr *E) {
5466 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005467}
Mike Stump11289f42009-09-09 15:08:12 +00005468
Douglas Gregora16548e2009-08-11 05:31:07 +00005469template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005470ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005471TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5472 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005473}
Mike Stump11289f42009-09-09 15:08:12 +00005474
Douglas Gregora16548e2009-08-11 05:31:07 +00005475template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005476ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005477TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005478 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005479 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5480 if (!Type)
5481 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005482
John McCalldadc5752010-08-24 06:29:42 +00005483 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005484 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005485 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005486 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005487
Douglas Gregora16548e2009-08-11 05:31:07 +00005488 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005489 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005490 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005491 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005492
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005493 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005494 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005495 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005496 E->getRParenLoc());
5497}
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>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005502 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005503 TypeSourceInfo *TInfo
5504 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5505 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005506 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005507
Douglas Gregora16548e2009-08-11 05:31:07 +00005508 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005509 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005510 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005511
Douglas Gregor9da64192010-04-26 22:37:10 +00005512 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5513 E->getLocStart(),
5514 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005515 E->getLocEnd());
5516 }
Mike Stump11289f42009-09-09 15:08:12 +00005517
Douglas Gregora16548e2009-08-11 05:31:07 +00005518 // We don't know whether the expression is potentially evaluated until
5519 // after we perform semantic analysis, so the expression is potentially
5520 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005521 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00005522 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005523
John McCalldadc5752010-08-24 06:29:42 +00005524 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00005525 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005526 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005527
Douglas Gregora16548e2009-08-11 05:31:07 +00005528 if (!getDerived().AlwaysRebuild() &&
5529 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005530 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005531
Douglas Gregor9da64192010-04-26 22:37:10 +00005532 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5533 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005534 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005535 E->getLocEnd());
5536}
5537
5538template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005539ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00005540TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5541 if (E->isTypeOperand()) {
5542 TypeSourceInfo *TInfo
5543 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5544 if (!TInfo)
5545 return ExprError();
5546
5547 if (!getDerived().AlwaysRebuild() &&
5548 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005549 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005550
5551 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5552 E->getLocStart(),
5553 TInfo,
5554 E->getLocEnd());
5555 }
5556
5557 // We don't know whether the expression is potentially evaluated until
5558 // after we perform semantic analysis, so the expression is potentially
5559 // potentially evaluated.
5560 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5561
5562 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5563 if (SubExpr.isInvalid())
5564 return ExprError();
5565
5566 if (!getDerived().AlwaysRebuild() &&
5567 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005568 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005569
5570 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5571 E->getLocStart(),
5572 SubExpr.get(),
5573 E->getLocEnd());
5574}
5575
5576template<typename Derived>
5577ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005578TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005579 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005580}
Mike Stump11289f42009-09-09 15:08:12 +00005581
Douglas Gregora16548e2009-08-11 05:31:07 +00005582template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005583ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005584TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005585 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005586 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005587}
Mike Stump11289f42009-09-09 15:08:12 +00005588
Douglas Gregora16548e2009-08-11 05:31:07 +00005589template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005590ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005591TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005592 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5593 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5594 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00005595
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005596 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005597 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005598
Douglas Gregorb15af892010-01-07 23:12:05 +00005599 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005600}
Mike Stump11289f42009-09-09 15:08:12 +00005601
Douglas Gregora16548e2009-08-11 05:31:07 +00005602template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005603ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005604TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005605 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005606 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005607 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005608
Douglas Gregora16548e2009-08-11 05:31:07 +00005609 if (!getDerived().AlwaysRebuild() &&
5610 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005611 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005612
John McCallb268a282010-08-23 23:25:46 +00005613 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005614}
Mike Stump11289f42009-09-09 15:08:12 +00005615
Douglas Gregora16548e2009-08-11 05:31:07 +00005616template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005617ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005618TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005619 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005620 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5621 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005622 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00005623 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005624
Chandler Carruth794da4c2010-02-08 06:42:49 +00005625 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005626 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00005627 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005628
Douglas Gregor033f6752009-12-23 23:03:06 +00005629 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005630}
Mike Stump11289f42009-09-09 15:08:12 +00005631
Douglas Gregora16548e2009-08-11 05:31:07 +00005632template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005633ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00005634TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5635 CXXScalarValueInitExpr *E) {
5636 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5637 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005638 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00005639
Douglas Gregora16548e2009-08-11 05:31:07 +00005640 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005641 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005642 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005643
Douglas Gregor2b88c112010-09-08 00:15:04 +00005644 return getDerived().RebuildCXXScalarValueInitExpr(T,
5645 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00005646 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005647}
Mike Stump11289f42009-09-09 15:08:12 +00005648
Douglas Gregora16548e2009-08-11 05:31:07 +00005649template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005650ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005651TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005652 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00005653 TypeSourceInfo *AllocTypeInfo
5654 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5655 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005656 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005657
Douglas Gregora16548e2009-08-11 05:31:07 +00005658 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00005659 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00005660 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005661 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005662
Douglas Gregora16548e2009-08-11 05:31:07 +00005663 // Transform the placement arguments (if any).
5664 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005665 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005666 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
John McCall09d13692010-10-05 22:36:42 +00005667 if (getDerived().DropCallArgument(E->getPlacementArg(I))) {
5668 ArgumentChanged = true;
5669 break;
5670 }
5671
John McCalldadc5752010-08-24 06:29:42 +00005672 ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005673 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005674 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005675
Douglas Gregora16548e2009-08-11 05:31:07 +00005676 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5677 PlacementArgs.push_back(Arg.take());
5678 }
Mike Stump11289f42009-09-09 15:08:12 +00005679
Douglas Gregorebe10102009-08-20 07:17:43 +00005680 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00005681 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005682 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
John McCall09d13692010-10-05 22:36:42 +00005683 if (getDerived().DropCallArgument(E->getConstructorArg(I))) {
5684 ArgumentChanged = true;
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005685 break;
John McCall09d13692010-10-05 22:36:42 +00005686 }
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005687
John McCalldadc5752010-08-24 06:29:42 +00005688 ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00005689 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005690 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005691
Douglas Gregora16548e2009-08-11 05:31:07 +00005692 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5693 ConstructorArgs.push_back(Arg.take());
5694 }
Mike Stump11289f42009-09-09 15:08:12 +00005695
Douglas Gregord2d9da02010-02-26 00:38:10 +00005696 // Transform constructor, new operator, and delete operator.
5697 CXXConstructorDecl *Constructor = 0;
5698 if (E->getConstructor()) {
5699 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005700 getDerived().TransformDecl(E->getLocStart(),
5701 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005702 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005703 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005704 }
5705
5706 FunctionDecl *OperatorNew = 0;
5707 if (E->getOperatorNew()) {
5708 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005709 getDerived().TransformDecl(E->getLocStart(),
5710 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005711 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00005712 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005713 }
5714
5715 FunctionDecl *OperatorDelete = 0;
5716 if (E->getOperatorDelete()) {
5717 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005718 getDerived().TransformDecl(E->getLocStart(),
5719 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005720 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005721 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005722 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005723
Douglas Gregora16548e2009-08-11 05:31:07 +00005724 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00005725 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005726 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005727 Constructor == E->getConstructor() &&
5728 OperatorNew == E->getOperatorNew() &&
5729 OperatorDelete == E->getOperatorDelete() &&
5730 !ArgumentChanged) {
5731 // Mark any declarations we need as referenced.
5732 // FIXME: instantiation-specific.
5733 if (Constructor)
5734 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5735 if (OperatorNew)
5736 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5737 if (OperatorDelete)
5738 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00005739 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005740 }
Mike Stump11289f42009-09-09 15:08:12 +00005741
Douglas Gregor0744ef62010-09-07 21:49:58 +00005742 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005743 if (!ArraySize.get()) {
5744 // If no array size was specified, but the new expression was
5745 // instantiated with an array type (e.g., "new T" where T is
5746 // instantiated with "int[4]"), extract the outer bound from the
5747 // array type as our array size. We do this with constant and
5748 // dependently-sized array types.
5749 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5750 if (!ArrayT) {
5751 // Do nothing
5752 } else if (const ConstantArrayType *ConsArrayT
5753 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005754 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00005755 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5756 ConsArrayT->getSize(),
5757 SemaRef.Context.getSizeType(),
5758 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005759 AllocType = ConsArrayT->getElementType();
5760 } else if (const DependentSizedArrayType *DepArrayT
5761 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5762 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00005763 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005764 AllocType = DepArrayT->getElementType();
5765 }
5766 }
5767 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00005768
Douglas Gregora16548e2009-08-11 05:31:07 +00005769 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5770 E->isGlobalNew(),
5771 /*FIXME:*/E->getLocStart(),
5772 move_arg(PlacementArgs),
5773 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00005774 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005775 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00005776 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00005777 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005778 /*FIXME:*/E->getLocStart(),
5779 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005780 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005781}
Mike Stump11289f42009-09-09 15:08:12 +00005782
Douglas Gregora16548e2009-08-11 05:31:07 +00005783template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005784ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005785TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005786 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00005787 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005788 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005789
Douglas Gregord2d9da02010-02-26 00:38:10 +00005790 // Transform the delete operator, if known.
5791 FunctionDecl *OperatorDelete = 0;
5792 if (E->getOperatorDelete()) {
5793 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005794 getDerived().TransformDecl(E->getLocStart(),
5795 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005796 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005797 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005798 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005799
Douglas Gregora16548e2009-08-11 05:31:07 +00005800 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005801 Operand.get() == E->getArgument() &&
5802 OperatorDelete == E->getOperatorDelete()) {
5803 // Mark any declarations we need as referenced.
5804 // FIXME: instantiation-specific.
5805 if (OperatorDelete)
5806 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00005807
5808 if (!E->getArgument()->isTypeDependent()) {
5809 QualType Destroyed = SemaRef.Context.getBaseElementType(
5810 E->getDestroyedType());
5811 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
5812 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
5813 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
5814 SemaRef.LookupDestructor(Record));
5815 }
5816 }
5817
John McCallc3007a22010-10-26 07:05:15 +00005818 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005819 }
Mike Stump11289f42009-09-09 15:08:12 +00005820
Douglas Gregora16548e2009-08-11 05:31:07 +00005821 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5822 E->isGlobalDelete(),
5823 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00005824 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005825}
Mike Stump11289f42009-09-09 15:08:12 +00005826
Douglas Gregora16548e2009-08-11 05:31:07 +00005827template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005828ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005829TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005830 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005831 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00005832 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005833 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005834
John McCallba7bf592010-08-24 05:47:05 +00005835 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00005836 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005837 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005838 E->getOperatorLoc(),
5839 E->isArrow()? tok::arrow : tok::period,
5840 ObjectTypePtr,
5841 MayBePseudoDestructor);
5842 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005843 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005844
John McCallba7bf592010-08-24 05:47:05 +00005845 QualType ObjectType = ObjectTypePtr.get();
John McCall31f82722010-11-12 08:19:04 +00005846 NestedNameSpecifier *Qualifier = E->getQualifier();
5847 if (Qualifier) {
5848 Qualifier
5849 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5850 E->getQualifierRange(),
5851 ObjectType);
5852 if (!Qualifier)
5853 return ExprError();
5854 }
Mike Stump11289f42009-09-09 15:08:12 +00005855
Douglas Gregor678f90d2010-02-25 01:56:36 +00005856 PseudoDestructorTypeStorage Destroyed;
5857 if (E->getDestroyedTypeInfo()) {
5858 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00005859 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
5860 ObjectType, 0, Qualifier);
Douglas Gregor678f90d2010-02-25 01:56:36 +00005861 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005862 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00005863 Destroyed = DestroyedTypeInfo;
5864 } else if (ObjectType->isDependentType()) {
5865 // We aren't likely to be able to resolve the identifier down to a type
5866 // now anyway, so just retain the identifier.
5867 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5868 E->getDestroyedTypeLoc());
5869 } else {
5870 // Look for a destructor known with the given name.
5871 CXXScopeSpec SS;
5872 if (Qualifier) {
5873 SS.setScopeRep(Qualifier);
5874 SS.setRange(E->getQualifierRange());
5875 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005876
John McCallba7bf592010-08-24 05:47:05 +00005877 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005878 *E->getDestroyedTypeIdentifier(),
5879 E->getDestroyedTypeLoc(),
5880 /*Scope=*/0,
5881 SS, ObjectTypePtr,
5882 false);
5883 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005884 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005885
Douglas Gregor678f90d2010-02-25 01:56:36 +00005886 Destroyed
5887 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5888 E->getDestroyedTypeLoc());
5889 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005890
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005891 TypeSourceInfo *ScopeTypeInfo = 0;
5892 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00005893 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005894 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005895 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005896 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005897
John McCallb268a282010-08-23 23:25:46 +00005898 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005899 E->getOperatorLoc(),
5900 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005901 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005902 E->getQualifierRange(),
5903 ScopeTypeInfo,
5904 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005905 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005906 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005907}
Mike Stump11289f42009-09-09 15:08:12 +00005908
Douglas Gregorad8a3362009-09-04 17:36:40 +00005909template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005910ExprResult
John McCalld14a8642009-11-21 08:51:07 +00005911TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005912 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005913 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5914
5915 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5916 Sema::LookupOrdinaryName);
5917
5918 // Transform all the decls.
5919 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5920 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005921 NamedDecl *InstD = static_cast<NamedDecl*>(
5922 getDerived().TransformDecl(Old->getNameLoc(),
5923 *I));
John McCall84d87672009-12-10 09:41:52 +00005924 if (!InstD) {
5925 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5926 // This can happen because of dependent hiding.
5927 if (isa<UsingShadowDecl>(*I))
5928 continue;
5929 else
John McCallfaf5fb42010-08-26 23:41:50 +00005930 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00005931 }
John McCalle66edc12009-11-24 19:00:30 +00005932
5933 // Expand using declarations.
5934 if (isa<UsingDecl>(InstD)) {
5935 UsingDecl *UD = cast<UsingDecl>(InstD);
5936 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5937 E = UD->shadow_end(); I != E; ++I)
5938 R.addDecl(*I);
5939 continue;
5940 }
5941
5942 R.addDecl(InstD);
5943 }
5944
5945 // Resolve a kind, but don't do any further analysis. If it's
5946 // ambiguous, the callee needs to deal with it.
5947 R.resolveKind();
5948
5949 // Rebuild the nested-name qualifier, if present.
5950 CXXScopeSpec SS;
5951 NestedNameSpecifier *Qualifier = 0;
5952 if (Old->getQualifier()) {
5953 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005954 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005955 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005956 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005957
John McCalle66edc12009-11-24 19:00:30 +00005958 SS.setScopeRep(Qualifier);
5959 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005960 }
5961
Douglas Gregor9262f472010-04-27 18:19:34 +00005962 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005963 CXXRecordDecl *NamingClass
5964 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5965 Old->getNameLoc(),
5966 Old->getNamingClass()));
5967 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00005968 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005969
Douglas Gregorda7be082010-04-27 16:10:10 +00005970 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005971 }
5972
5973 // If we have no template arguments, it's a normal declaration name.
5974 if (!Old->hasExplicitTemplateArgs())
5975 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5976
5977 // If we have template arguments, rebuild them, then rebuild the
5978 // templateid expression.
5979 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005980 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
5981 Old->getNumTemplateArgs(),
5982 TransArgs))
5983 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00005984
5985 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5986 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005987}
Mike Stump11289f42009-09-09 15:08:12 +00005988
Douglas Gregora16548e2009-08-11 05:31:07 +00005989template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005990ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005991TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00005992 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
5993 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005994 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005995
Douglas Gregora16548e2009-08-11 05:31:07 +00005996 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00005997 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005998 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005999
Mike Stump11289f42009-09-09 15:08:12 +00006000 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006001 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006002 T,
6003 E->getLocEnd());
6004}
Mike Stump11289f42009-09-09 15:08:12 +00006005
Douglas Gregora16548e2009-08-11 05:31:07 +00006006template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006007ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006008TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6009 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6010 if (!LhsT)
6011 return ExprError();
6012
6013 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6014 if (!RhsT)
6015 return ExprError();
6016
6017 if (!getDerived().AlwaysRebuild() &&
6018 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6019 return SemaRef.Owned(E);
6020
6021 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6022 E->getLocStart(),
6023 LhsT, RhsT,
6024 E->getLocEnd());
6025}
6026
6027template<typename Derived>
6028ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006029TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006030 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006031 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00006032 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006033 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006034 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00006035 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006036
John McCall31f82722010-11-12 08:19:04 +00006037 // TODO: If this is a conversion-function-id, verify that the
6038 // destination type name (if present) resolves the same way after
6039 // instantiation as it did in the local scope.
6040
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006041 DeclarationNameInfo NameInfo
6042 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6043 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006044 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006045
John McCalle66edc12009-11-24 19:00:30 +00006046 if (!E->hasExplicitTemplateArgs()) {
6047 if (!getDerived().AlwaysRebuild() &&
6048 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006049 // Note: it is sufficient to compare the Name component of NameInfo:
6050 // if name has not changed, DNLoc has not changed either.
6051 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006052 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006053
John McCalle66edc12009-11-24 19:00:30 +00006054 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6055 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006056 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006057 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006058 }
John McCall6b51f282009-11-23 01:53:49 +00006059
6060 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006061 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6062 E->getNumTemplateArgs(),
6063 TransArgs))
6064 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006065
John McCalle66edc12009-11-24 19:00:30 +00006066 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6067 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006068 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006069 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006070}
6071
6072template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006073ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006074TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006075 // CXXConstructExprs are always implicit, so when we have a
6076 // 1-argument construction we just transform that argument.
6077 if (E->getNumArgs() == 1 ||
6078 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6079 return getDerived().TransformExpr(E->getArg(0));
6080
Douglas Gregora16548e2009-08-11 05:31:07 +00006081 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6082
6083 QualType T = getDerived().TransformType(E->getType());
6084 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006085 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006086
6087 CXXConstructorDecl *Constructor
6088 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006089 getDerived().TransformDecl(E->getLocStart(),
6090 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006091 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006092 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006093
Douglas Gregora16548e2009-08-11 05:31:07 +00006094 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006095 ASTOwningVector<Expr*> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00006096 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006097 ArgEnd = E->arg_end();
6098 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00006099 if (getDerived().DropCallArgument(*Arg)) {
6100 ArgumentChanged = true;
6101 break;
6102 }
6103
John McCalldadc5752010-08-24 06:29:42 +00006104 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00006105 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006106 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006107
Douglas Gregora16548e2009-08-11 05:31:07 +00006108 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00006109 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006110 }
6111
6112 if (!getDerived().AlwaysRebuild() &&
6113 T == E->getType() &&
6114 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006115 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006116 // Mark the constructor as referenced.
6117 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006118 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006119 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006120 }
Mike Stump11289f42009-09-09 15:08:12 +00006121
Douglas Gregordb121ba2009-12-14 16:27:04 +00006122 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6123 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006124 move_arg(Args),
6125 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006126 E->getConstructionKind(),
6127 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006128}
Mike Stump11289f42009-09-09 15:08:12 +00006129
Douglas Gregora16548e2009-08-11 05:31:07 +00006130/// \brief Transform a C++ temporary-binding expression.
6131///
Douglas Gregor363b1512009-12-24 18:51:59 +00006132/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6133/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006134template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006135ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006136TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006137 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006138}
Mike Stump11289f42009-09-09 15:08:12 +00006139
John McCall5d413782010-12-06 08:20:24 +00006140/// \brief Transform a C++ expression that contains cleanups that should
6141/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006142///
John McCall5d413782010-12-06 08:20:24 +00006143/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006144/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006145template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006146ExprResult
John McCall5d413782010-12-06 08:20:24 +00006147TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006148 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006149}
Mike Stump11289f42009-09-09 15:08:12 +00006150
Douglas Gregora16548e2009-08-11 05:31:07 +00006151template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006152ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006153TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006154 CXXTemporaryObjectExpr *E) {
6155 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6156 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006157 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006158
Douglas Gregora16548e2009-08-11 05:31:07 +00006159 CXXConstructorDecl *Constructor
6160 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006161 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006162 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006163 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006164 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006165
Douglas Gregora16548e2009-08-11 05:31:07 +00006166 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006167 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006168 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00006169 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006170 ArgEnd = E->arg_end();
6171 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006172 if (getDerived().DropCallArgument(*Arg)) {
6173 ArgumentChanged = true;
6174 break;
6175 }
6176
John McCalldadc5752010-08-24 06:29:42 +00006177 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00006178 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006179 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006180
Douglas Gregora16548e2009-08-11 05:31:07 +00006181 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
6182 Args.push_back((Expr *)TransArg.release());
6183 }
Mike Stump11289f42009-09-09 15:08:12 +00006184
Douglas Gregora16548e2009-08-11 05:31:07 +00006185 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006186 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006187 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006188 !ArgumentChanged) {
6189 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006190 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006191 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006192 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006193
6194 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6195 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006196 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006197 E->getLocEnd());
6198}
Mike Stump11289f42009-09-09 15:08:12 +00006199
Douglas Gregora16548e2009-08-11 05:31:07 +00006200template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006201ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006202TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006203 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00006204 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6205 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006206 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006207
Douglas Gregora16548e2009-08-11 05:31:07 +00006208 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006209 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006210 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
6211 ArgEnd = E->arg_end();
6212 Arg != ArgEnd; ++Arg) {
John McCalldadc5752010-08-24 06:29:42 +00006213 ExprResult TransArg = getDerived().TransformExpr(*Arg);
Douglas Gregora16548e2009-08-11 05:31:07 +00006214 if (TransArg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006215 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006216
Douglas Gregora16548e2009-08-11 05:31:07 +00006217 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
John McCallb268a282010-08-23 23:25:46 +00006218 Args.push_back(TransArg.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006219 }
Mike Stump11289f42009-09-09 15:08:12 +00006220
Douglas Gregora16548e2009-08-11 05:31:07 +00006221 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006222 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006223 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006224 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006225
Douglas Gregora16548e2009-08-11 05:31:07 +00006226 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00006227 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00006228 E->getLParenLoc(),
6229 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006230 E->getRParenLoc());
6231}
Mike Stump11289f42009-09-09 15:08:12 +00006232
Douglas Gregora16548e2009-08-11 05:31:07 +00006233template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006234ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006235TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006236 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006237 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006238 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006239 Expr *OldBase;
6240 QualType BaseType;
6241 QualType ObjectType;
6242 if (!E->isImplicitAccess()) {
6243 OldBase = E->getBase();
6244 Base = getDerived().TransformExpr(OldBase);
6245 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006246 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006247
John McCall2d74de92009-12-01 22:10:20 +00006248 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00006249 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00006250 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006251 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006252 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006253 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00006254 ObjectTy,
6255 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00006256 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006257 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006258
John McCallba7bf592010-08-24 05:47:05 +00006259 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00006260 BaseType = ((Expr*) Base.get())->getType();
6261 } else {
6262 OldBase = 0;
6263 BaseType = getDerived().TransformType(E->getBaseType());
6264 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6265 }
Mike Stump11289f42009-09-09 15:08:12 +00006266
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006267 // Transform the first part of the nested-name-specifier that qualifies
6268 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006269 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006270 = getDerived().TransformFirstQualifierInScope(
6271 E->getFirstQualifierFoundInScope(),
6272 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006273
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006274 NestedNameSpecifier *Qualifier = 0;
6275 if (E->getQualifier()) {
6276 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6277 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00006278 ObjectType,
6279 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006280 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006281 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006282 }
Mike Stump11289f42009-09-09 15:08:12 +00006283
John McCall31f82722010-11-12 08:19:04 +00006284 // TODO: If this is a conversion-function-id, verify that the
6285 // destination type name (if present) resolves the same way after
6286 // instantiation as it did in the local scope.
6287
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006288 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00006289 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006290 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006291 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006292
John McCall2d74de92009-12-01 22:10:20 +00006293 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00006294 // This is a reference to a member without an explicitly-specified
6295 // template argument list. Optimize for this common case.
6296 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00006297 Base.get() == OldBase &&
6298 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006299 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006300 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006301 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00006302 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006303
John McCallb268a282010-08-23 23:25:46 +00006304 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006305 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00006306 E->isArrow(),
6307 E->getOperatorLoc(),
6308 Qualifier,
6309 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00006310 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006311 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006312 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00006313 }
6314
John McCall6b51f282009-11-23 01:53:49 +00006315 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006316 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6317 E->getNumTemplateArgs(),
6318 TransArgs))
6319 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006320
John McCallb268a282010-08-23 23:25:46 +00006321 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006322 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006323 E->isArrow(),
6324 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006325 Qualifier,
6326 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006327 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006328 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006329 &TransArgs);
6330}
6331
6332template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006333ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006334TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00006335 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006336 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006337 QualType BaseType;
6338 if (!Old->isImplicitAccess()) {
6339 Base = getDerived().TransformExpr(Old->getBase());
6340 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006341 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006342 BaseType = ((Expr*) Base.get())->getType();
6343 } else {
6344 BaseType = getDerived().TransformType(Old->getBaseType());
6345 }
John McCall10eae182009-11-30 22:42:35 +00006346
6347 NestedNameSpecifier *Qualifier = 0;
6348 if (Old->getQualifier()) {
6349 Qualifier
6350 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006351 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00006352 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00006353 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006354 }
6355
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006356 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00006357 Sema::LookupOrdinaryName);
6358
6359 // Transform all the decls.
6360 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6361 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006362 NamedDecl *InstD = static_cast<NamedDecl*>(
6363 getDerived().TransformDecl(Old->getMemberLoc(),
6364 *I));
John McCall84d87672009-12-10 09:41:52 +00006365 if (!InstD) {
6366 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6367 // This can happen because of dependent hiding.
6368 if (isa<UsingShadowDecl>(*I))
6369 continue;
6370 else
John McCallfaf5fb42010-08-26 23:41:50 +00006371 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006372 }
John McCall10eae182009-11-30 22:42:35 +00006373
6374 // Expand using declarations.
6375 if (isa<UsingDecl>(InstD)) {
6376 UsingDecl *UD = cast<UsingDecl>(InstD);
6377 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6378 E = UD->shadow_end(); I != E; ++I)
6379 R.addDecl(*I);
6380 continue;
6381 }
6382
6383 R.addDecl(InstD);
6384 }
6385
6386 R.resolveKind();
6387
Douglas Gregor9262f472010-04-27 18:19:34 +00006388 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00006389 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006390 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00006391 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00006392 Old->getMemberLoc(),
6393 Old->getNamingClass()));
6394 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006395 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006396
Douglas Gregorda7be082010-04-27 16:10:10 +00006397 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00006398 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006399
John McCall10eae182009-11-30 22:42:35 +00006400 TemplateArgumentListInfo TransArgs;
6401 if (Old->hasExplicitTemplateArgs()) {
6402 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6403 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006404 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6405 Old->getNumTemplateArgs(),
6406 TransArgs))
6407 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006408 }
John McCall38836f02010-01-15 08:34:02 +00006409
6410 // FIXME: to do this check properly, we will need to preserve the
6411 // first-qualifier-in-scope here, just in case we had a dependent
6412 // base (and therefore couldn't do the check) and a
6413 // nested-name-qualifier (and therefore could do the lookup).
6414 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006415
John McCallb268a282010-08-23 23:25:46 +00006416 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006417 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006418 Old->getOperatorLoc(),
6419 Old->isArrow(),
6420 Qualifier,
6421 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006422 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006423 R,
6424 (Old->hasExplicitTemplateArgs()
6425 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006426}
6427
6428template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006429ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006430TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6431 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6432 if (SubExpr.isInvalid())
6433 return ExprError();
6434
6435 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00006436 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006437
6438 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6439}
6440
6441template<typename Derived>
6442ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006443TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006444 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006445}
6446
Mike Stump11289f42009-09-09 15:08:12 +00006447template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006448ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006449TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006450 TypeSourceInfo *EncodedTypeInfo
6451 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6452 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006453 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006454
Douglas Gregora16548e2009-08-11 05:31:07 +00006455 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006456 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006457 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006458
6459 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006460 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006461 E->getRParenLoc());
6462}
Mike Stump11289f42009-09-09 15:08:12 +00006463
Douglas Gregora16548e2009-08-11 05:31:07 +00006464template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006465ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006466TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006467 // Transform arguments.
6468 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006469 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006470 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006471 ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006472 if (Arg.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006473 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006474
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006475 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
John McCallb268a282010-08-23 23:25:46 +00006476 Args.push_back(Arg.get());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006477 }
6478
6479 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6480 // Class message: transform the receiver type.
6481 TypeSourceInfo *ReceiverTypeInfo
6482 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6483 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006484 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006485
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006486 // If nothing changed, just retain the existing message send.
6487 if (!getDerived().AlwaysRebuild() &&
6488 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006489 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006490
6491 // Build a new class message send.
6492 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6493 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00006494 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006495 E->getMethodDecl(),
6496 E->getLeftLoc(),
6497 move_arg(Args),
6498 E->getRightLoc());
6499 }
6500
6501 // Instance message: transform the receiver
6502 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6503 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00006504 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006505 = getDerived().TransformExpr(E->getInstanceReceiver());
6506 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006507 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006508
6509 // If nothing changed, just retain the existing message send.
6510 if (!getDerived().AlwaysRebuild() &&
6511 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006512 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006513
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006514 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00006515 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006516 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00006517 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006518 E->getMethodDecl(),
6519 E->getLeftLoc(),
6520 move_arg(Args),
6521 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006522}
6523
Mike Stump11289f42009-09-09 15:08:12 +00006524template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006525ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006526TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006527 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006528}
6529
Mike Stump11289f42009-09-09 15:08:12 +00006530template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006531ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006532TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006533 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006534}
6535
Mike Stump11289f42009-09-09 15:08:12 +00006536template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006537ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006538TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006539 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006540 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006541 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006542 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00006543
6544 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006545
Douglas Gregord51d90d2010-04-26 20:11:03 +00006546 // If nothing changed, just retain the existing expression.
6547 if (!getDerived().AlwaysRebuild() &&
6548 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006549 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006550
John McCallb268a282010-08-23 23:25:46 +00006551 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006552 E->getLocation(),
6553 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006554}
6555
Mike Stump11289f42009-09-09 15:08:12 +00006556template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006557ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006558TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00006559 // 'super' and types never change. Property never changes. Just
6560 // retain the existing expression.
6561 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00006562 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006563
Douglas Gregor9faee212010-04-26 20:47:02 +00006564 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006565 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00006566 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006567 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006568
Douglas Gregor9faee212010-04-26 20:47:02 +00006569 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006570
Douglas Gregor9faee212010-04-26 20:47:02 +00006571 // If nothing changed, just retain the existing expression.
6572 if (!getDerived().AlwaysRebuild() &&
6573 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006574 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006575
John McCallb7bd14f2010-12-02 01:19:52 +00006576 if (E->isExplicitProperty())
6577 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6578 E->getExplicitProperty(),
6579 E->getLocation());
6580
6581 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6582 E->getType(),
6583 E->getImplicitPropertyGetter(),
6584 E->getImplicitPropertySetter(),
6585 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006586}
6587
Mike Stump11289f42009-09-09 15:08:12 +00006588template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006589ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006590TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006591 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006592 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006593 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006594 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006595
Douglas Gregord51d90d2010-04-26 20:11:03 +00006596 // If nothing changed, just retain the existing expression.
6597 if (!getDerived().AlwaysRebuild() &&
6598 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006599 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006600
John McCallb268a282010-08-23 23:25:46 +00006601 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006602 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006603}
6604
Mike Stump11289f42009-09-09 15:08:12 +00006605template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006606ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006607TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006608 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006609 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006610 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006611 ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
Douglas Gregora16548e2009-08-11 05:31:07 +00006612 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006613 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006614
Douglas Gregora16548e2009-08-11 05:31:07 +00006615 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
John McCallb268a282010-08-23 23:25:46 +00006616 SubExprs.push_back(SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006617 }
Mike Stump11289f42009-09-09 15:08:12 +00006618
Douglas Gregora16548e2009-08-11 05:31:07 +00006619 if (!getDerived().AlwaysRebuild() &&
6620 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006621 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006622
Douglas Gregora16548e2009-08-11 05:31:07 +00006623 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6624 move_arg(SubExprs),
6625 E->getRParenLoc());
6626}
6627
Mike Stump11289f42009-09-09 15:08:12 +00006628template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006629ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006630TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006631 SourceLocation CaretLoc(E->getExprLoc());
6632
6633 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6634 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6635 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6636 llvm::SmallVector<ParmVarDecl*, 4> Params;
6637 llvm::SmallVector<QualType, 4> ParamTypes;
6638
6639 // Parameter substitution.
6640 const BlockDecl *BD = E->getBlockDecl();
6641 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6642 EN = BD->param_end(); P != EN; ++P) {
6643 ParmVarDecl *OldParm = (*P);
6644 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6645 QualType NewType = NewParm->getType();
6646 Params.push_back(NewParm);
6647 ParamTypes.push_back(NewParm->getType());
6648 }
6649
6650 const FunctionType *BExprFunctionType = E->getFunctionType();
6651 QualType BExprResultType = BExprFunctionType->getResultType();
6652 if (!BExprResultType.isNull()) {
6653 if (!BExprResultType->isDependentType())
6654 CurBlock->ReturnType = BExprResultType;
6655 else if (BExprResultType != SemaRef.Context.DependentTy)
6656 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6657 }
6658
6659 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006660 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006661 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006662 return ExprError();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006663 // Set the parameters on the block decl.
6664 if (!Params.empty())
6665 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6666
6667 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6668 CurBlock->ReturnType,
6669 ParamTypes.data(),
6670 ParamTypes.size(),
6671 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006672 0,
6673 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006674
6675 CurBlock->FunctionType = FunctionType;
John McCallb268a282010-08-23 23:25:46 +00006676 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006677}
6678
Mike Stump11289f42009-09-09 15:08:12 +00006679template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006680ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006681TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006682 NestedNameSpecifier *Qualifier = 0;
6683
6684 ValueDecl *ND
6685 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6686 E->getDecl()));
6687 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006688 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006689
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006690 if (!getDerived().AlwaysRebuild() &&
6691 ND == E->getDecl()) {
6692 // Mark it referenced in the new context regardless.
6693 // FIXME: this is a bit instantiation-specific.
6694 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6695
John McCallc3007a22010-10-26 07:05:15 +00006696 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006697 }
6698
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006699 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006700 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006701 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006702}
Mike Stump11289f42009-09-09 15:08:12 +00006703
Douglas Gregora16548e2009-08-11 05:31:07 +00006704//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006705// Type reconstruction
6706//===----------------------------------------------------------------------===//
6707
Mike Stump11289f42009-09-09 15:08:12 +00006708template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006709QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6710 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006711 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006712 getDerived().getBaseEntity());
6713}
6714
Mike Stump11289f42009-09-09 15:08:12 +00006715template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006716QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6717 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006718 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006719 getDerived().getBaseEntity());
6720}
6721
Mike Stump11289f42009-09-09 15:08:12 +00006722template<typename Derived>
6723QualType
John McCall70dd5f62009-10-30 00:06:24 +00006724TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6725 bool WrittenAsLValue,
6726 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006727 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006728 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006729}
6730
6731template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006732QualType
John McCall70dd5f62009-10-30 00:06:24 +00006733TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6734 QualType ClassType,
6735 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006736 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006737 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006738}
6739
6740template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006741QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006742TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6743 ArrayType::ArraySizeModifier SizeMod,
6744 const llvm::APInt *Size,
6745 Expr *SizeExpr,
6746 unsigned IndexTypeQuals,
6747 SourceRange BracketsRange) {
6748 if (SizeExpr || !Size)
6749 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6750 IndexTypeQuals, BracketsRange,
6751 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006752
6753 QualType Types[] = {
6754 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6755 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6756 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006757 };
6758 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6759 QualType SizeType;
6760 for (unsigned I = 0; I != NumTypes; ++I)
6761 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6762 SizeType = Types[I];
6763 break;
6764 }
Mike Stump11289f42009-09-09 15:08:12 +00006765
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006766 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6767 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006768 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006769 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006770 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006771}
Mike Stump11289f42009-09-09 15:08:12 +00006772
Douglas Gregord6ff3322009-08-04 16:50:30 +00006773template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006774QualType
6775TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006776 ArrayType::ArraySizeModifier SizeMod,
6777 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006778 unsigned IndexTypeQuals,
6779 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006780 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006781 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006782}
6783
6784template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006785QualType
Mike Stump11289f42009-09-09 15:08:12 +00006786TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006787 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006788 unsigned IndexTypeQuals,
6789 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006790 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006791 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006792}
Mike Stump11289f42009-09-09 15:08:12 +00006793
Douglas Gregord6ff3322009-08-04 16:50:30 +00006794template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006795QualType
6796TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006797 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006798 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006799 unsigned IndexTypeQuals,
6800 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006801 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006802 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006803 IndexTypeQuals, BracketsRange);
6804}
6805
6806template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006807QualType
6808TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006809 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006810 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006811 unsigned IndexTypeQuals,
6812 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006813 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006814 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006815 IndexTypeQuals, BracketsRange);
6816}
6817
6818template<typename Derived>
6819QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00006820 unsigned NumElements,
6821 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006822 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00006823 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006824}
Mike Stump11289f42009-09-09 15:08:12 +00006825
Douglas Gregord6ff3322009-08-04 16:50:30 +00006826template<typename Derived>
6827QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6828 unsigned NumElements,
6829 SourceLocation AttributeLoc) {
6830 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6831 NumElements, true);
6832 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006833 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6834 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00006835 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006836}
Mike Stump11289f42009-09-09 15:08:12 +00006837
Douglas Gregord6ff3322009-08-04 16:50:30 +00006838template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006839QualType
6840TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00006841 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006842 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00006843 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006844}
Mike Stump11289f42009-09-09 15:08:12 +00006845
Douglas Gregord6ff3322009-08-04 16:50:30 +00006846template<typename Derived>
6847QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006848 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006849 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006850 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00006851 unsigned Quals,
6852 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00006853 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006854 Quals,
6855 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006856 getDerived().getBaseEntity(),
6857 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006858}
Mike Stump11289f42009-09-09 15:08:12 +00006859
Douglas Gregord6ff3322009-08-04 16:50:30 +00006860template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006861QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6862 return SemaRef.Context.getFunctionNoProtoType(T);
6863}
6864
6865template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006866QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6867 assert(D && "no decl found");
6868 if (D->isInvalidDecl()) return QualType();
6869
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006870 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006871 TypeDecl *Ty;
6872 if (isa<UsingDecl>(D)) {
6873 UsingDecl *Using = cast<UsingDecl>(D);
6874 assert(Using->isTypeName() &&
6875 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6876
6877 // A valid resolved using typename decl points to exactly one type decl.
6878 assert(++Using->shadow_begin() == Using->shadow_end());
6879 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006880
John McCallb96ec562009-12-04 22:46:56 +00006881 } else {
6882 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6883 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6884 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6885 }
6886
6887 return SemaRef.Context.getTypeDeclType(Ty);
6888}
6889
6890template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00006891QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
6892 SourceLocation Loc) {
6893 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006894}
6895
6896template<typename Derived>
6897QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6898 return SemaRef.Context.getTypeOfType(Underlying);
6899}
6900
6901template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00006902QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
6903 SourceLocation Loc) {
6904 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006905}
6906
6907template<typename Derived>
6908QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006909 TemplateName Template,
6910 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006911 const TemplateArgumentListInfo &TemplateArgs) {
6912 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006913}
Mike Stump11289f42009-09-09 15:08:12 +00006914
Douglas Gregor1135c352009-08-06 05:28:30 +00006915template<typename Derived>
6916NestedNameSpecifier *
6917TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6918 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006919 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006920 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006921 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006922 CXXScopeSpec SS;
6923 // FIXME: The source location information is all wrong.
6924 SS.setRange(Range);
6925 SS.setScopeRep(Prefix);
6926 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006927 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006928 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006929 ObjectType,
6930 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006931 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006932}
6933
6934template<typename Derived>
6935NestedNameSpecifier *
6936TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6937 SourceRange Range,
6938 NamespaceDecl *NS) {
6939 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6940}
6941
6942template<typename Derived>
6943NestedNameSpecifier *
6944TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6945 SourceRange Range,
6946 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006947 QualType T) {
6948 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006949 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006950 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006951 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6952 T.getTypePtr());
6953 }
Mike Stump11289f42009-09-09 15:08:12 +00006954
Douglas Gregor1135c352009-08-06 05:28:30 +00006955 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6956 return 0;
6957}
Mike Stump11289f42009-09-09 15:08:12 +00006958
Douglas Gregor71dc5092009-08-06 06:41:21 +00006959template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006960TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006961TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6962 bool TemplateKW,
6963 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006964 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006965 Template);
6966}
6967
6968template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006969TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006970TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00006971 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00006972 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00006973 QualType ObjectType,
6974 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006975 CXXScopeSpec SS;
Douglas Gregora5614c52010-09-08 23:56:00 +00006976 SS.setRange(QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00006977 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006978 UnqualifiedId Name;
6979 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00006980 Sema::TemplateTy Template;
6981 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6982 /*FIXME:*/getDerived().getBaseLocation(),
6983 SS,
6984 Name,
John McCallba7bf592010-08-24 05:47:05 +00006985 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00006986 /*EnteringContext=*/false,
6987 Template);
John McCall31f82722010-11-12 08:19:04 +00006988 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006989}
Mike Stump11289f42009-09-09 15:08:12 +00006990
Douglas Gregora16548e2009-08-11 05:31:07 +00006991template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006992TemplateName
6993TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6994 OverloadedOperatorKind Operator,
6995 QualType ObjectType) {
6996 CXXScopeSpec SS;
6997 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6998 SS.setScopeRep(Qualifier);
6999 UnqualifiedId Name;
7000 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7001 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7002 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007003 Sema::TemplateTy Template;
7004 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007005 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007006 SS,
7007 Name,
John McCallba7bf592010-08-24 05:47:05 +00007008 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007009 /*EnteringContext=*/false,
7010 Template);
7011 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007012}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007013
Douglas Gregor71395fa2009-11-04 00:56:37 +00007014template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007015ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007016TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7017 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007018 Expr *OrigCallee,
7019 Expr *First,
7020 Expr *Second) {
7021 Expr *Callee = OrigCallee->IgnoreParenCasts();
7022 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007023
Douglas Gregora16548e2009-08-11 05:31:07 +00007024 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007025 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007026 if (!First->getType()->isOverloadableType() &&
7027 !Second->getType()->isOverloadableType())
7028 return getSema().CreateBuiltinArraySubscriptExpr(First,
7029 Callee->getLocStart(),
7030 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007031 } else if (Op == OO_Arrow) {
7032 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007033 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7034 } else if (Second == 0 || isPostIncDec) {
7035 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007036 // The argument is not of overloadable type, so try to create a
7037 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007038 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007039 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007040
John McCallb268a282010-08-23 23:25:46 +00007041 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007042 }
7043 } else {
John McCallb268a282010-08-23 23:25:46 +00007044 if (!First->getType()->isOverloadableType() &&
7045 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007046 // Neither of the arguments is an overloadable type, so try to
7047 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007048 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007049 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007050 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007051 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007052 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007053
Douglas Gregora16548e2009-08-11 05:31:07 +00007054 return move(Result);
7055 }
7056 }
Mike Stump11289f42009-09-09 15:08:12 +00007057
7058 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007059 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007060 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007061
John McCallb268a282010-08-23 23:25:46 +00007062 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007063 assert(ULE->requiresADL());
7064
7065 // FIXME: Do we have to check
7066 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007067 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007068 } else {
John McCallb268a282010-08-23 23:25:46 +00007069 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007070 }
Mike Stump11289f42009-09-09 15:08:12 +00007071
Douglas Gregora16548e2009-08-11 05:31:07 +00007072 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007073 Expr *Args[2] = { First, Second };
7074 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007075
Douglas Gregora16548e2009-08-11 05:31:07 +00007076 // Create the overloaded operator invocation for unary operators.
7077 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007078 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007079 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007080 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007081 }
Mike Stump11289f42009-09-09 15:08:12 +00007082
Sebastian Redladba46e2009-10-29 20:17:01 +00007083 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007084 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007085 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007086 First,
7087 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007088
Douglas Gregora16548e2009-08-11 05:31:07 +00007089 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007090 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007091 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007092 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7093 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007094 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007095
Mike Stump11289f42009-09-09 15:08:12 +00007096 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007097}
Mike Stump11289f42009-09-09 15:08:12 +00007098
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007099template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007100ExprResult
John McCallb268a282010-08-23 23:25:46 +00007101TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007102 SourceLocation OperatorLoc,
7103 bool isArrow,
7104 NestedNameSpecifier *Qualifier,
7105 SourceRange QualifierRange,
7106 TypeSourceInfo *ScopeType,
7107 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007108 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007109 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007110 CXXScopeSpec SS;
7111 if (Qualifier) {
7112 SS.setRange(QualifierRange);
7113 SS.setScopeRep(Qualifier);
7114 }
7115
John McCallb268a282010-08-23 23:25:46 +00007116 QualType BaseType = Base->getType();
7117 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007118 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007119 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007120 !BaseType->getAs<PointerType>()->getPointeeType()
7121 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007122 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00007123 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007124 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007125 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007126 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007127 /*FIXME?*/true);
7128 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007129
Douglas Gregor678f90d2010-02-25 01:56:36 +00007130 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007131 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7132 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7133 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7134 NameInfo.setNamedTypeInfo(DestroyedType);
7135
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007136 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007137
John McCallb268a282010-08-23 23:25:46 +00007138 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007139 OperatorLoc, isArrow,
7140 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007141 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007142 /*TemplateArgs*/ 0);
7143}
7144
Douglas Gregord6ff3322009-08-04 16:50:30 +00007145} // end namespace clang
7146
7147#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H