blob: c38902a3e99c9331f30a4b88b7e58638e46c42d3 [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
Mike Stump11289f42009-09-09 15:08:12 +000095public:
Douglas Gregord6ff3322009-08-04 16:50:30 +000096 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +000097 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +000098
Douglas Gregord6ff3322009-08-04 16:50:30 +000099 /// \brief Retrieves a reference to the derived class.
100 Derived &getDerived() { return static_cast<Derived&>(*this); }
101
102 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000103 const Derived &getDerived() const {
104 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000105 }
106
John McCalldadc5752010-08-24 06:29:42 +0000107 static inline ExprResult Owned(Expr *E) { return E; }
108 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000109
Douglas Gregord6ff3322009-08-04 16:50:30 +0000110 /// \brief Retrieves a reference to the semantic analysis object used for
111 /// this tree transform.
112 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000113
Douglas Gregord6ff3322009-08-04 16:50:30 +0000114 /// \brief Whether the transformation should always rebuild AST nodes, even
115 /// if none of the children have changed.
116 ///
117 /// Subclasses may override this function to specify when the transformation
118 /// should rebuild all AST nodes.
119 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000120
Douglas Gregord6ff3322009-08-04 16:50:30 +0000121 /// \brief Returns the location of the entity being transformed, if that
122 /// information was not available elsewhere in the AST.
123 ///
Mike Stump11289f42009-09-09 15:08:12 +0000124 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000125 /// provide an alternative implementation that provides better location
126 /// information.
127 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000128
Douglas Gregord6ff3322009-08-04 16:50:30 +0000129 /// \brief Returns the name of the entity being transformed, if that
130 /// information was not available elsewhere in the AST.
131 ///
132 /// By default, returns an empty name. Subclasses can provide an alternative
133 /// implementation with a more precise name.
134 DeclarationName getBaseEntity() { return DeclarationName(); }
135
Douglas Gregora16548e2009-08-11 05:31:07 +0000136 /// \brief Sets the "base" location and entity when that
137 /// information is known based on another transformation.
138 ///
139 /// By default, the source location and entity are ignored. Subclasses can
140 /// override this function to provide a customized implementation.
141 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000142
Douglas Gregora16548e2009-08-11 05:31:07 +0000143 /// \brief RAII object that temporarily sets the base location and entity
144 /// used for reporting diagnostics in types.
145 class TemporaryBase {
146 TreeTransform &Self;
147 SourceLocation OldLocation;
148 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000149
Douglas Gregora16548e2009-08-11 05:31:07 +0000150 public:
151 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000152 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000153 OldLocation = Self.getDerived().getBaseLocation();
154 OldEntity = Self.getDerived().getBaseEntity();
155 Self.getDerived().setBase(Location, Entity);
156 }
Mike Stump11289f42009-09-09 15:08:12 +0000157
Douglas Gregora16548e2009-08-11 05:31:07 +0000158 ~TemporaryBase() {
159 Self.getDerived().setBase(OldLocation, OldEntity);
160 }
161 };
Mike Stump11289f42009-09-09 15:08:12 +0000162
163 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000164 /// transformed.
165 ///
166 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000167 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000168 /// not change. For example, template instantiation need not traverse
169 /// non-dependent types.
170 bool AlreadyTransformed(QualType T) {
171 return T.isNull();
172 }
173
Douglas Gregord196a582009-12-14 19:27:10 +0000174 /// \brief Determine whether the given call argument should be dropped, e.g.,
175 /// because it is a default argument.
176 ///
177 /// Subclasses can provide an alternative implementation of this routine to
178 /// determine which kinds of call arguments get dropped. By default,
179 /// CXXDefaultArgument nodes are dropped (prior to transformation).
180 bool DropCallArgument(Expr *E) {
181 return E->isDefaultArgument();
182 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000183
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000184 /// \brief Determine whether we should expand a pack expansion with the
185 /// given set of parameter packs into separate arguments by repeatedly
186 /// transforming the pattern.
187 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000188 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000189 /// Subclasses can override this routine to provide different behavior.
190 ///
191 /// \param EllipsisLoc The location of the ellipsis that identifies the
192 /// pack expansion.
193 ///
194 /// \param PatternRange The source range that covers the entire pattern of
195 /// the pack expansion.
196 ///
197 /// \param Unexpanded The set of unexpanded parameter packs within the
198 /// pattern.
199 ///
200 /// \param NumUnexpanded The number of unexpanded parameter packs in
201 /// \p Unexpanded.
202 ///
203 /// \param ShouldExpand Will be set to \c true if the transformer should
204 /// expand the corresponding pack expansions into separate arguments. When
205 /// set, \c NumExpansions must also be set.
206 ///
207 /// \param NumExpansions The number of separate arguments that will be in
208 /// the expanded form of the corresponding pack expansion. Must be set when
209 /// \c ShouldExpand is \c true.
210 ///
211 /// \returns true if an error occurred (e.g., because the parameter packs
212 /// are to be instantiated with arguments of different lengths), false
213 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
214 /// must be set.
215 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
216 SourceRange PatternRange,
217 const UnexpandedParameterPack *Unexpanded,
218 unsigned NumUnexpanded,
219 bool &ShouldExpand,
220 unsigned &NumExpansions) {
221 ShouldExpand = false;
222 return false;
223 }
224
Douglas Gregord6ff3322009-08-04 16:50:30 +0000225 /// \brief Transforms the given type into another type.
226 ///
John McCall550e0c22009-10-21 00:40:46 +0000227 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000228 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000229 /// function. This is expensive, but we don't mind, because
230 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000231 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000232 ///
233 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000234 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000235
John McCall550e0c22009-10-21 00:40:46 +0000236 /// \brief Transforms the given type-with-location into a new
237 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000238 ///
John McCall550e0c22009-10-21 00:40:46 +0000239 /// By default, this routine transforms a type by delegating to the
240 /// appropriate TransformXXXType to build a new type. Subclasses
241 /// may override this function (to take over all type
242 /// transformations) or some set of the TransformXXXType functions
243 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000244 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000245
246 /// \brief Transform the given type-with-location into a new
247 /// type, collecting location information in the given builder
248 /// as necessary.
249 ///
John McCall31f82722010-11-12 08:19:04 +0000250 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000251
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000252 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000253 ///
Mike Stump11289f42009-09-09 15:08:12 +0000254 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000255 /// appropriate TransformXXXStmt function to transform a specific kind of
256 /// statement or the TransformExpr() function to transform an expression.
257 /// Subclasses may override this function to transform statements using some
258 /// other mechanism.
259 ///
260 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000261 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000262
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000263 /// \brief Transform the given expression.
264 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000265 /// By default, this routine transforms an expression by delegating to the
266 /// appropriate TransformXXXExpr function to build a new expression.
267 /// Subclasses may override this function to transform expressions using some
268 /// other mechanism.
269 ///
270 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000271 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000272
Douglas Gregora3efea12011-01-03 19:04:46 +0000273 /// \brief Transform the given list of expressions.
274 ///
275 /// This routine transforms a list of expressions by invoking
276 /// \c TransformExpr() for each subexpression. However, it also provides
277 /// support for variadic templates by expanding any pack expansions (if the
278 /// derived class permits such expansion) along the way. When pack expansions
279 /// are present, the number of outputs may not equal the number of inputs.
280 ///
281 /// \param Inputs The set of expressions to be transformed.
282 ///
283 /// \param NumInputs The number of expressions in \c Inputs.
284 ///
285 /// \param IsCall If \c true, then this transform is being performed on
286 /// function-call arguments, and any arguments that should be dropped, will
287 /// be.
288 ///
289 /// \param Outputs The transformed input expressions will be added to this
290 /// vector.
291 ///
292 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
293 /// due to transformation.
294 ///
295 /// \returns true if an error occurred, false otherwise.
296 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
297 llvm::SmallVectorImpl<Expr *> &Outputs,
298 bool *ArgChanged = 0);
299
Douglas Gregord6ff3322009-08-04 16:50:30 +0000300 /// \brief Transform the given declaration, which is referenced from a type
301 /// or expression.
302 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000303 /// By default, acts as the identity function on declarations. Subclasses
304 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000305 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000306
307 /// \brief Transform the definition of the given declaration.
308 ///
Mike Stump11289f42009-09-09 15:08:12 +0000309 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000310 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000311 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
312 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000313 }
Mike Stump11289f42009-09-09 15:08:12 +0000314
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000315 /// \brief Transform the given declaration, which was the first part of a
316 /// nested-name-specifier in a member access expression.
317 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000318 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000319 /// identifier in a nested-name-specifier of a member access expression, e.g.,
320 /// the \c T in \c x->T::member
321 ///
322 /// By default, invokes TransformDecl() to transform the declaration.
323 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000324 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
325 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000326 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000327
Douglas Gregord6ff3322009-08-04 16:50:30 +0000328 /// \brief Transform the given nested-name-specifier.
329 ///
Mike Stump11289f42009-09-09 15:08:12 +0000330 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000331 /// nested-name-specifier. Subclasses may override this function to provide
332 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000333 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000334 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000335 QualType ObjectType = QualType(),
336 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000337
Douglas Gregorf816bd72009-09-03 22:13:48 +0000338 /// \brief Transform the given declaration name.
339 ///
340 /// By default, transforms the types of conversion function, constructor,
341 /// and destructor names and then (if needed) rebuilds the declaration name.
342 /// Identifiers and selectors are returned unmodified. Sublcasses may
343 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000344 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000345 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000346
Douglas Gregord6ff3322009-08-04 16:50:30 +0000347 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000348 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000349 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000350 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000351 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000352 TemplateName TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +0000353 QualType ObjectType = QualType(),
354 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000355
Douglas Gregord6ff3322009-08-04 16:50:30 +0000356 /// \brief Transform the given template argument.
357 ///
Mike Stump11289f42009-09-09 15:08:12 +0000358 /// By default, this operation transforms the type, expression, or
359 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000360 /// new template argument from the transformed result. Subclasses may
361 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000362 ///
363 /// Returns true if there was an error.
364 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
365 TemplateArgumentLoc &Output);
366
Douglas Gregor62e06f22010-12-20 17:31:10 +0000367 /// \brief Transform the given set of template arguments.
368 ///
369 /// By default, this operation transforms all of the template arguments
370 /// in the input set using \c TransformTemplateArgument(), and appends
371 /// the transformed arguments to the output list.
372 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000373 /// Note that this overload of \c TransformTemplateArguments() is merely
374 /// a convenience function. Subclasses that wish to override this behavior
375 /// should override the iterator-based member template version.
376 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000377 /// \param Inputs The set of template arguments to be transformed.
378 ///
379 /// \param NumInputs The number of template arguments in \p Inputs.
380 ///
381 /// \param Outputs The set of transformed template arguments output by this
382 /// routine.
383 ///
384 /// Returns true if an error occurred.
385 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
386 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000387 TemplateArgumentListInfo &Outputs) {
388 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
389 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000390
391 /// \brief Transform the given set of template arguments.
392 ///
393 /// By default, this operation transforms all of the template arguments
394 /// in the input set using \c TransformTemplateArgument(), and appends
395 /// the transformed arguments to the output list.
396 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000397 /// \param First An iterator to the first template argument.
398 ///
399 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000400 ///
401 /// \param Outputs The set of transformed template arguments output by this
402 /// routine.
403 ///
404 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000405 template<typename InputIterator>
406 bool TransformTemplateArguments(InputIterator First,
407 InputIterator Last,
408 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000409
John McCall0ad16662009-10-29 08:12:44 +0000410 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
411 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
412 TemplateArgumentLoc &ArgLoc);
413
John McCallbcd03502009-12-07 02:54:59 +0000414 /// \brief Fakes up a TypeSourceInfo for a type.
415 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
416 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000417 getDerived().getBaseLocation());
418 }
Mike Stump11289f42009-09-09 15:08:12 +0000419
John McCall550e0c22009-10-21 00:40:46 +0000420#define ABSTRACT_TYPELOC(CLASS, PARENT)
421#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000422 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000423#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000424
John McCall31f82722010-11-12 08:19:04 +0000425 QualType
426 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
427 TemplateSpecializationTypeLoc TL,
428 TemplateName Template);
429
430 QualType
431 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
432 DependentTemplateSpecializationTypeLoc TL,
433 NestedNameSpecifier *Prefix);
434
John McCall58f10c32010-03-11 09:03:00 +0000435 /// \brief Transforms the parameters of a function type into the
436 /// given vectors.
437 ///
438 /// The result vectors should be kept in sync; null entries in the
439 /// variables vector are acceptable.
440 ///
441 /// Return true on error.
442 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
443 llvm::SmallVectorImpl<QualType> &PTypes,
444 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
445
446 /// \brief Transforms a single function-type parameter. Return null
447 /// on error.
448 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
449
John McCall31f82722010-11-12 08:19:04 +0000450 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000451
John McCalldadc5752010-08-24 06:29:42 +0000452 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
453 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000454
Douglas Gregorebe10102009-08-20 07:17:43 +0000455#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000456 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000457#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000458 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000459#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000460#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000461
Douglas Gregord6ff3322009-08-04 16:50:30 +0000462 /// \brief Build a new pointer type given its pointee type.
463 ///
464 /// By default, performs semantic analysis when building the pointer type.
465 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000466 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000467
468 /// \brief Build a new block pointer type given its pointee type.
469 ///
Mike Stump11289f42009-09-09 15:08:12 +0000470 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000471 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000472 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000473
John McCall70dd5f62009-10-30 00:06:24 +0000474 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000475 ///
John McCall70dd5f62009-10-30 00:06:24 +0000476 /// By default, performs semantic analysis when building the
477 /// reference type. Subclasses may override this routine to provide
478 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000479 ///
John McCall70dd5f62009-10-30 00:06:24 +0000480 /// \param LValue whether the type was written with an lvalue sigil
481 /// or an rvalue sigil.
482 QualType RebuildReferenceType(QualType ReferentType,
483 bool LValue,
484 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000485
Douglas Gregord6ff3322009-08-04 16:50:30 +0000486 /// \brief Build a new member pointer type given the pointee type and the
487 /// class type it refers into.
488 ///
489 /// By default, performs semantic analysis when building the member pointer
490 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000491 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
492 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000493
Douglas Gregord6ff3322009-08-04 16:50:30 +0000494 /// \brief Build a new array type given the element type, size
495 /// modifier, size of the array (if known), size expression, and index type
496 /// qualifiers.
497 ///
498 /// By default, performs semantic analysis when building the array type.
499 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000500 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000501 QualType RebuildArrayType(QualType ElementType,
502 ArrayType::ArraySizeModifier SizeMod,
503 const llvm::APInt *Size,
504 Expr *SizeExpr,
505 unsigned IndexTypeQuals,
506 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000507
Douglas Gregord6ff3322009-08-04 16:50:30 +0000508 /// \brief Build a new constant array type given the element type, size
509 /// modifier, (known) size of the array, and index type qualifiers.
510 ///
511 /// By default, performs semantic analysis when building the array type.
512 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000513 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000514 ArrayType::ArraySizeModifier SizeMod,
515 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000516 unsigned IndexTypeQuals,
517 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000518
Douglas Gregord6ff3322009-08-04 16:50:30 +0000519 /// \brief Build a new incomplete array type given the element type, size
520 /// modifier, and index type qualifiers.
521 ///
522 /// By default, performs semantic analysis when building the array type.
523 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000524 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000525 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000526 unsigned IndexTypeQuals,
527 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000528
Mike Stump11289f42009-09-09 15:08:12 +0000529 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000530 /// size modifier, size expression, and index type qualifiers.
531 ///
532 /// By default, performs semantic analysis when building the array type.
533 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000534 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000535 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000536 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000537 unsigned IndexTypeQuals,
538 SourceRange BracketsRange);
539
Mike Stump11289f42009-09-09 15:08:12 +0000540 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000541 /// size modifier, size expression, and index type qualifiers.
542 ///
543 /// By default, performs semantic analysis when building the array type.
544 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000545 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000546 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000547 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000548 unsigned IndexTypeQuals,
549 SourceRange BracketsRange);
550
551 /// \brief Build a new vector type given the element type and
552 /// number of elements.
553 ///
554 /// By default, performs semantic analysis when building the vector type.
555 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000556 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000557 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000558
Douglas Gregord6ff3322009-08-04 16:50:30 +0000559 /// \brief Build a new extended vector type given the element type and
560 /// number of elements.
561 ///
562 /// By default, performs semantic analysis when building the vector type.
563 /// Subclasses may override this routine to provide different behavior.
564 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
565 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000566
567 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000568 /// given the element type and number of elements.
569 ///
570 /// By default, performs semantic analysis when building the vector type.
571 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000572 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000573 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000574 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000575
Douglas Gregord6ff3322009-08-04 16:50:30 +0000576 /// \brief Build a new function type.
577 ///
578 /// By default, performs semantic analysis when building the function type.
579 /// Subclasses may override this routine to provide different behavior.
580 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000581 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000582 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000583 bool Variadic, unsigned Quals,
584 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000585
John McCall550e0c22009-10-21 00:40:46 +0000586 /// \brief Build a new unprototyped function type.
587 QualType RebuildFunctionNoProtoType(QualType ResultType);
588
John McCallb96ec562009-12-04 22:46:56 +0000589 /// \brief Rebuild an unresolved typename type, given the decl that
590 /// the UnresolvedUsingTypenameDecl was transformed to.
591 QualType RebuildUnresolvedUsingType(Decl *D);
592
Douglas Gregord6ff3322009-08-04 16:50:30 +0000593 /// \brief Build a new typedef type.
594 QualType RebuildTypedefType(TypedefDecl *Typedef) {
595 return SemaRef.Context.getTypeDeclType(Typedef);
596 }
597
598 /// \brief Build a new class/struct/union type.
599 QualType RebuildRecordType(RecordDecl *Record) {
600 return SemaRef.Context.getTypeDeclType(Record);
601 }
602
603 /// \brief Build a new Enum type.
604 QualType RebuildEnumType(EnumDecl *Enum) {
605 return SemaRef.Context.getTypeDeclType(Enum);
606 }
John McCallfcc33b02009-09-05 00:15:47 +0000607
Mike Stump11289f42009-09-09 15:08:12 +0000608 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000609 ///
610 /// By default, performs semantic analysis when building the typeof type.
611 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000612 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000613
Mike Stump11289f42009-09-09 15:08:12 +0000614 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000615 ///
616 /// By default, builds a new TypeOfType with the given underlying type.
617 QualType RebuildTypeOfType(QualType Underlying);
618
Mike Stump11289f42009-09-09 15:08:12 +0000619 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000620 ///
621 /// By default, performs semantic analysis when building the decltype type.
622 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000623 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000624
Douglas Gregord6ff3322009-08-04 16:50:30 +0000625 /// \brief Build a new template specialization type.
626 ///
627 /// By default, performs semantic analysis when building the template
628 /// specialization type. Subclasses may override this routine to provide
629 /// different behavior.
630 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000631 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000632 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000633
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000634 /// \brief Build a new parenthesized type.
635 ///
636 /// By default, builds a new ParenType type from the inner type.
637 /// Subclasses may override this routine to provide different behavior.
638 QualType RebuildParenType(QualType InnerType) {
639 return SemaRef.Context.getParenType(InnerType);
640 }
641
Douglas Gregord6ff3322009-08-04 16:50:30 +0000642 /// \brief Build a new qualified name type.
643 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000644 /// By default, builds a new ElaboratedType type from the keyword,
645 /// the nested-name-specifier and the named type.
646 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000647 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
648 ElaboratedTypeKeyword Keyword,
Abramo Bagnara6150c882010-05-11 21:36:43 +0000649 NestedNameSpecifier *NNS, QualType Named) {
650 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000651 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000652
653 /// \brief Build a new typename type that refers to a template-id.
654 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000655 /// By default, builds a new DependentNameType type from the
656 /// nested-name-specifier and the given type. Subclasses may override
657 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000658 QualType RebuildDependentTemplateSpecializationType(
659 ElaboratedTypeKeyword Keyword,
Douglas Gregora5614c52010-09-08 23:56:00 +0000660 NestedNameSpecifier *Qualifier,
661 SourceRange QualifierRange,
John McCallc392f372010-06-11 00:33:02 +0000662 const IdentifierInfo *Name,
663 SourceLocation NameLoc,
664 const TemplateArgumentListInfo &Args) {
665 // Rebuild the template name.
666 // TODO: avoid TemplateName abstraction
667 TemplateName InstName =
Douglas Gregora5614c52010-09-08 23:56:00 +0000668 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall31f82722010-11-12 08:19:04 +0000669 QualType(), 0);
John McCallc392f372010-06-11 00:33:02 +0000670
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000671 if (InstName.isNull())
672 return QualType();
673
John McCallc392f372010-06-11 00:33:02 +0000674 // If it's still dependent, make a dependent specialization.
675 if (InstName.getAsDependentTemplateName())
676 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregora5614c52010-09-08 23:56:00 +0000677 Keyword, Qualifier, Name, Args);
John McCallc392f372010-06-11 00:33:02 +0000678
679 // Otherwise, make an elaborated type wrapping a non-dependent
680 // specialization.
681 QualType T =
682 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
683 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000684
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000685 // NOTE: NNS is already recorded in template specialization type T.
686 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000687 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000688
689 /// \brief Build a new typename type that refers to an identifier.
690 ///
691 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000692 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000693 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000694 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000695 NestedNameSpecifier *NNS,
696 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000697 SourceLocation KeywordLoc,
698 SourceRange NNSRange,
699 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000700 CXXScopeSpec SS;
701 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000702 SS.setRange(NNSRange);
703
Douglas Gregore677daf2010-03-31 22:19:08 +0000704 if (NNS->isDependent()) {
705 // If the name is still dependent, just build a new dependent name type.
706 if (!SemaRef.computeDeclContext(SS))
707 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
708 }
709
Abramo Bagnara6150c882010-05-11 21:36:43 +0000710 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000711 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
712 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000713
714 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
715
Abramo Bagnarad7548482010-05-19 21:37:53 +0000716 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000717 // into a non-dependent elaborated-type-specifier. Find the tag we're
718 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000719 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000720 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
721 if (!DC)
722 return QualType();
723
John McCallbf8c5192010-05-27 06:40:31 +0000724 if (SemaRef.RequireCompleteDeclContext(SS, DC))
725 return QualType();
726
Douglas Gregore677daf2010-03-31 22:19:08 +0000727 TagDecl *Tag = 0;
728 SemaRef.LookupQualifiedName(Result, DC);
729 switch (Result.getResultKind()) {
730 case LookupResult::NotFound:
731 case LookupResult::NotFoundInCurrentInstantiation:
732 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000733
Douglas Gregore677daf2010-03-31 22:19:08 +0000734 case LookupResult::Found:
735 Tag = Result.getAsSingle<TagDecl>();
736 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000737
Douglas Gregore677daf2010-03-31 22:19:08 +0000738 case LookupResult::FoundOverloaded:
739 case LookupResult::FoundUnresolvedValue:
740 llvm_unreachable("Tag lookup cannot find non-tags");
741 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000742
Douglas Gregore677daf2010-03-31 22:19:08 +0000743 case LookupResult::Ambiguous:
744 // Let the LookupResult structure handle ambiguities.
745 return QualType();
746 }
747
748 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000749 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000750 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000751 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000752 return QualType();
753 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000754
Abramo Bagnarad7548482010-05-19 21:37:53 +0000755 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
756 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000757 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
758 return QualType();
759 }
760
761 // Build the elaborated-type-specifier type.
762 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000763 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000764 }
Mike Stump11289f42009-09-09 15:08:12 +0000765
Douglas Gregor1135c352009-08-06 05:28:30 +0000766 /// \brief Build a new nested-name-specifier given the prefix and an
767 /// identifier that names the next step in the nested-name-specifier.
768 ///
769 /// By default, performs semantic analysis when building the new
770 /// nested-name-specifier. Subclasses may override this routine to provide
771 /// different behavior.
772 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
773 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000774 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000775 QualType ObjectType,
776 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000777
778 /// \brief Build a new nested-name-specifier given the prefix and the
779 /// namespace named in the next step in the nested-name-specifier.
780 ///
781 /// By default, performs semantic analysis when building the new
782 /// nested-name-specifier. Subclasses may override this routine to provide
783 /// different behavior.
784 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
785 SourceRange Range,
786 NamespaceDecl *NS);
787
788 /// \brief Build a new nested-name-specifier given the prefix and the
789 /// type named in the next step in the nested-name-specifier.
790 ///
791 /// By default, performs semantic analysis when building the new
792 /// nested-name-specifier. Subclasses may override this routine to provide
793 /// different behavior.
794 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
795 SourceRange Range,
796 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000797 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000798
799 /// \brief Build a new template name given a nested name specifier, a flag
800 /// indicating whether the "template" keyword was provided, and the template
801 /// that the template name refers to.
802 ///
803 /// By default, builds the new template name directly. Subclasses may override
804 /// this routine to provide different behavior.
805 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
806 bool TemplateKW,
807 TemplateDecl *Template);
808
Douglas Gregor71dc5092009-08-06 06:41:21 +0000809 /// \brief Build a new template name given a nested name specifier and the
810 /// name that is referred to as a template.
811 ///
812 /// By default, performs semantic analysis to determine whether the name can
813 /// be resolved to a specific template, then builds the appropriate kind of
814 /// template name. Subclasses may override this routine to provide different
815 /// behavior.
816 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +0000817 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +0000818 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +0000819 QualType ObjectType,
820 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000821
Douglas Gregor71395fa2009-11-04 00:56:37 +0000822 /// \brief Build a new template name given a nested name specifier and the
823 /// overloaded operator name that is referred to as a template.
824 ///
825 /// By default, performs semantic analysis to determine whether the name can
826 /// be resolved to a specific template, then builds the appropriate kind of
827 /// template name. Subclasses may override this routine to provide different
828 /// behavior.
829 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
830 OverloadedOperatorKind Operator,
831 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000832
Douglas Gregorebe10102009-08-20 07:17:43 +0000833 /// \brief Build a new compound statement.
834 ///
835 /// By default, performs semantic analysis to build the new statement.
836 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000837 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000838 MultiStmtArg Statements,
839 SourceLocation RBraceLoc,
840 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000841 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000842 IsStmtExpr);
843 }
844
845 /// \brief Build a new case statement.
846 ///
847 /// By default, performs semantic analysis to build the new statement.
848 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000849 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000850 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000851 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000852 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000853 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000854 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000855 ColonLoc);
856 }
Mike Stump11289f42009-09-09 15:08:12 +0000857
Douglas Gregorebe10102009-08-20 07:17:43 +0000858 /// \brief Attach the body to a new case statement.
859 ///
860 /// By default, performs semantic analysis to build the new statement.
861 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000862 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000863 getSema().ActOnCaseStmtBody(S, Body);
864 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000865 }
Mike Stump11289f42009-09-09 15:08:12 +0000866
Douglas Gregorebe10102009-08-20 07:17:43 +0000867 /// \brief Build a new default statement.
868 ///
869 /// By default, performs semantic analysis to build the new statement.
870 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000871 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000872 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000873 Stmt *SubStmt) {
874 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000875 /*CurScope=*/0);
876 }
Mike Stump11289f42009-09-09 15:08:12 +0000877
Douglas Gregorebe10102009-08-20 07:17:43 +0000878 /// \brief Build a new label statement.
879 ///
880 /// By default, performs semantic analysis to build the new statement.
881 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000882 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000883 IdentifierInfo *Id,
884 SourceLocation ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +0000885 Stmt *SubStmt, bool HasUnusedAttr) {
886 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
887 HasUnusedAttr);
Douglas Gregorebe10102009-08-20 07:17:43 +0000888 }
Mike Stump11289f42009-09-09 15:08:12 +0000889
Douglas Gregorebe10102009-08-20 07:17:43 +0000890 /// \brief Build a new "if" statement.
891 ///
892 /// By default, performs semantic analysis to build the new statement.
893 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000894 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000895 VarDecl *CondVar, Stmt *Then,
John McCallb268a282010-08-23 23:25:46 +0000896 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000897 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +0000898 }
Mike Stump11289f42009-09-09 15:08:12 +0000899
Douglas Gregorebe10102009-08-20 07:17:43 +0000900 /// \brief Start building a new switch statement.
901 ///
902 /// By default, performs semantic analysis to build the new statement.
903 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000904 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000905 Expr *Cond, VarDecl *CondVar) {
906 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +0000907 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +0000908 }
Mike Stump11289f42009-09-09 15:08:12 +0000909
Douglas Gregorebe10102009-08-20 07:17:43 +0000910 /// \brief Attach the body to the switch statement.
911 ///
912 /// By default, performs semantic analysis to build the new statement.
913 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000914 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000915 Stmt *Switch, Stmt *Body) {
916 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000917 }
918
919 /// \brief Build a new while statement.
920 ///
921 /// By default, performs semantic analysis to build the new statement.
922 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000923 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000924 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000925 VarDecl *CondVar,
John McCallb268a282010-08-23 23:25:46 +0000926 Stmt *Body) {
927 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000928 }
Mike Stump11289f42009-09-09 15:08:12 +0000929
Douglas Gregorebe10102009-08-20 07:17:43 +0000930 /// \brief Build a new do-while statement.
931 ///
932 /// By default, performs semantic analysis to build the new statement.
933 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000934 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregorebe10102009-08-20 07:17:43 +0000935 SourceLocation WhileLoc,
936 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000937 Expr *Cond,
Douglas Gregorebe10102009-08-20 07:17:43 +0000938 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +0000939 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
940 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +0000941 }
942
943 /// \brief Build a new for statement.
944 ///
945 /// By default, performs semantic analysis to build the new statement.
946 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000947 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000948 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000949 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000950 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCallb268a282010-08-23 23:25:46 +0000951 SourceLocation RParenLoc, Stmt *Body) {
952 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCall48871652010-08-21 09:40:31 +0000953 CondVar,
John McCallb268a282010-08-23 23:25:46 +0000954 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000955 }
Mike Stump11289f42009-09-09 15:08:12 +0000956
Douglas Gregorebe10102009-08-20 07:17:43 +0000957 /// \brief Build a new goto statement.
958 ///
959 /// By default, performs semantic analysis to build the new statement.
960 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000961 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000962 SourceLocation LabelLoc,
963 LabelStmt *Label) {
964 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
965 }
966
967 /// \brief Build a new indirect goto statement.
968 ///
969 /// By default, performs semantic analysis to build the new statement.
970 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000971 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000972 SourceLocation StarLoc,
John McCallb268a282010-08-23 23:25:46 +0000973 Expr *Target) {
974 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +0000975 }
Mike Stump11289f42009-09-09 15:08:12 +0000976
Douglas Gregorebe10102009-08-20 07:17:43 +0000977 /// \brief Build a new return statement.
978 ///
979 /// By default, performs semantic analysis to build the new statement.
980 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000981 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCallb268a282010-08-23 23:25:46 +0000982 Expr *Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000983
John McCallb268a282010-08-23 23:25:46 +0000984 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +0000985 }
Mike Stump11289f42009-09-09 15:08:12 +0000986
Douglas Gregorebe10102009-08-20 07:17:43 +0000987 /// \brief Build a new declaration statement.
988 ///
989 /// By default, performs semantic analysis to build the new statement.
990 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000991 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000992 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000993 SourceLocation EndLoc) {
994 return getSema().Owned(
995 new (getSema().Context) DeclStmt(
996 DeclGroupRef::Create(getSema().Context,
997 Decls, NumDecls),
998 StartLoc, EndLoc));
999 }
Mike Stump11289f42009-09-09 15:08:12 +00001000
Anders Carlssonaaeef072010-01-24 05:50:09 +00001001 /// \brief Build a new inline asm statement.
1002 ///
1003 /// By default, performs semantic analysis to build the new statement.
1004 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001005 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001006 bool IsSimple,
1007 bool IsVolatile,
1008 unsigned NumOutputs,
1009 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001010 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001011 MultiExprArg Constraints,
1012 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001013 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001014 MultiExprArg Clobbers,
1015 SourceLocation RParenLoc,
1016 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001017 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001018 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001019 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001020 RParenLoc, MSAsm);
1021 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001022
1023 /// \brief Build a new Objective-C @try statement.
1024 ///
1025 /// By default, performs semantic analysis to build the new statement.
1026 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001027 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001028 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001029 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001030 Stmt *Finally) {
1031 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1032 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001033 }
1034
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001035 /// \brief Rebuild an Objective-C exception declaration.
1036 ///
1037 /// By default, performs semantic analysis to build the new declaration.
1038 /// Subclasses may override this routine to provide different behavior.
1039 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1040 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001041 return getSema().BuildObjCExceptionDecl(TInfo, T,
1042 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001043 ExceptionDecl->getLocation());
1044 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001045
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001046 /// \brief Build a new Objective-C @catch statement.
1047 ///
1048 /// By default, performs semantic analysis to build the new statement.
1049 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001050 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001051 SourceLocation RParenLoc,
1052 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001053 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001054 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001055 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001056 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001057
Douglas Gregor306de2f2010-04-22 23:59:56 +00001058 /// \brief Build a new Objective-C @finally statement.
1059 ///
1060 /// By default, performs semantic analysis to build the new statement.
1061 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001062 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001063 Stmt *Body) {
1064 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001065 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001066
Douglas Gregor6148de72010-04-22 22:01:21 +00001067 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001068 ///
1069 /// By default, performs semantic analysis to build the new statement.
1070 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001071 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001072 Expr *Operand) {
1073 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001074 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001075
Douglas Gregor6148de72010-04-22 22:01:21 +00001076 /// \brief Build a new Objective-C @synchronized statement.
1077 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001078 /// By default, performs semantic analysis to build the new statement.
1079 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001080 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001081 Expr *Object,
1082 Stmt *Body) {
1083 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1084 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001085 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001086
1087 /// \brief Build a new Objective-C fast enumeration statement.
1088 ///
1089 /// By default, performs semantic analysis to build the new statement.
1090 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001091 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001092 SourceLocation LParenLoc,
1093 Stmt *Element,
1094 Expr *Collection,
1095 SourceLocation RParenLoc,
1096 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001097 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001098 Element,
1099 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001100 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001101 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001102 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001103
Douglas Gregorebe10102009-08-20 07:17:43 +00001104 /// \brief Build a new C++ exception declaration.
1105 ///
1106 /// By default, performs semantic analysis to build the new decaration.
1107 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001108 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001109 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +00001110 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001111 SourceLocation Loc) {
1112 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001113 }
1114
1115 /// \brief Build a new C++ catch statement.
1116 ///
1117 /// By default, performs semantic analysis to build the new statement.
1118 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001119 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001120 VarDecl *ExceptionDecl,
1121 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001122 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1123 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001124 }
Mike Stump11289f42009-09-09 15:08:12 +00001125
Douglas Gregorebe10102009-08-20 07:17:43 +00001126 /// \brief Build a new C++ try statement.
1127 ///
1128 /// By default, performs semantic analysis to build the new statement.
1129 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001130 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001131 Stmt *TryBlock,
1132 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001133 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001134 }
Mike Stump11289f42009-09-09 15:08:12 +00001135
Douglas Gregora16548e2009-08-11 05:31:07 +00001136 /// \brief Build a new expression that references a declaration.
1137 ///
1138 /// By default, performs semantic analysis to build the new expression.
1139 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001140 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001141 LookupResult &R,
1142 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001143 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1144 }
1145
1146
1147 /// \brief Build a new expression that references a declaration.
1148 ///
1149 /// By default, performs semantic analysis to build the new expression.
1150 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001151 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallfaf5fb42010-08-26 23:41:50 +00001152 SourceRange QualifierRange,
1153 ValueDecl *VD,
1154 const DeclarationNameInfo &NameInfo,
1155 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001156 CXXScopeSpec SS;
1157 SS.setScopeRep(Qualifier);
1158 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001159
1160 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001161
1162 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001163 }
Mike Stump11289f42009-09-09 15:08:12 +00001164
Douglas Gregora16548e2009-08-11 05:31:07 +00001165 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001166 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001167 /// By default, performs semantic analysis to build the new expression.
1168 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001169 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001170 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001171 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001172 }
1173
Douglas Gregorad8a3362009-09-04 17:36:40 +00001174 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001175 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001176 /// By default, performs semantic analysis to build the new expression.
1177 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001178 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001179 SourceLocation OperatorLoc,
1180 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001181 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001182 SourceRange QualifierRange,
1183 TypeSourceInfo *ScopeType,
1184 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001185 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001186 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001187
Douglas Gregora16548e2009-08-11 05:31:07 +00001188 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001189 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001190 /// By default, performs semantic analysis to build the new expression.
1191 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001192 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001193 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001194 Expr *SubExpr) {
1195 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001196 }
Mike Stump11289f42009-09-09 15:08:12 +00001197
Douglas Gregor882211c2010-04-28 22:16:22 +00001198 /// \brief Build a new builtin offsetof expression.
1199 ///
1200 /// By default, performs semantic analysis to build the new expression.
1201 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001202 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001203 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001204 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001205 unsigned NumComponents,
1206 SourceLocation RParenLoc) {
1207 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1208 NumComponents, RParenLoc);
1209 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001210
Douglas Gregora16548e2009-08-11 05:31:07 +00001211 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001212 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001213 /// By default, performs semantic analysis to build the new expression.
1214 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001215 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001216 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001217 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001218 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001219 }
1220
Mike Stump11289f42009-09-09 15:08:12 +00001221 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001222 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001223 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001224 /// By default, performs semantic analysis to build the new expression.
1225 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001226 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001227 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001228 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001229 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001230 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001231 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001232
Douglas Gregora16548e2009-08-11 05:31:07 +00001233 return move(Result);
1234 }
Mike Stump11289f42009-09-09 15:08:12 +00001235
Douglas Gregora16548e2009-08-11 05:31:07 +00001236 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001237 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001238 /// By default, performs semantic analysis to build the new expression.
1239 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001240 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001241 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001242 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001243 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001244 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1245 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001246 RBracketLoc);
1247 }
1248
1249 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001250 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001251 /// By default, performs semantic analysis to build the new expression.
1252 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001253 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001254 MultiExprArg Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00001255 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001256 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregorce5aa332010-09-09 16:33:13 +00001257 move(Args), RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001258 }
1259
1260 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001261 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001262 /// By default, performs semantic analysis to build the new expression.
1263 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001264 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001265 bool isArrow,
1266 NestedNameSpecifier *Qualifier,
1267 SourceRange QualifierRange,
1268 const DeclarationNameInfo &MemberNameInfo,
1269 ValueDecl *Member,
1270 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001271 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001272 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001273 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001274 // We have a reference to an unnamed field. This is always the
1275 // base of an anonymous struct/union member access, i.e. the
1276 // field is always of record type.
Anders Carlsson5da84842009-09-01 04:26:58 +00001277 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001278 assert(Member->getType()->isRecordType() &&
1279 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001280
John McCallb268a282010-08-23 23:25:46 +00001281 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001282 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001283 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001284
John McCall7decc9e2010-11-18 06:31:45 +00001285 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001286 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001287 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001288 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001289 cast<FieldDecl>(Member)->getType(),
1290 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001291 return getSema().Owned(ME);
1292 }
Mike Stump11289f42009-09-09 15:08:12 +00001293
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001294 CXXScopeSpec SS;
1295 if (Qualifier) {
1296 SS.setRange(QualifierRange);
1297 SS.setScopeRep(Qualifier);
1298 }
1299
John McCallb268a282010-08-23 23:25:46 +00001300 getSema().DefaultFunctionArrayConversion(Base);
1301 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001302
John McCall16df1e52010-03-30 21:47:33 +00001303 // FIXME: this involves duplicating earlier analysis in a lot of
1304 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001305 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001306 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001307 R.resolveKind();
1308
John McCallb268a282010-08-23 23:25:46 +00001309 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001310 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001311 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001312 }
Mike Stump11289f42009-09-09 15:08:12 +00001313
Douglas Gregora16548e2009-08-11 05:31:07 +00001314 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001315 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001316 /// By default, performs semantic analysis to build the new expression.
1317 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001318 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001319 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001320 Expr *LHS, Expr *RHS) {
1321 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001322 }
1323
1324 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001325 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001326 /// By default, performs semantic analysis to build the new expression.
1327 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001328 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregora16548e2009-08-11 05:31:07 +00001329 SourceLocation QuestionLoc,
John McCallb268a282010-08-23 23:25:46 +00001330 Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001331 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001332 Expr *RHS) {
1333 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1334 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001335 }
1336
Douglas Gregora16548e2009-08-11 05:31:07 +00001337 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001338 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001339 /// By default, performs semantic analysis to build the new expression.
1340 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001341 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001342 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001343 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001344 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001345 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001346 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001347 }
Mike Stump11289f42009-09-09 15:08:12 +00001348
Douglas Gregora16548e2009-08-11 05:31:07 +00001349 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001350 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001351 /// By default, performs semantic analysis to build the new expression.
1352 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001353 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001354 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001356 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001357 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001358 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001359 }
Mike Stump11289f42009-09-09 15:08:12 +00001360
Douglas Gregora16548e2009-08-11 05:31:07 +00001361 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001362 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001363 /// By default, performs semantic analysis to build the new expression.
1364 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001365 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001366 SourceLocation OpLoc,
1367 SourceLocation AccessorLoc,
1368 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001369
John McCall10eae182009-11-30 22:42:35 +00001370 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001371 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001372 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001373 OpLoc, /*IsArrow*/ false,
1374 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001375 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001376 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001377 }
Mike Stump11289f42009-09-09 15:08:12 +00001378
Douglas Gregora16548e2009-08-11 05:31:07 +00001379 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001380 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001381 /// By default, performs semantic analysis to build the new expression.
1382 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001383 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001384 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001385 SourceLocation RBraceLoc,
1386 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001387 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001388 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1389 if (Result.isInvalid() || ResultTy->isDependentType())
1390 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001391
Douglas Gregord3d93062009-11-09 17:16:50 +00001392 // Patch in the result type we were given, which may have been computed
1393 // when the initial InitListExpr was built.
1394 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1395 ILE->setType(ResultTy);
1396 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001397 }
Mike Stump11289f42009-09-09 15:08:12 +00001398
Douglas Gregora16548e2009-08-11 05:31:07 +00001399 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001400 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001401 /// By default, performs semantic analysis to build the new expression.
1402 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001403 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001404 MultiExprArg ArrayExprs,
1405 SourceLocation EqualOrColonLoc,
1406 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001407 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001408 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001410 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001411 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001412 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001413
Douglas Gregora16548e2009-08-11 05:31:07 +00001414 ArrayExprs.release();
1415 return move(Result);
1416 }
Mike Stump11289f42009-09-09 15:08:12 +00001417
Douglas Gregora16548e2009-08-11 05:31:07 +00001418 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001419 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001420 /// By default, builds the implicit value initialization without performing
1421 /// any semantic analysis. Subclasses may override this routine to provide
1422 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001423 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001424 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1425 }
Mike Stump11289f42009-09-09 15:08:12 +00001426
Douglas Gregora16548e2009-08-11 05:31:07 +00001427 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001428 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001429 /// By default, performs semantic analysis to build the new expression.
1430 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001431 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001432 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001433 SourceLocation RParenLoc) {
1434 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001435 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001436 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001437 }
1438
1439 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001440 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001441 /// By default, performs semantic analysis to build the new expression.
1442 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001443 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001444 MultiExprArg SubExprs,
1445 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001446 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001447 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001448 }
Mike Stump11289f42009-09-09 15:08:12 +00001449
Douglas Gregora16548e2009-08-11 05:31:07 +00001450 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001451 ///
1452 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001453 /// rather than attempting to map the label statement itself.
1454 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001455 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001456 SourceLocation LabelLoc,
1457 LabelStmt *Label) {
1458 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1459 }
Mike Stump11289f42009-09-09 15:08:12 +00001460
Douglas Gregora16548e2009-08-11 05:31:07 +00001461 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001462 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001463 /// By default, performs semantic analysis to build the new expression.
1464 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001465 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001466 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001467 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001468 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001469 }
Mike Stump11289f42009-09-09 15:08:12 +00001470
Douglas Gregora16548e2009-08-11 05:31:07 +00001471 /// \brief Build a new __builtin_choose_expr expression.
1472 ///
1473 /// By default, performs semantic analysis to build the new expression.
1474 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001475 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001476 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001477 SourceLocation RParenLoc) {
1478 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001479 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001480 RParenLoc);
1481 }
Mike Stump11289f42009-09-09 15:08:12 +00001482
Douglas Gregora16548e2009-08-11 05:31:07 +00001483 /// \brief Build a new overloaded operator call expression.
1484 ///
1485 /// By default, performs semantic analysis to build the new expression.
1486 /// The semantic analysis provides the behavior of template instantiation,
1487 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001488 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001489 /// argument-dependent lookup, etc. Subclasses may override this routine to
1490 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001491 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001493 Expr *Callee,
1494 Expr *First,
1495 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001496
1497 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001498 /// reinterpret_cast.
1499 ///
1500 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001501 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001502 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001503 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 Stmt::StmtClass Class,
1505 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001506 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001507 SourceLocation RAngleLoc,
1508 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001509 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001510 SourceLocation RParenLoc) {
1511 switch (Class) {
1512 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001513 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001514 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001515 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001516
1517 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001518 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001519 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001520 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001521
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001523 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001524 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001525 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001526 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001527
Douglas Gregora16548e2009-08-11 05:31:07 +00001528 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001529 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001530 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001531 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001532
Douglas Gregora16548e2009-08-11 05:31:07 +00001533 default:
1534 assert(false && "Invalid C++ named cast");
1535 break;
1536 }
Mike Stump11289f42009-09-09 15:08:12 +00001537
John McCallfaf5fb42010-08-26 23:41:50 +00001538 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001539 }
Mike Stump11289f42009-09-09 15:08:12 +00001540
Douglas Gregora16548e2009-08-11 05:31:07 +00001541 /// \brief Build a new C++ static_cast expression.
1542 ///
1543 /// By default, performs semantic analysis to build the new expression.
1544 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001545 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001546 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001547 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001548 SourceLocation RAngleLoc,
1549 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001550 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001551 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001552 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001553 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001554 SourceRange(LAngleLoc, RAngleLoc),
1555 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001556 }
1557
1558 /// \brief Build a new C++ dynamic_cast expression.
1559 ///
1560 /// By default, performs semantic analysis to build the new expression.
1561 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001562 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001563 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001564 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001565 SourceLocation RAngleLoc,
1566 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001567 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001568 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001569 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001570 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001571 SourceRange(LAngleLoc, RAngleLoc),
1572 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001573 }
1574
1575 /// \brief Build a new C++ reinterpret_cast expression.
1576 ///
1577 /// By default, performs semantic analysis to build the new expression.
1578 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001579 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001580 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001581 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001582 SourceLocation RAngleLoc,
1583 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001584 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001585 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001586 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001587 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001588 SourceRange(LAngleLoc, RAngleLoc),
1589 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001590 }
1591
1592 /// \brief Build a new C++ const_cast expression.
1593 ///
1594 /// By default, performs semantic analysis to build the new expression.
1595 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001596 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001597 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001598 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001599 SourceLocation RAngleLoc,
1600 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001601 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001602 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001603 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001604 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001605 SourceRange(LAngleLoc, RAngleLoc),
1606 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001607 }
Mike Stump11289f42009-09-09 15:08:12 +00001608
Douglas Gregora16548e2009-08-11 05:31:07 +00001609 /// \brief Build a new C++ functional-style cast expression.
1610 ///
1611 /// By default, performs semantic analysis to build the new expression.
1612 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001613 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1614 SourceLocation LParenLoc,
1615 Expr *Sub,
1616 SourceLocation RParenLoc) {
1617 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001618 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001619 RParenLoc);
1620 }
Mike Stump11289f42009-09-09 15:08:12 +00001621
Douglas Gregora16548e2009-08-11 05:31:07 +00001622 /// \brief Build a new C++ typeid(type) expression.
1623 ///
1624 /// By default, performs semantic analysis to build the new expression.
1625 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001626 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001627 SourceLocation TypeidLoc,
1628 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001629 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001630 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001631 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 }
Mike Stump11289f42009-09-09 15:08:12 +00001633
Francois Pichet9f4f2072010-09-08 12:20:18 +00001634
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 /// \brief Build a new C++ typeid(expr) expression.
1636 ///
1637 /// By default, performs semantic analysis to build the new expression.
1638 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001639 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001640 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001641 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001642 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001643 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001644 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001645 }
1646
Francois Pichet9f4f2072010-09-08 12:20:18 +00001647 /// \brief Build a new C++ __uuidof(type) expression.
1648 ///
1649 /// By default, performs semantic analysis to build the new expression.
1650 /// Subclasses may override this routine to provide different behavior.
1651 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1652 SourceLocation TypeidLoc,
1653 TypeSourceInfo *Operand,
1654 SourceLocation RParenLoc) {
1655 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1656 RParenLoc);
1657 }
1658
1659 /// \brief Build a new C++ __uuidof(expr) expression.
1660 ///
1661 /// By default, performs semantic analysis to build the new expression.
1662 /// Subclasses may override this routine to provide different behavior.
1663 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1664 SourceLocation TypeidLoc,
1665 Expr *Operand,
1666 SourceLocation RParenLoc) {
1667 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1668 RParenLoc);
1669 }
1670
Douglas Gregora16548e2009-08-11 05:31:07 +00001671 /// \brief Build a new C++ "this" expression.
1672 ///
1673 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001674 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001675 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001676 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001677 QualType ThisType,
1678 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001679 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001680 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1681 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001682 }
1683
1684 /// \brief Build a new C++ throw expression.
1685 ///
1686 /// By default, performs semantic analysis to build the new expression.
1687 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001688 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001689 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001690 }
1691
1692 /// \brief Build a new C++ default-argument expression.
1693 ///
1694 /// By default, builds a new default-argument expression, which does not
1695 /// require any semantic analysis. Subclasses may override this routine to
1696 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001697 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001698 ParmVarDecl *Param) {
1699 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1700 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001701 }
1702
1703 /// \brief Build a new C++ zero-initialization expression.
1704 ///
1705 /// By default, performs semantic analysis to build the new expression.
1706 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001707 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1708 SourceLocation LParenLoc,
1709 SourceLocation RParenLoc) {
1710 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001711 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001712 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001713 }
Mike Stump11289f42009-09-09 15:08:12 +00001714
Douglas Gregora16548e2009-08-11 05:31:07 +00001715 /// \brief Build a new C++ "new" expression.
1716 ///
1717 /// By default, performs semantic analysis to build the new expression.
1718 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001719 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001720 bool UseGlobal,
1721 SourceLocation PlacementLParen,
1722 MultiExprArg PlacementArgs,
1723 SourceLocation PlacementRParen,
1724 SourceRange TypeIdParens,
1725 QualType AllocatedType,
1726 TypeSourceInfo *AllocatedTypeInfo,
1727 Expr *ArraySize,
1728 SourceLocation ConstructorLParen,
1729 MultiExprArg ConstructorArgs,
1730 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001731 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001732 PlacementLParen,
1733 move(PlacementArgs),
1734 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001735 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001736 AllocatedType,
1737 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001738 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001739 ConstructorLParen,
1740 move(ConstructorArgs),
1741 ConstructorRParen);
1742 }
Mike Stump11289f42009-09-09 15:08:12 +00001743
Douglas Gregora16548e2009-08-11 05:31:07 +00001744 /// \brief Build a new C++ "delete" expression.
1745 ///
1746 /// By default, performs semantic analysis to build the new expression.
1747 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001748 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001749 bool IsGlobalDelete,
1750 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001751 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001752 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001753 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001754 }
Mike Stump11289f42009-09-09 15:08:12 +00001755
Douglas Gregora16548e2009-08-11 05:31:07 +00001756 /// \brief Build a new unary type trait expression.
1757 ///
1758 /// By default, performs semantic analysis to build the new expression.
1759 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001760 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001761 SourceLocation StartLoc,
1762 TypeSourceInfo *T,
1763 SourceLocation RParenLoc) {
1764 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001765 }
1766
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001767 /// \brief Build a new binary type trait expression.
1768 ///
1769 /// By default, performs semantic analysis to build the new expression.
1770 /// Subclasses may override this routine to provide different behavior.
1771 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1772 SourceLocation StartLoc,
1773 TypeSourceInfo *LhsT,
1774 TypeSourceInfo *RhsT,
1775 SourceLocation RParenLoc) {
1776 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1777 }
1778
Mike Stump11289f42009-09-09 15:08:12 +00001779 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001780 /// expression.
1781 ///
1782 /// By default, performs semantic analysis to build the new expression.
1783 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001784 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001785 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001786 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001787 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001788 CXXScopeSpec SS;
1789 SS.setRange(QualifierRange);
1790 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001791
1792 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001793 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001794 *TemplateArgs);
1795
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001796 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001797 }
1798
1799 /// \brief Build a new template-id expression.
1800 ///
1801 /// By default, performs semantic analysis to build the new expression.
1802 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001803 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001804 LookupResult &R,
1805 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001806 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001807 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001808 }
1809
1810 /// \brief Build a new object-construction expression.
1811 ///
1812 /// By default, performs semantic analysis to build the new expression.
1813 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001814 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001815 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001816 CXXConstructorDecl *Constructor,
1817 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001818 MultiExprArg Args,
1819 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001820 CXXConstructExpr::ConstructionKind ConstructKind,
1821 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001822 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001823 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001824 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001825 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001826
Douglas Gregordb121ba2009-12-14 16:27:04 +00001827 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001828 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001829 RequiresZeroInit, ConstructKind,
1830 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001831 }
1832
1833 /// \brief Build a new object-construction expression.
1834 ///
1835 /// By default, performs semantic analysis to build the new expression.
1836 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001837 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1838 SourceLocation LParenLoc,
1839 MultiExprArg Args,
1840 SourceLocation RParenLoc) {
1841 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001842 LParenLoc,
1843 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001844 RParenLoc);
1845 }
1846
1847 /// \brief Build a new object-construction expression.
1848 ///
1849 /// By default, performs semantic analysis to build the new expression.
1850 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001851 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1852 SourceLocation LParenLoc,
1853 MultiExprArg Args,
1854 SourceLocation RParenLoc) {
1855 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001856 LParenLoc,
1857 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001858 RParenLoc);
1859 }
Mike Stump11289f42009-09-09 15:08:12 +00001860
Douglas Gregora16548e2009-08-11 05:31:07 +00001861 /// \brief Build a new member reference expression.
1862 ///
1863 /// By default, performs semantic analysis to build the new expression.
1864 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001865 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001866 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001867 bool IsArrow,
1868 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001869 NestedNameSpecifier *Qualifier,
1870 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001871 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001872 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001873 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001874 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001875 SS.setRange(QualifierRange);
1876 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001877
John McCallb268a282010-08-23 23:25:46 +00001878 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001879 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001880 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001881 MemberNameInfo,
1882 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001883 }
1884
John McCall10eae182009-11-30 22:42:35 +00001885 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001886 ///
1887 /// By default, performs semantic analysis to build the new expression.
1888 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001889 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001890 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001891 SourceLocation OperatorLoc,
1892 bool IsArrow,
1893 NestedNameSpecifier *Qualifier,
1894 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001895 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001896 LookupResult &R,
1897 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001898 CXXScopeSpec SS;
1899 SS.setRange(QualifierRange);
1900 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001901
John McCallb268a282010-08-23 23:25:46 +00001902 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001903 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001904 SS, FirstQualifierInScope,
1905 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001906 }
Mike Stump11289f42009-09-09 15:08:12 +00001907
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001908 /// \brief Build a new noexcept expression.
1909 ///
1910 /// By default, performs semantic analysis to build the new expression.
1911 /// Subclasses may override this routine to provide different behavior.
1912 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1913 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1914 }
1915
Douglas Gregora16548e2009-08-11 05:31:07 +00001916 /// \brief Build a new Objective-C @encode expression.
1917 ///
1918 /// By default, performs semantic analysis to build the new expression.
1919 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001920 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001921 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001922 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001923 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001924 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001925 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001926
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001927 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00001928 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001929 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00001930 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001931 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001932 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001933 MultiExprArg Args,
1934 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001935 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1936 ReceiverTypeInfo->getType(),
1937 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00001938 Sel, Method, LBracLoc, SelectorLoc,
1939 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001940 }
1941
1942 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00001943 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001944 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00001945 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001946 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001947 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001948 MultiExprArg Args,
1949 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00001950 return SemaRef.BuildInstanceMessage(Receiver,
1951 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001952 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00001953 Sel, Method, LBracLoc, SelectorLoc,
1954 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001955 }
1956
Douglas Gregord51d90d2010-04-26 20:11:03 +00001957 /// \brief Build a new Objective-C ivar reference expression.
1958 ///
1959 /// By default, performs semantic analysis to build the new expression.
1960 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001961 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001962 SourceLocation IvarLoc,
1963 bool IsArrow, bool IsFreeIvar) {
1964 // FIXME: We lose track of the IsFreeIvar bit.
1965 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001966 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001967 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1968 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001969 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001970 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00001971 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00001972 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001973 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001974 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001975
Douglas Gregord51d90d2010-04-26 20:11:03 +00001976 if (Result.get())
1977 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001978
John McCallb268a282010-08-23 23:25:46 +00001979 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001980 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001981 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001982 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001983 /*TemplateArgs=*/0);
1984 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001985
1986 /// \brief Build a new Objective-C property reference expression.
1987 ///
1988 /// By default, performs semantic analysis to build the new expression.
1989 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001990 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001991 ObjCPropertyDecl *Property,
1992 SourceLocation PropertyLoc) {
1993 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001994 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00001995 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1996 Sema::LookupMemberName);
1997 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00001998 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00001999 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002000 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00002001 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002002 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002003
Douglas Gregor9faee212010-04-26 20:47:02 +00002004 if (Result.get())
2005 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002006
John McCallb268a282010-08-23 23:25:46 +00002007 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002008 /*FIXME:*/PropertyLoc, IsArrow,
2009 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002010 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002011 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002012 /*TemplateArgs=*/0);
2013 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002014
John McCallb7bd14f2010-12-02 01:19:52 +00002015 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002016 ///
2017 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002018 /// Subclasses may override this routine to provide different behavior.
2019 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2020 ObjCMethodDecl *Getter,
2021 ObjCMethodDecl *Setter,
2022 SourceLocation PropertyLoc) {
2023 // Since these expressions can only be value-dependent, we do not
2024 // need to perform semantic analysis again.
2025 return Owned(
2026 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2027 VK_LValue, OK_ObjCProperty,
2028 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002029 }
2030
Douglas Gregord51d90d2010-04-26 20:11:03 +00002031 /// \brief Build a new Objective-C "isa" 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 RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002036 bool IsArrow) {
2037 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002038 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002039 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2040 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002041 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002042 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002043 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002044 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002045 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002046
Douglas Gregord51d90d2010-04-26 20:11:03 +00002047 if (Result.get())
2048 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002049
John McCallb268a282010-08-23 23:25:46 +00002050 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002051 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002052 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002053 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002054 /*TemplateArgs=*/0);
2055 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002056
Douglas Gregora16548e2009-08-11 05:31:07 +00002057 /// \brief Build a new shuffle vector expression.
2058 ///
2059 /// By default, performs semantic analysis to build the new expression.
2060 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002061 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002062 MultiExprArg SubExprs,
2063 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002064 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002065 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002066 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2067 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2068 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2069 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002070
Douglas Gregora16548e2009-08-11 05:31:07 +00002071 // Build a reference to the __builtin_shufflevector builtin
2072 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00002073 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00002074 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00002075 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002076 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002077
2078 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002079 unsigned NumSubExprs = SubExprs.size();
2080 Expr **Subs = (Expr **)SubExprs.release();
2081 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2082 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002083 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002084 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002085 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002086 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002087
Douglas Gregora16548e2009-08-11 05:31:07 +00002088 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002089 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002090 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002091 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002092
Douglas Gregora16548e2009-08-11 05:31:07 +00002093 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002094 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002095 }
John McCall31f82722010-11-12 08:19:04 +00002096
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002097 /// \brief Build a new template argument pack expansion.
2098 ///
2099 /// By default, performs semantic analysis to build a new pack expansion
2100 /// for a template argument. Subclasses may override this routine to provide
2101 /// different behavior.
2102 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
2103 SourceLocation EllipsisLoc) {
2104 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002105 case TemplateArgument::Expression: {
2106 ExprResult Result
2107 = getSema().ActOnPackExpansion(Pattern.getSourceExpression(),
2108 EllipsisLoc);
2109 if (Result.isInvalid())
2110 return TemplateArgumentLoc();
2111
2112 return TemplateArgumentLoc(Result.get(), Result.get());
2113 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002114
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002115 case TemplateArgument::Template:
Douglas Gregor98318c22011-01-03 21:37:45 +00002116 llvm_unreachable("Unsupported pack expansion of templates");
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002117
2118 case TemplateArgument::Null:
2119 case TemplateArgument::Integral:
2120 case TemplateArgument::Declaration:
2121 case TemplateArgument::Pack:
2122 llvm_unreachable("Pack expansion pattern has no parameter packs");
2123
2124 case TemplateArgument::Type:
2125 if (TypeSourceInfo *Expansion
2126 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
2127 EllipsisLoc))
2128 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2129 Expansion);
2130 break;
2131 }
2132
2133 return TemplateArgumentLoc();
2134 }
2135
Douglas Gregor968f23a2011-01-03 19:31:53 +00002136 /// \brief Build a new expression pack expansion.
2137 ///
2138 /// By default, performs semantic analysis to build a new pack expansion
2139 /// for an expression. Subclasses may override this routine to provide
2140 /// different behavior.
2141 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc) {
2142 return getSema().ActOnPackExpansion(Pattern, EllipsisLoc);
2143 }
2144
John McCall31f82722010-11-12 08:19:04 +00002145private:
2146 QualType TransformTypeInObjectScope(QualType T,
2147 QualType ObjectType,
2148 NamedDecl *FirstQualifierInScope,
2149 NestedNameSpecifier *Prefix);
2150
2151 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2152 QualType ObjectType,
2153 NamedDecl *FirstQualifierInScope,
2154 NestedNameSpecifier *Prefix);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002155};
Douglas Gregora16548e2009-08-11 05:31:07 +00002156
Douglas Gregorebe10102009-08-20 07:17:43 +00002157template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002158StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002159 if (!S)
2160 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002161
Douglas Gregorebe10102009-08-20 07:17:43 +00002162 switch (S->getStmtClass()) {
2163 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002164
Douglas Gregorebe10102009-08-20 07:17:43 +00002165 // Transform individual statement nodes
2166#define STMT(Node, Parent) \
2167 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2168#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002169#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002170
Douglas Gregorebe10102009-08-20 07:17:43 +00002171 // Transform expressions by calling TransformExpr.
2172#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002173#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002174#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002175#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002176 {
John McCalldadc5752010-08-24 06:29:42 +00002177 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002178 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002179 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002180
John McCallb268a282010-08-23 23:25:46 +00002181 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002182 }
Mike Stump11289f42009-09-09 15:08:12 +00002183 }
2184
John McCallc3007a22010-10-26 07:05:15 +00002185 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002186}
Mike Stump11289f42009-09-09 15:08:12 +00002187
2188
Douglas Gregore922c772009-08-04 22:27:00 +00002189template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002190ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002191 if (!E)
2192 return SemaRef.Owned(E);
2193
2194 switch (E->getStmtClass()) {
2195 case Stmt::NoStmtClass: break;
2196#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002197#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002198#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002199 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002200#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002201 }
2202
John McCallc3007a22010-10-26 07:05:15 +00002203 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002204}
2205
2206template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002207bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2208 unsigned NumInputs,
2209 bool IsCall,
2210 llvm::SmallVectorImpl<Expr *> &Outputs,
2211 bool *ArgChanged) {
2212 for (unsigned I = 0; I != NumInputs; ++I) {
2213 // If requested, drop call arguments that need to be dropped.
2214 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2215 if (ArgChanged)
2216 *ArgChanged = true;
2217
2218 break;
2219 }
2220
Douglas Gregor968f23a2011-01-03 19:31:53 +00002221 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2222 Expr *Pattern = Expansion->getPattern();
2223
2224 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2225 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2226 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2227
2228 // Determine whether the set of unexpanded parameter packs can and should
2229 // be expanded.
2230 bool Expand = true;
2231 unsigned NumExpansions = 0;
2232 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2233 Pattern->getSourceRange(),
2234 Unexpanded.data(),
2235 Unexpanded.size(),
2236 Expand, NumExpansions))
2237 return true;
2238
2239 if (!Expand) {
2240 // The transform has determined that we should perform a simple
2241 // transformation on the pack expansion, producing another pack
2242 // expansion.
2243 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2244 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2245 if (OutPattern.isInvalid())
2246 return true;
2247
2248 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
2249 Expansion->getEllipsisLoc());
2250 if (Out.isInvalid())
2251 return true;
2252
2253 if (ArgChanged)
2254 *ArgChanged = true;
2255 Outputs.push_back(Out.get());
2256 continue;
2257 }
2258
2259 // The transform has determined that we should perform an elementwise
2260 // expansion of the pattern. Do so.
2261 for (unsigned I = 0; I != NumExpansions; ++I) {
2262 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2263 ExprResult Out = getDerived().TransformExpr(Pattern);
2264 if (Out.isInvalid())
2265 return true;
2266
2267 if (ArgChanged)
2268 *ArgChanged = true;
2269 Outputs.push_back(Out.get());
2270 }
2271
2272 continue;
2273 }
2274
Douglas Gregora3efea12011-01-03 19:04:46 +00002275 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2276 if (Result.isInvalid())
2277 return true;
2278
2279 if (Result.get() != Inputs[I] && ArgChanged)
2280 *ArgChanged = true;
2281
2282 Outputs.push_back(Result.get());
2283 }
2284
2285 return false;
2286}
2287
2288template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002289NestedNameSpecifier *
2290TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002291 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002292 QualType ObjectType,
2293 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002294 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002295
Douglas Gregorebe10102009-08-20 07:17:43 +00002296 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002297 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002298 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002299 ObjectType,
2300 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002301 if (!Prefix)
2302 return 0;
2303 }
Mike Stump11289f42009-09-09 15:08:12 +00002304
Douglas Gregor1135c352009-08-06 05:28:30 +00002305 switch (NNS->getKind()) {
2306 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002307 if (Prefix) {
2308 // The object type and qualifier-in-scope really apply to the
2309 // leftmost entity.
2310 ObjectType = QualType();
2311 FirstQualifierInScope = 0;
2312 }
2313
Mike Stump11289f42009-09-09 15:08:12 +00002314 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002315 "Identifier nested-name-specifier with no prefix or object type");
2316 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2317 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002318 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002319
2320 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002321 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002322 ObjectType,
2323 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002324
Douglas Gregor1135c352009-08-06 05:28:30 +00002325 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002326 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002327 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002328 getDerived().TransformDecl(Range.getBegin(),
2329 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002330 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002331 Prefix == NNS->getPrefix() &&
2332 NS == NNS->getAsNamespace())
2333 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002334
Douglas Gregor1135c352009-08-06 05:28:30 +00002335 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2336 }
Mike Stump11289f42009-09-09 15:08:12 +00002337
Douglas Gregor1135c352009-08-06 05:28:30 +00002338 case NestedNameSpecifier::Global:
2339 // There is no meaningful transformation that one could perform on the
2340 // global scope.
2341 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002342
Douglas Gregor1135c352009-08-06 05:28:30 +00002343 case NestedNameSpecifier::TypeSpecWithTemplate:
2344 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002345 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002346 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2347 ObjectType,
2348 FirstQualifierInScope,
2349 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002350 if (T.isNull())
2351 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002352
Douglas Gregor1135c352009-08-06 05:28:30 +00002353 if (!getDerived().AlwaysRebuild() &&
2354 Prefix == NNS->getPrefix() &&
2355 T == QualType(NNS->getAsType(), 0))
2356 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002357
2358 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2359 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002360 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002361 }
2362 }
Mike Stump11289f42009-09-09 15:08:12 +00002363
Douglas Gregor1135c352009-08-06 05:28:30 +00002364 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002365 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002366}
2367
2368template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002369DeclarationNameInfo
2370TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002371::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002372 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002373 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002374 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002375
2376 switch (Name.getNameKind()) {
2377 case DeclarationName::Identifier:
2378 case DeclarationName::ObjCZeroArgSelector:
2379 case DeclarationName::ObjCOneArgSelector:
2380 case DeclarationName::ObjCMultiArgSelector:
2381 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002382 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002383 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002384 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002385
Douglas Gregorf816bd72009-09-03 22:13:48 +00002386 case DeclarationName::CXXConstructorName:
2387 case DeclarationName::CXXDestructorName:
2388 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002389 TypeSourceInfo *NewTInfo;
2390 CanQualType NewCanTy;
2391 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002392 NewTInfo = getDerived().TransformType(OldTInfo);
2393 if (!NewTInfo)
2394 return DeclarationNameInfo();
2395 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002396 }
2397 else {
2398 NewTInfo = 0;
2399 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002400 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002401 if (NewT.isNull())
2402 return DeclarationNameInfo();
2403 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2404 }
Mike Stump11289f42009-09-09 15:08:12 +00002405
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002406 DeclarationName NewName
2407 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2408 NewCanTy);
2409 DeclarationNameInfo NewNameInfo(NameInfo);
2410 NewNameInfo.setName(NewName);
2411 NewNameInfo.setNamedTypeInfo(NewTInfo);
2412 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002413 }
Mike Stump11289f42009-09-09 15:08:12 +00002414 }
2415
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002416 assert(0 && "Unknown name kind.");
2417 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002418}
2419
2420template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002421TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002422TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002423 QualType ObjectType,
2424 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002425 SourceLocation Loc = getDerived().getBaseLocation();
2426
Douglas Gregor71dc5092009-08-06 06:41:21 +00002427 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002428 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002429 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002430 /*FIXME*/ SourceRange(Loc),
2431 ObjectType,
2432 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002433 if (!NNS)
2434 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002435
Douglas Gregor71dc5092009-08-06 06:41:21 +00002436 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002437 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002438 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002439 if (!TransTemplate)
2440 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002441
Douglas Gregor71dc5092009-08-06 06:41:21 +00002442 if (!getDerived().AlwaysRebuild() &&
2443 NNS == QTN->getQualifier() &&
2444 TransTemplate == Template)
2445 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002446
Douglas Gregor71dc5092009-08-06 06:41:21 +00002447 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2448 TransTemplate);
2449 }
Mike Stump11289f42009-09-09 15:08:12 +00002450
John McCalle66edc12009-11-24 19:00:30 +00002451 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002452 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002453 }
Mike Stump11289f42009-09-09 15:08:12 +00002454
Douglas Gregor71dc5092009-08-06 06:41:21 +00002455 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002456 NestedNameSpecifier *NNS = DTN->getQualifier();
2457 if (NNS) {
2458 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2459 /*FIXME:*/SourceRange(Loc),
2460 ObjectType,
2461 FirstQualifierInScope);
2462 if (!NNS) return TemplateName();
2463
2464 // These apply to the scope specifier, not the template.
2465 ObjectType = QualType();
2466 FirstQualifierInScope = 0;
2467 }
Mike Stump11289f42009-09-09 15:08:12 +00002468
Douglas Gregor71dc5092009-08-06 06:41:21 +00002469 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002470 NNS == DTN->getQualifier() &&
2471 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002472 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002473
Douglas Gregora5614c52010-09-08 23:56:00 +00002474 if (DTN->isIdentifier()) {
2475 // FIXME: Bad range
2476 SourceRange QualifierRange(getDerived().getBaseLocation());
2477 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2478 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002479 ObjectType,
2480 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002481 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002482
2483 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002484 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002485 }
Mike Stump11289f42009-09-09 15:08:12 +00002486
Douglas Gregor71dc5092009-08-06 06:41:21 +00002487 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002488 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002489 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002490 if (!TransTemplate)
2491 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002492
Douglas Gregor71dc5092009-08-06 06:41:21 +00002493 if (!getDerived().AlwaysRebuild() &&
2494 TransTemplate == Template)
2495 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002496
Douglas Gregor71dc5092009-08-06 06:41:21 +00002497 return TemplateName(TransTemplate);
2498 }
Mike Stump11289f42009-09-09 15:08:12 +00002499
John McCalle66edc12009-11-24 19:00:30 +00002500 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002501 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002502 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002503}
2504
2505template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002506void TreeTransform<Derived>::InventTemplateArgumentLoc(
2507 const TemplateArgument &Arg,
2508 TemplateArgumentLoc &Output) {
2509 SourceLocation Loc = getDerived().getBaseLocation();
2510 switch (Arg.getKind()) {
2511 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002512 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002513 break;
2514
2515 case TemplateArgument::Type:
2516 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002517 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002518
John McCall0ad16662009-10-29 08:12:44 +00002519 break;
2520
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002521 case TemplateArgument::Template:
2522 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2523 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002524
John McCall0ad16662009-10-29 08:12:44 +00002525 case TemplateArgument::Expression:
2526 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2527 break;
2528
2529 case TemplateArgument::Declaration:
2530 case TemplateArgument::Integral:
2531 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002532 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002533 break;
2534 }
2535}
2536
2537template<typename Derived>
2538bool TreeTransform<Derived>::TransformTemplateArgument(
2539 const TemplateArgumentLoc &Input,
2540 TemplateArgumentLoc &Output) {
2541 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002542 switch (Arg.getKind()) {
2543 case TemplateArgument::Null:
2544 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002545 Output = Input;
2546 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002547
Douglas Gregore922c772009-08-04 22:27:00 +00002548 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002549 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002550 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002551 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002552
2553 DI = getDerived().TransformType(DI);
2554 if (!DI) return true;
2555
2556 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2557 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002558 }
Mike Stump11289f42009-09-09 15:08:12 +00002559
Douglas Gregore922c772009-08-04 22:27:00 +00002560 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002561 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002562 DeclarationName Name;
2563 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2564 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002565 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002566 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002567 if (!D) return true;
2568
John McCall0d07eb32009-10-29 18:45:58 +00002569 Expr *SourceExpr = Input.getSourceDeclExpression();
2570 if (SourceExpr) {
2571 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002572 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002573 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002574 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002575 }
2576
2577 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002578 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002579 }
Mike Stump11289f42009-09-09 15:08:12 +00002580
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002581 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002582 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002583 TemplateName Template
2584 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2585 if (Template.isNull())
2586 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002587
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002588 Output = TemplateArgumentLoc(TemplateArgument(Template),
2589 Input.getTemplateQualifierRange(),
2590 Input.getTemplateNameLoc());
2591 return false;
2592 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002593
Douglas Gregore922c772009-08-04 22:27:00 +00002594 case TemplateArgument::Expression: {
2595 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002596 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002597 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002598
John McCall0ad16662009-10-29 08:12:44 +00002599 Expr *InputExpr = Input.getSourceExpression();
2600 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2601
John McCalldadc5752010-08-24 06:29:42 +00002602 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002603 = getDerived().TransformExpr(InputExpr);
2604 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002605 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002606 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002607 }
Mike Stump11289f42009-09-09 15:08:12 +00002608
Douglas Gregore922c772009-08-04 22:27:00 +00002609 case TemplateArgument::Pack: {
2610 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2611 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002612 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002613 AEnd = Arg.pack_end();
2614 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002615
John McCall0ad16662009-10-29 08:12:44 +00002616 // FIXME: preserve source information here when we start
2617 // caring about parameter packs.
2618
John McCall0d07eb32009-10-29 18:45:58 +00002619 TemplateArgumentLoc InputArg;
2620 TemplateArgumentLoc OutputArg;
2621 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2622 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002623 return true;
2624
John McCall0d07eb32009-10-29 18:45:58 +00002625 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002626 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002627
2628 TemplateArgument *TransformedArgsPtr
2629 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2630 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2631 TransformedArgsPtr);
2632 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2633 TransformedArgs.size()),
2634 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002635 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002636 }
2637 }
Mike Stump11289f42009-09-09 15:08:12 +00002638
Douglas Gregore922c772009-08-04 22:27:00 +00002639 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002640 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002641}
2642
Douglas Gregorfe921a72010-12-20 23:36:19 +00002643/// \brief Iterator adaptor that invents template argument location information
2644/// for each of the template arguments in its underlying iterator.
2645template<typename Derived, typename InputIterator>
2646class TemplateArgumentLocInventIterator {
2647 TreeTransform<Derived> &Self;
2648 InputIterator Iter;
2649
2650public:
2651 typedef TemplateArgumentLoc value_type;
2652 typedef TemplateArgumentLoc reference;
2653 typedef typename std::iterator_traits<InputIterator>::difference_type
2654 difference_type;
2655 typedef std::input_iterator_tag iterator_category;
2656
2657 class pointer {
2658 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002659
Douglas Gregorfe921a72010-12-20 23:36:19 +00002660 public:
2661 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2662
2663 const TemplateArgumentLoc *operator->() const { return &Arg; }
2664 };
2665
2666 TemplateArgumentLocInventIterator() { }
2667
2668 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2669 InputIterator Iter)
2670 : Self(Self), Iter(Iter) { }
2671
2672 TemplateArgumentLocInventIterator &operator++() {
2673 ++Iter;
2674 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002675 }
2676
Douglas Gregorfe921a72010-12-20 23:36:19 +00002677 TemplateArgumentLocInventIterator operator++(int) {
2678 TemplateArgumentLocInventIterator Old(*this);
2679 ++(*this);
2680 return Old;
2681 }
2682
2683 reference operator*() const {
2684 TemplateArgumentLoc Result;
2685 Self.InventTemplateArgumentLoc(*Iter, Result);
2686 return Result;
2687 }
2688
2689 pointer operator->() const { return pointer(**this); }
2690
2691 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2692 const TemplateArgumentLocInventIterator &Y) {
2693 return X.Iter == Y.Iter;
2694 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002695
Douglas Gregorfe921a72010-12-20 23:36:19 +00002696 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2697 const TemplateArgumentLocInventIterator &Y) {
2698 return X.Iter != Y.Iter;
2699 }
2700};
2701
Douglas Gregor42cafa82010-12-20 17:42:22 +00002702template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002703template<typename InputIterator>
2704bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2705 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002706 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002707 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002708 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002709 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002710
2711 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2712 // Unpack argument packs, which we translate them into separate
2713 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002714 // FIXME: We could do much better if we could guarantee that the
2715 // TemplateArgumentLocInfo for the pack expansion would be usable for
2716 // all of the template arguments in the argument pack.
2717 typedef TemplateArgumentLocInventIterator<Derived,
2718 TemplateArgument::pack_iterator>
2719 PackLocIterator;
2720 if (TransformTemplateArguments(PackLocIterator(*this,
2721 In.getArgument().pack_begin()),
2722 PackLocIterator(*this,
2723 In.getArgument().pack_end()),
2724 Outputs))
2725 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002726
2727 continue;
2728 }
2729
2730 if (In.getArgument().isPackExpansion()) {
2731 // We have a pack expansion, for which we will be substituting into
2732 // the pattern.
2733 SourceLocation Ellipsis;
2734 TemplateArgumentLoc Pattern
2735 = In.getPackExpansionPattern(Ellipsis, getSema().Context);
2736
2737 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2738 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2739 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2740
2741 // Determine whether the set of unexpanded parameter packs can and should
2742 // be expanded.
2743 bool Expand = true;
2744 unsigned NumExpansions = 0;
2745 if (getDerived().TryExpandParameterPacks(Ellipsis,
2746 Pattern.getSourceRange(),
2747 Unexpanded.data(),
2748 Unexpanded.size(),
2749 Expand, NumExpansions))
2750 return true;
2751
2752 if (!Expand) {
2753 // The transform has determined that we should perform a simple
2754 // transformation on the pack expansion, producing another pack
2755 // expansion.
2756 TemplateArgumentLoc OutPattern;
2757 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2758 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2759 return true;
2760
2761 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis);
2762 if (Out.getArgument().isNull())
2763 return true;
2764
2765 Outputs.addArgument(Out);
2766 continue;
2767 }
2768
2769 // The transform has determined that we should perform an elementwise
2770 // expansion of the pattern. Do so.
2771 for (unsigned I = 0; I != NumExpansions; ++I) {
2772 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2773
2774 if (getDerived().TransformTemplateArgument(Pattern, Out))
2775 return true;
2776
2777 Outputs.addArgument(Out);
2778 }
2779
2780 continue;
2781 }
2782
2783 // The simple case:
2784 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00002785 return true;
2786
2787 Outputs.addArgument(Out);
2788 }
2789
2790 return false;
2791
2792}
2793
Douglas Gregord6ff3322009-08-04 16:50:30 +00002794//===----------------------------------------------------------------------===//
2795// Type transformation
2796//===----------------------------------------------------------------------===//
2797
2798template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002799QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002800 if (getDerived().AlreadyTransformed(T))
2801 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002802
John McCall550e0c22009-10-21 00:40:46 +00002803 // Temporary workaround. All of these transformations should
2804 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002805 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002806 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002807
John McCall31f82722010-11-12 08:19:04 +00002808 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002809
John McCall550e0c22009-10-21 00:40:46 +00002810 if (!NewDI)
2811 return QualType();
2812
2813 return NewDI->getType();
2814}
2815
2816template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002817TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002818 if (getDerived().AlreadyTransformed(DI->getType()))
2819 return DI;
2820
2821 TypeLocBuilder TLB;
2822
2823 TypeLoc TL = DI->getTypeLoc();
2824 TLB.reserve(TL.getFullDataSize());
2825
John McCall31f82722010-11-12 08:19:04 +00002826 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00002827 if (Result.isNull())
2828 return 0;
2829
John McCallbcd03502009-12-07 02:54:59 +00002830 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002831}
2832
2833template<typename Derived>
2834QualType
John McCall31f82722010-11-12 08:19:04 +00002835TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00002836 switch (T.getTypeLocClass()) {
2837#define ABSTRACT_TYPELOC(CLASS, PARENT)
2838#define TYPELOC(CLASS, PARENT) \
2839 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00002840 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00002841#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002842 }
Mike Stump11289f42009-09-09 15:08:12 +00002843
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002844 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002845 return QualType();
2846}
2847
2848/// FIXME: By default, this routine adds type qualifiers only to types
2849/// that can have qualifiers, and silently suppresses those qualifiers
2850/// that are not permitted (e.g., qualifiers on reference or function
2851/// types). This is the right thing for template instantiation, but
2852/// probably not for other clients.
2853template<typename Derived>
2854QualType
2855TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002856 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002857 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002858
John McCall31f82722010-11-12 08:19:04 +00002859 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00002860 if (Result.isNull())
2861 return QualType();
2862
2863 // Silently suppress qualifiers if the result type can't be qualified.
2864 // FIXME: this is the right thing for template instantiation, but
2865 // probably not for other clients.
2866 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002867 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002868
John McCallcb0f89a2010-06-05 06:41:15 +00002869 if (!Quals.empty()) {
2870 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2871 TLB.push<QualifiedTypeLoc>(Result);
2872 // No location information to preserve.
2873 }
John McCall550e0c22009-10-21 00:40:46 +00002874
2875 return Result;
2876}
2877
John McCall31f82722010-11-12 08:19:04 +00002878/// \brief Transforms a type that was written in a scope specifier,
2879/// given an object type, the results of unqualified lookup, and
2880/// an already-instantiated prefix.
2881///
2882/// The object type is provided iff the scope specifier qualifies the
2883/// member of a dependent member-access expression. The prefix is
2884/// provided iff the the scope specifier in which this appears has a
2885/// prefix.
2886///
2887/// This is private to TreeTransform.
2888template<typename Derived>
2889QualType
2890TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
2891 QualType ObjectType,
2892 NamedDecl *UnqualLookup,
2893 NestedNameSpecifier *Prefix) {
2894 if (getDerived().AlreadyTransformed(T))
2895 return T;
2896
2897 TypeSourceInfo *TSI =
2898 SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
2899
2900 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
2901 UnqualLookup, Prefix);
2902 if (!TSI) return QualType();
2903 return TSI->getType();
2904}
2905
2906template<typename Derived>
2907TypeSourceInfo *
2908TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
2909 QualType ObjectType,
2910 NamedDecl *UnqualLookup,
2911 NestedNameSpecifier *Prefix) {
2912 // TODO: in some cases, we might be some verification to do here.
2913 if (ObjectType.isNull())
2914 return getDerived().TransformType(TSI);
2915
2916 QualType T = TSI->getType();
2917 if (getDerived().AlreadyTransformed(T))
2918 return TSI;
2919
2920 TypeLocBuilder TLB;
2921 QualType Result;
2922
2923 if (isa<TemplateSpecializationType>(T)) {
2924 TemplateSpecializationTypeLoc TL
2925 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2926
2927 TemplateName Template =
2928 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
2929 ObjectType, UnqualLookup);
2930 if (Template.isNull()) return 0;
2931
2932 Result = getDerived()
2933 .TransformTemplateSpecializationType(TLB, TL, Template);
2934 } else if (isa<DependentTemplateSpecializationType>(T)) {
2935 DependentTemplateSpecializationTypeLoc TL
2936 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2937
2938 Result = getDerived()
2939 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
2940 } else {
2941 // Nothing special needs to be done for these.
2942 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
2943 }
2944
2945 if (Result.isNull()) return 0;
2946 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
2947}
2948
John McCall550e0c22009-10-21 00:40:46 +00002949template <class TyLoc> static inline
2950QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2951 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2952 NewT.setNameLoc(T.getNameLoc());
2953 return T.getType();
2954}
2955
John McCall550e0c22009-10-21 00:40:46 +00002956template<typename Derived>
2957QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002958 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002959 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2960 NewT.setBuiltinLoc(T.getBuiltinLoc());
2961 if (T.needsExtraLocalData())
2962 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2963 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002964}
Mike Stump11289f42009-09-09 15:08:12 +00002965
Douglas Gregord6ff3322009-08-04 16:50:30 +00002966template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002967QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002968 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00002969 // FIXME: recurse?
2970 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002971}
Mike Stump11289f42009-09-09 15:08:12 +00002972
Douglas Gregord6ff3322009-08-04 16:50:30 +00002973template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002974QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002975 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002976 QualType PointeeType
2977 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002978 if (PointeeType.isNull())
2979 return QualType();
2980
2981 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002982 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002983 // A dependent pointer type 'T *' has is being transformed such
2984 // that an Objective-C class type is being replaced for 'T'. The
2985 // resulting pointer type is an ObjCObjectPointerType, not a
2986 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002987 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002988
John McCall8b07ec22010-05-15 11:32:37 +00002989 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2990 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002991 return Result;
2992 }
John McCall31f82722010-11-12 08:19:04 +00002993
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002994 if (getDerived().AlwaysRebuild() ||
2995 PointeeType != TL.getPointeeLoc().getType()) {
2996 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2997 if (Result.isNull())
2998 return QualType();
2999 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003000
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003001 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3002 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003003 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003004}
Mike Stump11289f42009-09-09 15:08:12 +00003005
3006template<typename Derived>
3007QualType
John McCall550e0c22009-10-21 00:40:46 +00003008TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003009 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003010 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003011 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3012 if (PointeeType.isNull())
3013 return QualType();
3014
3015 QualType Result = TL.getType();
3016 if (getDerived().AlwaysRebuild() ||
3017 PointeeType != TL.getPointeeLoc().getType()) {
3018 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003019 TL.getSigilLoc());
3020 if (Result.isNull())
3021 return QualType();
3022 }
3023
Douglas Gregor049211a2010-04-22 16:50:51 +00003024 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003025 NewT.setSigilLoc(TL.getSigilLoc());
3026 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003027}
3028
John McCall70dd5f62009-10-30 00:06:24 +00003029/// Transforms a reference type. Note that somewhat paradoxically we
3030/// don't care whether the type itself is an l-value type or an r-value
3031/// type; we only care if the type was *written* as an l-value type
3032/// or an r-value type.
3033template<typename Derived>
3034QualType
3035TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003036 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003037 const ReferenceType *T = TL.getTypePtr();
3038
3039 // Note that this works with the pointee-as-written.
3040 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3041 if (PointeeType.isNull())
3042 return QualType();
3043
3044 QualType Result = TL.getType();
3045 if (getDerived().AlwaysRebuild() ||
3046 PointeeType != T->getPointeeTypeAsWritten()) {
3047 Result = getDerived().RebuildReferenceType(PointeeType,
3048 T->isSpelledAsLValue(),
3049 TL.getSigilLoc());
3050 if (Result.isNull())
3051 return QualType();
3052 }
3053
3054 // r-value references can be rebuilt as l-value references.
3055 ReferenceTypeLoc NewTL;
3056 if (isa<LValueReferenceType>(Result))
3057 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3058 else
3059 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3060 NewTL.setSigilLoc(TL.getSigilLoc());
3061
3062 return Result;
3063}
3064
Mike Stump11289f42009-09-09 15:08:12 +00003065template<typename Derived>
3066QualType
John McCall550e0c22009-10-21 00:40:46 +00003067TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003068 LValueReferenceTypeLoc TL) {
3069 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003070}
3071
Mike Stump11289f42009-09-09 15:08:12 +00003072template<typename Derived>
3073QualType
John McCall550e0c22009-10-21 00:40:46 +00003074TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003075 RValueReferenceTypeLoc TL) {
3076 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003077}
Mike Stump11289f42009-09-09 15:08:12 +00003078
Douglas Gregord6ff3322009-08-04 16:50:30 +00003079template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003080QualType
John McCall550e0c22009-10-21 00:40:46 +00003081TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003082 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003083 MemberPointerType *T = TL.getTypePtr();
3084
3085 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003086 if (PointeeType.isNull())
3087 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003088
John McCall550e0c22009-10-21 00:40:46 +00003089 // TODO: preserve source information for this.
3090 QualType ClassType
3091 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003092 if (ClassType.isNull())
3093 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003094
John McCall550e0c22009-10-21 00:40:46 +00003095 QualType Result = TL.getType();
3096 if (getDerived().AlwaysRebuild() ||
3097 PointeeType != T->getPointeeType() ||
3098 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00003099 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3100 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003101 if (Result.isNull())
3102 return QualType();
3103 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003104
John McCall550e0c22009-10-21 00:40:46 +00003105 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3106 NewTL.setSigilLoc(TL.getSigilLoc());
3107
3108 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003109}
3110
Mike Stump11289f42009-09-09 15:08:12 +00003111template<typename Derived>
3112QualType
John McCall550e0c22009-10-21 00:40:46 +00003113TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003114 ConstantArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003115 ConstantArrayType *T = TL.getTypePtr();
3116 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003117 if (ElementType.isNull())
3118 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003119
John McCall550e0c22009-10-21 00:40:46 +00003120 QualType Result = TL.getType();
3121 if (getDerived().AlwaysRebuild() ||
3122 ElementType != T->getElementType()) {
3123 Result = getDerived().RebuildConstantArrayType(ElementType,
3124 T->getSizeModifier(),
3125 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003126 T->getIndexTypeCVRQualifiers(),
3127 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003128 if (Result.isNull())
3129 return QualType();
3130 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003131
John McCall550e0c22009-10-21 00:40:46 +00003132 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3133 NewTL.setLBracketLoc(TL.getLBracketLoc());
3134 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003135
John McCall550e0c22009-10-21 00:40:46 +00003136 Expr *Size = TL.getSizeExpr();
3137 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003138 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003139 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3140 }
3141 NewTL.setSizeExpr(Size);
3142
3143 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003144}
Mike Stump11289f42009-09-09 15:08:12 +00003145
Douglas Gregord6ff3322009-08-04 16:50:30 +00003146template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003147QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003148 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003149 IncompleteArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003150 IncompleteArrayType *T = TL.getTypePtr();
3151 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003152 if (ElementType.isNull())
3153 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003154
John McCall550e0c22009-10-21 00:40:46 +00003155 QualType Result = TL.getType();
3156 if (getDerived().AlwaysRebuild() ||
3157 ElementType != T->getElementType()) {
3158 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003159 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003160 T->getIndexTypeCVRQualifiers(),
3161 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003162 if (Result.isNull())
3163 return QualType();
3164 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003165
John McCall550e0c22009-10-21 00:40:46 +00003166 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3167 NewTL.setLBracketLoc(TL.getLBracketLoc());
3168 NewTL.setRBracketLoc(TL.getRBracketLoc());
3169 NewTL.setSizeExpr(0);
3170
3171 return Result;
3172}
3173
3174template<typename Derived>
3175QualType
3176TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003177 VariableArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003178 VariableArrayType *T = TL.getTypePtr();
3179 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3180 if (ElementType.isNull())
3181 return QualType();
3182
3183 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003184 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003185
John McCalldadc5752010-08-24 06:29:42 +00003186 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003187 = getDerived().TransformExpr(T->getSizeExpr());
3188 if (SizeResult.isInvalid())
3189 return QualType();
3190
John McCallb268a282010-08-23 23:25:46 +00003191 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003192
3193 QualType Result = TL.getType();
3194 if (getDerived().AlwaysRebuild() ||
3195 ElementType != T->getElementType() ||
3196 Size != T->getSizeExpr()) {
3197 Result = getDerived().RebuildVariableArrayType(ElementType,
3198 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003199 Size,
John McCall550e0c22009-10-21 00:40:46 +00003200 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003201 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003202 if (Result.isNull())
3203 return QualType();
3204 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003205
John McCall550e0c22009-10-21 00:40:46 +00003206 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3207 NewTL.setLBracketLoc(TL.getLBracketLoc());
3208 NewTL.setRBracketLoc(TL.getRBracketLoc());
3209 NewTL.setSizeExpr(Size);
3210
3211 return Result;
3212}
3213
3214template<typename Derived>
3215QualType
3216TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003217 DependentSizedArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003218 DependentSizedArrayType *T = TL.getTypePtr();
3219 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3220 if (ElementType.isNull())
3221 return QualType();
3222
3223 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003224 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003225
John McCalldadc5752010-08-24 06:29:42 +00003226 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003227 = getDerived().TransformExpr(T->getSizeExpr());
3228 if (SizeResult.isInvalid())
3229 return QualType();
3230
3231 Expr *Size = static_cast<Expr*>(SizeResult.get());
3232
3233 QualType Result = TL.getType();
3234 if (getDerived().AlwaysRebuild() ||
3235 ElementType != T->getElementType() ||
3236 Size != T->getSizeExpr()) {
3237 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3238 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003239 Size,
John McCall550e0c22009-10-21 00:40:46 +00003240 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003241 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003242 if (Result.isNull())
3243 return QualType();
3244 }
3245 else SizeResult.take();
3246
3247 // We might have any sort of array type now, but fortunately they
3248 // all have the same location layout.
3249 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3250 NewTL.setLBracketLoc(TL.getLBracketLoc());
3251 NewTL.setRBracketLoc(TL.getRBracketLoc());
3252 NewTL.setSizeExpr(Size);
3253
3254 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003255}
Mike Stump11289f42009-09-09 15:08:12 +00003256
3257template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003258QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003259 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003260 DependentSizedExtVectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003261 DependentSizedExtVectorType *T = TL.getTypePtr();
3262
3263 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003264 QualType ElementType = getDerived().TransformType(T->getElementType());
3265 if (ElementType.isNull())
3266 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003267
Douglas Gregore922c772009-08-04 22:27:00 +00003268 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003269 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003270
John McCalldadc5752010-08-24 06:29:42 +00003271 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003272 if (Size.isInvalid())
3273 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003274
John McCall550e0c22009-10-21 00:40:46 +00003275 QualType Result = TL.getType();
3276 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003277 ElementType != T->getElementType() ||
3278 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003279 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003280 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003281 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003282 if (Result.isNull())
3283 return QualType();
3284 }
John McCall550e0c22009-10-21 00:40:46 +00003285
3286 // Result might be dependent or not.
3287 if (isa<DependentSizedExtVectorType>(Result)) {
3288 DependentSizedExtVectorTypeLoc NewTL
3289 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3290 NewTL.setNameLoc(TL.getNameLoc());
3291 } else {
3292 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3293 NewTL.setNameLoc(TL.getNameLoc());
3294 }
3295
3296 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003297}
Mike Stump11289f42009-09-09 15:08:12 +00003298
3299template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003300QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003301 VectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003302 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003303 QualType ElementType = getDerived().TransformType(T->getElementType());
3304 if (ElementType.isNull())
3305 return QualType();
3306
John McCall550e0c22009-10-21 00:40:46 +00003307 QualType Result = TL.getType();
3308 if (getDerived().AlwaysRebuild() ||
3309 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003310 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003311 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003312 if (Result.isNull())
3313 return QualType();
3314 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003315
John McCall550e0c22009-10-21 00:40:46 +00003316 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3317 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003318
John McCall550e0c22009-10-21 00:40:46 +00003319 return Result;
3320}
3321
3322template<typename Derived>
3323QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003324 ExtVectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003325 VectorType *T = TL.getTypePtr();
3326 QualType ElementType = getDerived().TransformType(T->getElementType());
3327 if (ElementType.isNull())
3328 return QualType();
3329
3330 QualType Result = TL.getType();
3331 if (getDerived().AlwaysRebuild() ||
3332 ElementType != T->getElementType()) {
3333 Result = getDerived().RebuildExtVectorType(ElementType,
3334 T->getNumElements(),
3335 /*FIXME*/ SourceLocation());
3336 if (Result.isNull())
3337 return QualType();
3338 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003339
John McCall550e0c22009-10-21 00:40:46 +00003340 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3341 NewTL.setNameLoc(TL.getNameLoc());
3342
3343 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003344}
Mike Stump11289f42009-09-09 15:08:12 +00003345
3346template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003347ParmVarDecl *
3348TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
3349 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
3350 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
3351 if (!NewDI)
3352 return 0;
3353
3354 if (NewDI == OldDI)
3355 return OldParm;
3356 else
3357 return ParmVarDecl::Create(SemaRef.Context,
3358 OldParm->getDeclContext(),
3359 OldParm->getLocation(),
3360 OldParm->getIdentifier(),
3361 NewDI->getType(),
3362 NewDI,
3363 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003364 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003365 /* DefArg */ NULL);
3366}
3367
3368template<typename Derived>
3369bool TreeTransform<Derived>::
3370 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
3371 llvm::SmallVectorImpl<QualType> &PTypes,
3372 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
3373 FunctionProtoType *T = TL.getTypePtr();
3374
3375 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3376 ParmVarDecl *OldParm = TL.getArg(i);
3377
3378 QualType NewType;
3379 ParmVarDecl *NewParm;
3380
3381 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00003382 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
3383 if (!NewParm)
3384 return true;
3385 NewType = NewParm->getType();
3386
3387 // Deal with the possibility that we don't have a parameter
3388 // declaration for this parameter.
3389 } else {
3390 NewParm = 0;
3391
3392 QualType OldType = T->getArgType(i);
3393 NewType = getDerived().TransformType(OldType);
3394 if (NewType.isNull())
3395 return true;
3396 }
3397
3398 PTypes.push_back(NewType);
3399 PVars.push_back(NewParm);
3400 }
3401
3402 return false;
3403}
3404
3405template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003406QualType
John McCall550e0c22009-10-21 00:40:46 +00003407TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003408 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003409 // Transform the parameters and return type.
3410 //
3411 // We instantiate in source order, with the return type first followed by
3412 // the parameters, because users tend to expect this (even if they shouldn't
3413 // rely on it!).
3414 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003415 // When the function has a trailing return type, we instantiate the
3416 // parameters before the return type, since the return type can then refer
3417 // to the parameters themselves (via decltype, sizeof, etc.).
3418 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003419 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003420 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor14cf7522010-04-30 18:55:50 +00003421 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003422
Douglas Gregor7fb25412010-10-01 18:44:50 +00003423 QualType ResultType;
3424
3425 if (TL.getTrailingReturn()) {
3426 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3427 return QualType();
3428
3429 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3430 if (ResultType.isNull())
3431 return QualType();
3432 }
3433 else {
3434 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3435 if (ResultType.isNull())
3436 return QualType();
3437
3438 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3439 return QualType();
3440 }
3441
John McCall550e0c22009-10-21 00:40:46 +00003442 QualType Result = TL.getType();
3443 if (getDerived().AlwaysRebuild() ||
3444 ResultType != T->getResultType() ||
3445 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3446 Result = getDerived().RebuildFunctionProtoType(ResultType,
3447 ParamTypes.data(),
3448 ParamTypes.size(),
3449 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003450 T->getTypeQuals(),
3451 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003452 if (Result.isNull())
3453 return QualType();
3454 }
Mike Stump11289f42009-09-09 15:08:12 +00003455
John McCall550e0c22009-10-21 00:40:46 +00003456 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3457 NewTL.setLParenLoc(TL.getLParenLoc());
3458 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003459 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003460 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3461 NewTL.setArg(i, ParamDecls[i]);
3462
3463 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003464}
Mike Stump11289f42009-09-09 15:08:12 +00003465
Douglas Gregord6ff3322009-08-04 16:50:30 +00003466template<typename Derived>
3467QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003468 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003469 FunctionNoProtoTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003470 FunctionNoProtoType *T = TL.getTypePtr();
3471 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3472 if (ResultType.isNull())
3473 return QualType();
3474
3475 QualType Result = TL.getType();
3476 if (getDerived().AlwaysRebuild() ||
3477 ResultType != T->getResultType())
3478 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3479
3480 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3481 NewTL.setLParenLoc(TL.getLParenLoc());
3482 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003483 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003484
3485 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003486}
Mike Stump11289f42009-09-09 15:08:12 +00003487
John McCallb96ec562009-12-04 22:46:56 +00003488template<typename Derived> QualType
3489TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003490 UnresolvedUsingTypeLoc TL) {
John McCallb96ec562009-12-04 22:46:56 +00003491 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003492 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003493 if (!D)
3494 return QualType();
3495
3496 QualType Result = TL.getType();
3497 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3498 Result = getDerived().RebuildUnresolvedUsingType(D);
3499 if (Result.isNull())
3500 return QualType();
3501 }
3502
3503 // We might get an arbitrary type spec type back. We should at
3504 // least always get a type spec type, though.
3505 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3506 NewTL.setNameLoc(TL.getNameLoc());
3507
3508 return Result;
3509}
3510
Douglas Gregord6ff3322009-08-04 16:50:30 +00003511template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003512QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003513 TypedefTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003514 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003515 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003516 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3517 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003518 if (!Typedef)
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 Typedef != T->getDecl()) {
3524 Result = getDerived().RebuildTypedefType(Typedef);
3525 if (Result.isNull())
3526 return QualType();
3527 }
Mike Stump11289f42009-09-09 15:08:12 +00003528
John McCall550e0c22009-10-21 00:40:46 +00003529 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3530 NewTL.setNameLoc(TL.getNameLoc());
3531
3532 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003533}
Mike Stump11289f42009-09-09 15:08:12 +00003534
Douglas Gregord6ff3322009-08-04 16:50:30 +00003535template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003536QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003537 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003538 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003539 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003540
John McCalldadc5752010-08-24 06:29:42 +00003541 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003542 if (E.isInvalid())
3543 return QualType();
3544
John McCall550e0c22009-10-21 00:40:46 +00003545 QualType Result = TL.getType();
3546 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003547 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003548 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003549 if (Result.isNull())
3550 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003551 }
John McCall550e0c22009-10-21 00:40:46 +00003552 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003553
John McCall550e0c22009-10-21 00:40:46 +00003554 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003555 NewTL.setTypeofLoc(TL.getTypeofLoc());
3556 NewTL.setLParenLoc(TL.getLParenLoc());
3557 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003558
3559 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003560}
Mike Stump11289f42009-09-09 15:08:12 +00003561
3562template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003563QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003564 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003565 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3566 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3567 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003568 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003569
John McCall550e0c22009-10-21 00:40:46 +00003570 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003571 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3572 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003573 if (Result.isNull())
3574 return QualType();
3575 }
Mike Stump11289f42009-09-09 15:08:12 +00003576
John McCall550e0c22009-10-21 00:40:46 +00003577 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003578 NewTL.setTypeofLoc(TL.getTypeofLoc());
3579 NewTL.setLParenLoc(TL.getLParenLoc());
3580 NewTL.setRParenLoc(TL.getRParenLoc());
3581 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003582
3583 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003584}
Mike Stump11289f42009-09-09 15:08:12 +00003585
3586template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003587QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003588 DecltypeTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003589 DecltypeType *T = TL.getTypePtr();
3590
Douglas Gregore922c772009-08-04 22:27:00 +00003591 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003592 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003593
John McCalldadc5752010-08-24 06:29:42 +00003594 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003595 if (E.isInvalid())
3596 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003597
John McCall550e0c22009-10-21 00:40:46 +00003598 QualType Result = TL.getType();
3599 if (getDerived().AlwaysRebuild() ||
3600 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003601 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003602 if (Result.isNull())
3603 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003604 }
John McCall550e0c22009-10-21 00:40:46 +00003605 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003606
John McCall550e0c22009-10-21 00:40:46 +00003607 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3608 NewTL.setNameLoc(TL.getNameLoc());
3609
3610 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003611}
3612
3613template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003614QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003615 RecordTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003616 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003617 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003618 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3619 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003620 if (!Record)
3621 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003622
John McCall550e0c22009-10-21 00:40:46 +00003623 QualType Result = TL.getType();
3624 if (getDerived().AlwaysRebuild() ||
3625 Record != T->getDecl()) {
3626 Result = getDerived().RebuildRecordType(Record);
3627 if (Result.isNull())
3628 return QualType();
3629 }
Mike Stump11289f42009-09-09 15:08:12 +00003630
John McCall550e0c22009-10-21 00:40:46 +00003631 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3632 NewTL.setNameLoc(TL.getNameLoc());
3633
3634 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003635}
Mike Stump11289f42009-09-09 15:08:12 +00003636
3637template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003638QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003639 EnumTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003640 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003641 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003642 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3643 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003644 if (!Enum)
3645 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003646
John McCall550e0c22009-10-21 00:40:46 +00003647 QualType Result = TL.getType();
3648 if (getDerived().AlwaysRebuild() ||
3649 Enum != T->getDecl()) {
3650 Result = getDerived().RebuildEnumType(Enum);
3651 if (Result.isNull())
3652 return QualType();
3653 }
Mike Stump11289f42009-09-09 15:08:12 +00003654
John McCall550e0c22009-10-21 00:40:46 +00003655 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3656 NewTL.setNameLoc(TL.getNameLoc());
3657
3658 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003659}
John McCallfcc33b02009-09-05 00:15:47 +00003660
John McCalle78aac42010-03-10 03:28:59 +00003661template<typename Derived>
3662QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3663 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003664 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00003665 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3666 TL.getTypePtr()->getDecl());
3667 if (!D) return QualType();
3668
3669 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3670 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3671 return T;
3672}
3673
Mike Stump11289f42009-09-09 15:08:12 +00003674
Douglas Gregord6ff3322009-08-04 16:50:30 +00003675template<typename Derived>
3676QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003677 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003678 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003679 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003680}
3681
Mike Stump11289f42009-09-09 15:08:12 +00003682template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003683QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003684 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003685 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003686 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003687}
3688
3689template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003690QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003691 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003692 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00003693 const TemplateSpecializationType *T = TL.getTypePtr();
3694
Mike Stump11289f42009-09-09 15:08:12 +00003695 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00003696 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003697 if (Template.isNull())
3698 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003699
John McCall31f82722010-11-12 08:19:04 +00003700 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
3701}
3702
Douglas Gregorfe921a72010-12-20 23:36:19 +00003703namespace {
3704 /// \brief Simple iterator that traverses the template arguments in a
3705 /// container that provides a \c getArgLoc() member function.
3706 ///
3707 /// This iterator is intended to be used with the iterator form of
3708 /// \c TreeTransform<Derived>::TransformTemplateArguments().
3709 template<typename ArgLocContainer>
3710 class TemplateArgumentLocContainerIterator {
3711 ArgLocContainer *Container;
3712 unsigned Index;
3713
3714 public:
3715 typedef TemplateArgumentLoc value_type;
3716 typedef TemplateArgumentLoc reference;
3717 typedef int difference_type;
3718 typedef std::input_iterator_tag iterator_category;
3719
3720 class pointer {
3721 TemplateArgumentLoc Arg;
3722
3723 public:
3724 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3725
3726 const TemplateArgumentLoc *operator->() const {
3727 return &Arg;
3728 }
3729 };
3730
3731
3732 TemplateArgumentLocContainerIterator() {}
3733
3734 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
3735 unsigned Index)
3736 : Container(&Container), Index(Index) { }
3737
3738 TemplateArgumentLocContainerIterator &operator++() {
3739 ++Index;
3740 return *this;
3741 }
3742
3743 TemplateArgumentLocContainerIterator operator++(int) {
3744 TemplateArgumentLocContainerIterator Old(*this);
3745 ++(*this);
3746 return Old;
3747 }
3748
3749 TemplateArgumentLoc operator*() const {
3750 return Container->getArgLoc(Index);
3751 }
3752
3753 pointer operator->() const {
3754 return pointer(Container->getArgLoc(Index));
3755 }
3756
3757 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00003758 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003759 return X.Container == Y.Container && X.Index == Y.Index;
3760 }
3761
3762 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00003763 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003764 return !(X == Y);
3765 }
3766 };
3767}
3768
3769
John McCall31f82722010-11-12 08:19:04 +00003770template <typename Derived>
3771QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3772 TypeLocBuilder &TLB,
3773 TemplateSpecializationTypeLoc TL,
3774 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00003775 TemplateArgumentListInfo NewTemplateArgs;
3776 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3777 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00003778 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
3779 ArgIterator;
3780 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
3781 ArgIterator(TL, TL.getNumArgs()),
3782 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003783 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003784
John McCall0ad16662009-10-29 08:12:44 +00003785 // FIXME: maybe don't rebuild if all the template arguments are the same.
3786
3787 QualType Result =
3788 getDerived().RebuildTemplateSpecializationType(Template,
3789 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003790 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003791
3792 if (!Result.isNull()) {
3793 TemplateSpecializationTypeLoc NewTL
3794 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3795 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3796 NewTL.setLAngleLoc(TL.getLAngleLoc());
3797 NewTL.setRAngleLoc(TL.getRAngleLoc());
3798 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3799 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003800 }
Mike Stump11289f42009-09-09 15:08:12 +00003801
John McCall0ad16662009-10-29 08:12:44 +00003802 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003803}
Mike Stump11289f42009-09-09 15:08:12 +00003804
3805template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003806QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003807TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003808 ElaboratedTypeLoc TL) {
Abramo Bagnara6150c882010-05-11 21:36:43 +00003809 ElaboratedType *T = TL.getTypePtr();
3810
3811 NestedNameSpecifier *NNS = 0;
3812 // NOTE: the qualifier in an ElaboratedType is optional.
3813 if (T->getQualifier() != 0) {
3814 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003815 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00003816 if (!NNS)
3817 return QualType();
3818 }
Mike Stump11289f42009-09-09 15:08:12 +00003819
John McCall31f82722010-11-12 08:19:04 +00003820 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3821 if (NamedT.isNull())
3822 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003823
John McCall550e0c22009-10-21 00:40:46 +00003824 QualType Result = TL.getType();
3825 if (getDerived().AlwaysRebuild() ||
3826 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003827 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00003828 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
3829 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003830 if (Result.isNull())
3831 return QualType();
3832 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003833
Abramo Bagnara6150c882010-05-11 21:36:43 +00003834 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003835 NewTL.setKeywordLoc(TL.getKeywordLoc());
3836 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003837
3838 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003839}
Mike Stump11289f42009-09-09 15:08:12 +00003840
3841template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00003842QualType
3843TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
3844 ParenTypeLoc TL) {
3845 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
3846 if (Inner.isNull())
3847 return QualType();
3848
3849 QualType Result = TL.getType();
3850 if (getDerived().AlwaysRebuild() ||
3851 Inner != TL.getInnerLoc().getType()) {
3852 Result = getDerived().RebuildParenType(Inner);
3853 if (Result.isNull())
3854 return QualType();
3855 }
3856
3857 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
3858 NewTL.setLParenLoc(TL.getLParenLoc());
3859 NewTL.setRParenLoc(TL.getRParenLoc());
3860 return Result;
3861}
3862
3863template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003864QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003865 DependentNameTypeLoc TL) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003866 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003867
Douglas Gregord6ff3322009-08-04 16:50:30 +00003868 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003869 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003870 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003871 if (!NNS)
3872 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003873
John McCallc392f372010-06-11 00:33:02 +00003874 QualType Result
3875 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3876 T->getIdentifier(),
3877 TL.getKeywordLoc(),
3878 TL.getQualifierRange(),
3879 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003880 if (Result.isNull())
3881 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003882
Abramo Bagnarad7548482010-05-19 21:37:53 +00003883 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3884 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003885 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3886
Abramo Bagnarad7548482010-05-19 21:37:53 +00003887 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3888 NewTL.setKeywordLoc(TL.getKeywordLoc());
3889 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003890 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003891 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3892 NewTL.setKeywordLoc(TL.getKeywordLoc());
3893 NewTL.setQualifierRange(TL.getQualifierRange());
3894 NewTL.setNameLoc(TL.getNameLoc());
3895 }
John McCall550e0c22009-10-21 00:40:46 +00003896 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003897}
Mike Stump11289f42009-09-09 15:08:12 +00003898
Douglas Gregord6ff3322009-08-04 16:50:30 +00003899template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003900QualType TreeTransform<Derived>::
3901 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003902 DependentTemplateSpecializationTypeLoc TL) {
John McCallc392f372010-06-11 00:33:02 +00003903 DependentTemplateSpecializationType *T = TL.getTypePtr();
3904
3905 NestedNameSpecifier *NNS
3906 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003907 TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003908 if (!NNS)
3909 return QualType();
3910
John McCall31f82722010-11-12 08:19:04 +00003911 return getDerived()
3912 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
3913}
3914
3915template<typename Derived>
3916QualType TreeTransform<Derived>::
3917 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3918 DependentTemplateSpecializationTypeLoc TL,
3919 NestedNameSpecifier *NNS) {
3920 DependentTemplateSpecializationType *T = TL.getTypePtr();
3921
John McCallc392f372010-06-11 00:33:02 +00003922 TemplateArgumentListInfo NewTemplateArgs;
3923 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3924 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00003925
3926 typedef TemplateArgumentLocContainerIterator<
3927 DependentTemplateSpecializationTypeLoc> ArgIterator;
3928 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
3929 ArgIterator(TL, TL.getNumArgs()),
3930 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003931 return QualType();
John McCallc392f372010-06-11 00:33:02 +00003932
Douglas Gregora5614c52010-09-08 23:56:00 +00003933 QualType Result
3934 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
3935 NNS,
3936 TL.getQualifierRange(),
3937 T->getIdentifier(),
3938 TL.getNameLoc(),
3939 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00003940 if (Result.isNull())
3941 return QualType();
3942
3943 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3944 QualType NamedT = ElabT->getNamedType();
3945
3946 // Copy information relevant to the template specialization.
3947 TemplateSpecializationTypeLoc NamedTL
3948 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3949 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3950 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3951 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3952 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3953
3954 // Copy information relevant to the elaborated type.
3955 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3956 NewTL.setKeywordLoc(TL.getKeywordLoc());
3957 NewTL.setQualifierRange(TL.getQualifierRange());
3958 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00003959 TypeLoc NewTL(Result, TL.getOpaqueData());
3960 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00003961 }
3962 return Result;
3963}
3964
3965template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00003966QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
3967 PackExpansionTypeLoc TL) {
3968 // FIXME: Implement!
3969 getSema().Diag(TL.getEllipsisLoc(),
3970 diag::err_pack_expansion_instantiation_unsupported);
3971 return QualType();
3972}
3973
3974template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003975QualType
3976TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003977 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003978 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003979 TLB.pushFullCopy(TL);
3980 return TL.getType();
3981}
3982
3983template<typename Derived>
3984QualType
3985TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003986 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00003987 // ObjCObjectType is never dependent.
3988 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003989 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003990}
Mike Stump11289f42009-09-09 15:08:12 +00003991
3992template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003993QualType
3994TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003995 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003996 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003997 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003998 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003999}
4000
Douglas Gregord6ff3322009-08-04 16:50:30 +00004001//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004002// Statement transformation
4003//===----------------------------------------------------------------------===//
4004template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004005StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004006TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004007 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004008}
4009
4010template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004011StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004012TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4013 return getDerived().TransformCompoundStmt(S, false);
4014}
4015
4016template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004017StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004018TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004019 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004020 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004021 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004022 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004023 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4024 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004025 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004026 if (Result.isInvalid()) {
4027 // Immediately fail if this was a DeclStmt, since it's very
4028 // likely that this will cause problems for future statements.
4029 if (isa<DeclStmt>(*B))
4030 return StmtError();
4031
4032 // Otherwise, just keep processing substatements and fail later.
4033 SubStmtInvalid = true;
4034 continue;
4035 }
Mike Stump11289f42009-09-09 15:08:12 +00004036
Douglas Gregorebe10102009-08-20 07:17:43 +00004037 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4038 Statements.push_back(Result.takeAs<Stmt>());
4039 }
Mike Stump11289f42009-09-09 15:08:12 +00004040
John McCall1ababa62010-08-27 19:56:05 +00004041 if (SubStmtInvalid)
4042 return StmtError();
4043
Douglas Gregorebe10102009-08-20 07:17:43 +00004044 if (!getDerived().AlwaysRebuild() &&
4045 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004046 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004047
4048 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4049 move_arg(Statements),
4050 S->getRBracLoc(),
4051 IsStmtExpr);
4052}
Mike Stump11289f42009-09-09 15:08:12 +00004053
Douglas Gregorebe10102009-08-20 07:17:43 +00004054template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004055StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004056TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004057 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004058 {
4059 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004060 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004061
Eli Friedman06577382009-11-19 03:14:00 +00004062 // Transform the left-hand case value.
4063 LHS = getDerived().TransformExpr(S->getLHS());
4064 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004065 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004066
Eli Friedman06577382009-11-19 03:14:00 +00004067 // Transform the right-hand case value (for the GNU case-range extension).
4068 RHS = getDerived().TransformExpr(S->getRHS());
4069 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004070 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004071 }
Mike Stump11289f42009-09-09 15:08:12 +00004072
Douglas Gregorebe10102009-08-20 07:17:43 +00004073 // Build the case statement.
4074 // Case statements are always rebuilt so that they will attached to their
4075 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004076 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004077 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004078 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004079 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004080 S->getColonLoc());
4081 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004082 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004083
Douglas Gregorebe10102009-08-20 07:17:43 +00004084 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004085 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004086 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004087 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004088
Douglas Gregorebe10102009-08-20 07:17:43 +00004089 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004090 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004091}
4092
4093template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004094StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004095TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004096 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004097 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004098 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004099 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004100
Douglas Gregorebe10102009-08-20 07:17:43 +00004101 // Default statements are always rebuilt
4102 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004103 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004104}
Mike Stump11289f42009-09-09 15:08:12 +00004105
Douglas Gregorebe10102009-08-20 07:17:43 +00004106template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004107StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004108TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004109 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004110 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004111 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004112
Douglas Gregorebe10102009-08-20 07:17:43 +00004113 // FIXME: Pass the real colon location in.
4114 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
4115 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +00004116 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregorebe10102009-08-20 07:17:43 +00004117}
Mike Stump11289f42009-09-09 15:08:12 +00004118
Douglas Gregorebe10102009-08-20 07:17:43 +00004119template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004120StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004121TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004122 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004123 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004124 VarDecl *ConditionVar = 0;
4125 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004126 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004127 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004128 getDerived().TransformDefinition(
4129 S->getConditionVariable()->getLocation(),
4130 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004131 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004132 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004133 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004134 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004135
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004136 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004137 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004138
4139 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004140 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004141 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4142 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004143 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004144 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004145
John McCallb268a282010-08-23 23:25:46 +00004146 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004147 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004148 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004149
John McCallb268a282010-08-23 23:25:46 +00004150 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4151 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004152 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004153
Douglas Gregorebe10102009-08-20 07:17:43 +00004154 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004155 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004156 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004157 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004158
Douglas Gregorebe10102009-08-20 07:17:43 +00004159 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004160 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004161 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004162 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004163
Douglas Gregorebe10102009-08-20 07:17:43 +00004164 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004165 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004166 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004167 Then.get() == S->getThen() &&
4168 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004169 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004170
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004171 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004172 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004173 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004174}
4175
4176template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004177StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004178TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004179 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004180 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004181 VarDecl *ConditionVar = 0;
4182 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004183 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004184 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004185 getDerived().TransformDefinition(
4186 S->getConditionVariable()->getLocation(),
4187 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004188 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004189 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004190 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004191 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004192
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004193 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004194 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004195 }
Mike Stump11289f42009-09-09 15:08:12 +00004196
Douglas Gregorebe10102009-08-20 07:17:43 +00004197 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004198 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004199 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004200 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004201 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004202 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004203
Douglas Gregorebe10102009-08-20 07:17:43 +00004204 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004205 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004206 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004207 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004208
Douglas Gregorebe10102009-08-20 07:17:43 +00004209 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004210 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4211 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004212}
Mike Stump11289f42009-09-09 15:08:12 +00004213
Douglas Gregorebe10102009-08-20 07:17:43 +00004214template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004215StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004216TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004217 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004218 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004219 VarDecl *ConditionVar = 0;
4220 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004221 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004222 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004223 getDerived().TransformDefinition(
4224 S->getConditionVariable()->getLocation(),
4225 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004226 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004227 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004228 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004229 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004230
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004231 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004232 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004233
4234 if (S->getCond()) {
4235 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004236 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4237 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004238 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004239 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004240 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004241 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004242 }
Mike Stump11289f42009-09-09 15:08:12 +00004243
John McCallb268a282010-08-23 23:25:46 +00004244 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4245 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004246 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004247
Douglas Gregorebe10102009-08-20 07:17:43 +00004248 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004249 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004250 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004251 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004252
Douglas Gregorebe10102009-08-20 07:17:43 +00004253 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004254 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004255 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004256 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004257 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004258
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004259 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004260 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004261}
Mike Stump11289f42009-09-09 15:08:12 +00004262
Douglas Gregorebe10102009-08-20 07:17:43 +00004263template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004264StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004265TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004266 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004267 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004268 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004269 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004270
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004271 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004272 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004273 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004274 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004275
Douglas Gregorebe10102009-08-20 07:17:43 +00004276 if (!getDerived().AlwaysRebuild() &&
4277 Cond.get() == S->getCond() &&
4278 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004279 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004280
John McCallb268a282010-08-23 23:25:46 +00004281 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4282 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004283 S->getRParenLoc());
4284}
Mike Stump11289f42009-09-09 15:08:12 +00004285
Douglas Gregorebe10102009-08-20 07:17:43 +00004286template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004287StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004288TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004289 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004290 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004291 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004292 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004293
Douglas Gregorebe10102009-08-20 07:17:43 +00004294 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004295 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004296 VarDecl *ConditionVar = 0;
4297 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004298 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004299 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004300 getDerived().TransformDefinition(
4301 S->getConditionVariable()->getLocation(),
4302 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004303 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004304 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004305 } else {
4306 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004307
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004308 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004309 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004310
4311 if (S->getCond()) {
4312 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004313 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4314 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004315 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004316 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004317
John McCallb268a282010-08-23 23:25:46 +00004318 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004319 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004320 }
Mike Stump11289f42009-09-09 15:08:12 +00004321
John McCallb268a282010-08-23 23:25:46 +00004322 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4323 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004324 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004325
Douglas Gregorebe10102009-08-20 07:17:43 +00004326 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00004327 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00004328 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004329 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004330
John McCallb268a282010-08-23 23:25:46 +00004331 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4332 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004333 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004334
Douglas Gregorebe10102009-08-20 07:17:43 +00004335 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004336 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004337 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004338 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004339
Douglas Gregorebe10102009-08-20 07:17:43 +00004340 if (!getDerived().AlwaysRebuild() &&
4341 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00004342 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004343 Inc.get() == S->getInc() &&
4344 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004345 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004346
Douglas Gregorebe10102009-08-20 07:17:43 +00004347 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004348 Init.get(), FullCond, ConditionVar,
4349 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004350}
4351
4352template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004353StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004354TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004355 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00004356 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004357 S->getLabel());
4358}
4359
4360template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004361StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004362TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004363 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00004364 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004365 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004366
Douglas Gregorebe10102009-08-20 07:17:43 +00004367 if (!getDerived().AlwaysRebuild() &&
4368 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00004369 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004370
4371 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00004372 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004373}
4374
4375template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004376StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004377TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004378 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004379}
Mike Stump11289f42009-09-09 15:08:12 +00004380
Douglas Gregorebe10102009-08-20 07:17:43 +00004381template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004382StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004383TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004384 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004385}
Mike Stump11289f42009-09-09 15:08:12 +00004386
Douglas Gregorebe10102009-08-20 07:17:43 +00004387template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004388StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004389TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004390 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00004391 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004392 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004393
Mike Stump11289f42009-09-09 15:08:12 +00004394 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00004395 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00004396 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004397}
Mike Stump11289f42009-09-09 15:08:12 +00004398
Douglas Gregorebe10102009-08-20 07:17:43 +00004399template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004400StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004401TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004402 bool DeclChanged = false;
4403 llvm::SmallVector<Decl *, 4> Decls;
4404 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4405 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00004406 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4407 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00004408 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00004409 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004410
Douglas Gregorebe10102009-08-20 07:17:43 +00004411 if (Transformed != *D)
4412 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00004413
Douglas Gregorebe10102009-08-20 07:17:43 +00004414 Decls.push_back(Transformed);
4415 }
Mike Stump11289f42009-09-09 15:08:12 +00004416
Douglas Gregorebe10102009-08-20 07:17:43 +00004417 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00004418 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004419
4420 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004421 S->getStartLoc(), S->getEndLoc());
4422}
Mike Stump11289f42009-09-09 15:08:12 +00004423
Douglas Gregorebe10102009-08-20 07:17:43 +00004424template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004425StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004426TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004427 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCallc3007a22010-10-26 07:05:15 +00004428 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004429}
4430
4431template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004432StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004433TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004434
John McCall37ad5512010-08-23 06:44:23 +00004435 ASTOwningVector<Expr*> Constraints(getSema());
4436 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00004437 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00004438
John McCalldadc5752010-08-24 06:29:42 +00004439 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00004440 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004441
4442 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004443
Anders Carlssonaaeef072010-01-24 05:50:09 +00004444 // Go through the outputs.
4445 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004446 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004447
Anders Carlssonaaeef072010-01-24 05:50:09 +00004448 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004449 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004450
Anders Carlssonaaeef072010-01-24 05:50:09 +00004451 // Transform the output expr.
4452 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004453 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004454 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004455 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004456
Anders Carlssonaaeef072010-01-24 05:50:09 +00004457 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004458
John McCallb268a282010-08-23 23:25:46 +00004459 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004460 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004461
Anders Carlssonaaeef072010-01-24 05:50:09 +00004462 // Go through the inputs.
4463 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004464 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004465
Anders Carlssonaaeef072010-01-24 05:50:09 +00004466 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004467 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004468
Anders Carlssonaaeef072010-01-24 05:50:09 +00004469 // Transform the input expr.
4470 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004471 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004472 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004473 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004474
Anders Carlssonaaeef072010-01-24 05:50:09 +00004475 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004476
John McCallb268a282010-08-23 23:25:46 +00004477 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004478 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004479
Anders Carlssonaaeef072010-01-24 05:50:09 +00004480 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00004481 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004482
4483 // Go through the clobbers.
4484 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00004485 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00004486
4487 // No need to transform the asm string literal.
4488 AsmString = SemaRef.Owned(S->getAsmString());
4489
4490 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4491 S->isSimple(),
4492 S->isVolatile(),
4493 S->getNumOutputs(),
4494 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00004495 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004496 move_arg(Constraints),
4497 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00004498 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004499 move_arg(Clobbers),
4500 S->getRParenLoc(),
4501 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00004502}
4503
4504
4505template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004506StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004507TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004508 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00004509 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004510 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004511 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004512
Douglas Gregor96c79492010-04-23 22:50:49 +00004513 // Transform the @catch statements (if present).
4514 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004515 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00004516 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004517 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00004518 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004519 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00004520 if (Catch.get() != S->getCatchStmt(I))
4521 AnyCatchChanged = true;
4522 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004523 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004524
Douglas Gregor306de2f2010-04-22 23:59:56 +00004525 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00004526 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00004527 if (S->getFinallyStmt()) {
4528 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4529 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004530 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00004531 }
4532
4533 // If nothing changed, just retain this statement.
4534 if (!getDerived().AlwaysRebuild() &&
4535 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00004536 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00004537 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00004538 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004539
Douglas Gregor306de2f2010-04-22 23:59:56 +00004540 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00004541 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4542 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004543}
Mike Stump11289f42009-09-09 15:08:12 +00004544
Douglas Gregorebe10102009-08-20 07:17:43 +00004545template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004546StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004547TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004548 // Transform the @catch parameter, if there is one.
4549 VarDecl *Var = 0;
4550 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4551 TypeSourceInfo *TSInfo = 0;
4552 if (FromVar->getTypeSourceInfo()) {
4553 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4554 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004555 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004556 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004557
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004558 QualType T;
4559 if (TSInfo)
4560 T = TSInfo->getType();
4561 else {
4562 T = getDerived().TransformType(FromVar->getType());
4563 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004564 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004565 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004566
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004567 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4568 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00004569 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004570 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004571
John McCalldadc5752010-08-24 06:29:42 +00004572 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004573 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004574 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004575
4576 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004577 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004578 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004579}
Mike Stump11289f42009-09-09 15:08:12 +00004580
Douglas Gregorebe10102009-08-20 07:17:43 +00004581template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004582StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004583TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004584 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004585 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004586 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004587 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004588
Douglas Gregor306de2f2010-04-22 23:59:56 +00004589 // If nothing changed, just retain this statement.
4590 if (!getDerived().AlwaysRebuild() &&
4591 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00004592 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00004593
4594 // Build a new statement.
4595 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004596 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004597}
Mike Stump11289f42009-09-09 15:08:12 +00004598
Douglas Gregorebe10102009-08-20 07:17:43 +00004599template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004600StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004601TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004602 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00004603 if (S->getThrowExpr()) {
4604 Operand = getDerived().TransformExpr(S->getThrowExpr());
4605 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004606 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00004607 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004608
Douglas Gregor2900c162010-04-22 21:44:01 +00004609 if (!getDerived().AlwaysRebuild() &&
4610 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00004611 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004612
John McCallb268a282010-08-23 23:25:46 +00004613 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004614}
Mike Stump11289f42009-09-09 15:08:12 +00004615
Douglas Gregorebe10102009-08-20 07:17:43 +00004616template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004617StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004618TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004619 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004620 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00004621 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00004622 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004623 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004624
Douglas Gregor6148de72010-04-22 22:01:21 +00004625 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004626 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00004627 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004628 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004629
Douglas Gregor6148de72010-04-22 22:01:21 +00004630 // If nothing change, just retain the current statement.
4631 if (!getDerived().AlwaysRebuild() &&
4632 Object.get() == S->getSynchExpr() &&
4633 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00004634 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00004635
4636 // Build a new statement.
4637 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00004638 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004639}
4640
4641template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004642StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004643TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004644 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004645 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00004646 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004647 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004648 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004649
Douglas Gregorf68a5082010-04-22 23:10:45 +00004650 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00004651 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004652 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004653 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004654
Douglas Gregorf68a5082010-04-22 23:10:45 +00004655 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004656 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004657 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004658 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004659
Douglas Gregorf68a5082010-04-22 23:10:45 +00004660 // If nothing changed, just retain this statement.
4661 if (!getDerived().AlwaysRebuild() &&
4662 Element.get() == S->getElement() &&
4663 Collection.get() == S->getCollection() &&
4664 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004665 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004666
Douglas Gregorf68a5082010-04-22 23:10:45 +00004667 // Build a new statement.
4668 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4669 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00004670 Element.get(),
4671 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00004672 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004673 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004674}
4675
4676
4677template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004678StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004679TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4680 // Transform the exception declaration, if any.
4681 VarDecl *Var = 0;
4682 if (S->getExceptionDecl()) {
4683 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004684 TypeSourceInfo *T = getDerived().TransformType(
4685 ExceptionDecl->getTypeSourceInfo());
4686 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00004687 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004688
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004689 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00004690 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004691 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00004692 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00004693 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004694 }
Mike Stump11289f42009-09-09 15:08:12 +00004695
Douglas Gregorebe10102009-08-20 07:17:43 +00004696 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00004697 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004698 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004699 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004700
Douglas Gregorebe10102009-08-20 07:17:43 +00004701 if (!getDerived().AlwaysRebuild() &&
4702 !Var &&
4703 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00004704 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004705
4706 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4707 Var,
John McCallb268a282010-08-23 23:25:46 +00004708 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004709}
Mike Stump11289f42009-09-09 15:08:12 +00004710
Douglas Gregorebe10102009-08-20 07:17:43 +00004711template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004712StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004713TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4714 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00004715 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004716 = getDerived().TransformCompoundStmt(S->getTryBlock());
4717 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004718 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004719
Douglas Gregorebe10102009-08-20 07:17:43 +00004720 // Transform the handlers.
4721 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004722 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00004723 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004724 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004725 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4726 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004727 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004728
Douglas Gregorebe10102009-08-20 07:17:43 +00004729 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4730 Handlers.push_back(Handler.takeAs<Stmt>());
4731 }
Mike Stump11289f42009-09-09 15:08:12 +00004732
Douglas Gregorebe10102009-08-20 07:17:43 +00004733 if (!getDerived().AlwaysRebuild() &&
4734 TryBlock.get() == S->getTryBlock() &&
4735 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00004736 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004737
John McCallb268a282010-08-23 23:25:46 +00004738 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00004739 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004740}
Mike Stump11289f42009-09-09 15:08:12 +00004741
Douglas Gregorebe10102009-08-20 07:17:43 +00004742//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004743// Expression transformation
4744//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004745template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004746ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004747TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00004748 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004749}
Mike Stump11289f42009-09-09 15:08:12 +00004750
4751template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004752ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004753TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004754 NestedNameSpecifier *Qualifier = 0;
4755 if (E->getQualifier()) {
4756 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004757 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004758 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00004759 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004760 }
John McCallce546572009-12-08 09:08:17 +00004761
4762 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004763 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4764 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004765 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00004766 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004767
John McCall815039a2010-08-17 21:27:17 +00004768 DeclarationNameInfo NameInfo = E->getNameInfo();
4769 if (NameInfo.getName()) {
4770 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4771 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00004772 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00004773 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004774
4775 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004776 Qualifier == E->getQualifier() &&
4777 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004778 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00004779 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004780
4781 // Mark it referenced in the new context regardless.
4782 // FIXME: this is a bit instantiation-specific.
4783 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4784
John McCallc3007a22010-10-26 07:05:15 +00004785 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004786 }
John McCallce546572009-12-08 09:08:17 +00004787
4788 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00004789 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004790 TemplateArgs = &TransArgs;
4791 TransArgs.setLAngleLoc(E->getLAngleLoc());
4792 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00004793 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
4794 E->getNumTemplateArgs(),
4795 TransArgs))
4796 return ExprError();
John McCallce546572009-12-08 09:08:17 +00004797 }
4798
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004799 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004800 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004801}
Mike Stump11289f42009-09-09 15:08:12 +00004802
Douglas Gregora16548e2009-08-11 05:31:07 +00004803template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004804ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004805TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004806 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004807}
Mike Stump11289f42009-09-09 15:08:12 +00004808
Douglas Gregora16548e2009-08-11 05:31:07 +00004809template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004810ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004811TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004812 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004813}
Mike Stump11289f42009-09-09 15:08:12 +00004814
Douglas Gregora16548e2009-08-11 05:31:07 +00004815template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004816ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004817TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004818 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004819}
Mike Stump11289f42009-09-09 15:08:12 +00004820
Douglas Gregora16548e2009-08-11 05:31:07 +00004821template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004822ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004823TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004824 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004825}
Mike Stump11289f42009-09-09 15:08:12 +00004826
Douglas Gregora16548e2009-08-11 05:31:07 +00004827template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004828ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004829TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004830 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004831}
4832
4833template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004834ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004835TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004836 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004837 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004838 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004839
Douglas Gregora16548e2009-08-11 05:31:07 +00004840 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004841 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004842
John McCallb268a282010-08-23 23:25:46 +00004843 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004844 E->getRParen());
4845}
4846
Mike Stump11289f42009-09-09 15:08:12 +00004847template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004848ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004849TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004850 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004851 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004852 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004853
Douglas Gregora16548e2009-08-11 05:31:07 +00004854 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004855 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004856
Douglas Gregora16548e2009-08-11 05:31:07 +00004857 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4858 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004859 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004860}
Mike Stump11289f42009-09-09 15:08:12 +00004861
Douglas Gregora16548e2009-08-11 05:31:07 +00004862template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004863ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004864TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4865 // Transform the type.
4866 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4867 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00004868 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004869
Douglas Gregor882211c2010-04-28 22:16:22 +00004870 // Transform all of the components into components similar to what the
4871 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004872 // FIXME: It would be slightly more efficient in the non-dependent case to
4873 // just map FieldDecls, rather than requiring the rebuilder to look for
4874 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004875 // template code that we don't care.
4876 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00004877 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00004878 typedef OffsetOfExpr::OffsetOfNode Node;
4879 llvm::SmallVector<Component, 4> Components;
4880 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4881 const Node &ON = E->getComponent(I);
4882 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004883 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004884 Comp.LocStart = ON.getRange().getBegin();
4885 Comp.LocEnd = ON.getRange().getEnd();
4886 switch (ON.getKind()) {
4887 case Node::Array: {
4888 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00004889 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00004890 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004891 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004892
Douglas Gregor882211c2010-04-28 22:16:22 +00004893 ExprChanged = ExprChanged || Index.get() != FromIndex;
4894 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00004895 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00004896 break;
4897 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004898
Douglas Gregor882211c2010-04-28 22:16:22 +00004899 case Node::Field:
4900 case Node::Identifier:
4901 Comp.isBrackets = false;
4902 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004903 if (!Comp.U.IdentInfo)
4904 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004905
Douglas Gregor882211c2010-04-28 22:16:22 +00004906 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004907
Douglas Gregord1702062010-04-29 00:18:15 +00004908 case Node::Base:
4909 // Will be recomputed during the rebuild.
4910 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004911 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004912
Douglas Gregor882211c2010-04-28 22:16:22 +00004913 Components.push_back(Comp);
4914 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004915
Douglas Gregor882211c2010-04-28 22:16:22 +00004916 // If nothing changed, retain the existing expression.
4917 if (!getDerived().AlwaysRebuild() &&
4918 Type == E->getTypeSourceInfo() &&
4919 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00004920 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004921
Douglas Gregor882211c2010-04-28 22:16:22 +00004922 // Build a new offsetof expression.
4923 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4924 Components.data(), Components.size(),
4925 E->getRParenLoc());
4926}
4927
4928template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004929ExprResult
John McCall8d69a212010-11-15 23:31:06 +00004930TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
4931 assert(getDerived().AlreadyTransformed(E->getType()) &&
4932 "opaque value expression requires transformation");
4933 return SemaRef.Owned(E);
4934}
4935
4936template<typename Derived>
4937ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004938TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004939 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004940 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004941
John McCallbcd03502009-12-07 02:54:59 +00004942 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004943 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004944 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004945
John McCall4c98fd82009-11-04 07:28:41 +00004946 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00004947 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004948
John McCall4c98fd82009-11-04 07:28:41 +00004949 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004950 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004951 E->getSourceRange());
4952 }
Mike Stump11289f42009-09-09 15:08:12 +00004953
John McCalldadc5752010-08-24 06:29:42 +00004954 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00004955 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004956 // C++0x [expr.sizeof]p1:
4957 // The operand is either an expression, which is an unevaluated operand
4958 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00004959 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004960
Douglas Gregora16548e2009-08-11 05:31:07 +00004961 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4962 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004963 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004964
Douglas Gregora16548e2009-08-11 05:31:07 +00004965 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00004966 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004967 }
Mike Stump11289f42009-09-09 15:08:12 +00004968
John McCallb268a282010-08-23 23:25:46 +00004969 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004970 E->isSizeOf(),
4971 E->getSourceRange());
4972}
Mike Stump11289f42009-09-09 15:08:12 +00004973
Douglas Gregora16548e2009-08-11 05:31:07 +00004974template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004975ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004976TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004977 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004978 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004979 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004980
John McCalldadc5752010-08-24 06:29:42 +00004981 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004982 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004983 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004984
4985
Douglas Gregora16548e2009-08-11 05:31:07 +00004986 if (!getDerived().AlwaysRebuild() &&
4987 LHS.get() == E->getLHS() &&
4988 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004989 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004990
John McCallb268a282010-08-23 23:25:46 +00004991 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004992 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00004993 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004994 E->getRBracketLoc());
4995}
Mike Stump11289f42009-09-09 15:08:12 +00004996
4997template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004998ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004999TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005000 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005001 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005002 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005003 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005004
5005 // Transform arguments.
5006 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005007 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005008 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5009 &ArgChanged))
5010 return ExprError();
5011
Douglas Gregora16548e2009-08-11 05:31:07 +00005012 if (!getDerived().AlwaysRebuild() &&
5013 Callee.get() == E->getCallee() &&
5014 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005015 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005016
Douglas Gregora16548e2009-08-11 05:31:07 +00005017 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005018 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005019 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005020 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005021 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005022 E->getRParenLoc());
5023}
Mike Stump11289f42009-09-09 15:08:12 +00005024
5025template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005026ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005027TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005028 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005029 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005030 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005031
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005032 NestedNameSpecifier *Qualifier = 0;
5033 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00005034 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005035 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005036 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00005037 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00005038 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005039 }
Mike Stump11289f42009-09-09 15:08:12 +00005040
Eli Friedman2cfcef62009-12-04 06:40:45 +00005041 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005042 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5043 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005044 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005045 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005046
John McCall16df1e52010-03-30 21:47:33 +00005047 NamedDecl *FoundDecl = E->getFoundDecl();
5048 if (FoundDecl == E->getMemberDecl()) {
5049 FoundDecl = Member;
5050 } else {
5051 FoundDecl = cast_or_null<NamedDecl>(
5052 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5053 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005054 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005055 }
5056
Douglas Gregora16548e2009-08-11 05:31:07 +00005057 if (!getDerived().AlwaysRebuild() &&
5058 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005059 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005060 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005061 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005062 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005063
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005064 // Mark it referenced in the new context regardless.
5065 // FIXME: this is a bit instantiation-specific.
5066 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005067 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005068 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005069
John McCall6b51f282009-11-23 01:53:49 +00005070 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005071 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005072 TransArgs.setLAngleLoc(E->getLAngleLoc());
5073 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005074 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5075 E->getNumTemplateArgs(),
5076 TransArgs))
5077 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005078 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005079
Douglas Gregora16548e2009-08-11 05:31:07 +00005080 // FIXME: Bogus source location for the operator
5081 SourceLocation FakeOperatorLoc
5082 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5083
John McCall38836f02010-01-15 08:34:02 +00005084 // FIXME: to do this check properly, we will need to preserve the
5085 // first-qualifier-in-scope here, just in case we had a dependent
5086 // base (and therefore couldn't do the check) and a
5087 // nested-name-qualifier (and therefore could do the lookup).
5088 NamedDecl *FirstQualifierInScope = 0;
5089
John McCallb268a282010-08-23 23:25:46 +00005090 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005091 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005092 Qualifier,
5093 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005094 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005095 Member,
John McCall16df1e52010-03-30 21:47:33 +00005096 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005097 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005098 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005099 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005100}
Mike Stump11289f42009-09-09 15:08:12 +00005101
Douglas Gregora16548e2009-08-11 05:31:07 +00005102template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005103ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005104TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005105 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005106 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005107 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005108
John McCalldadc5752010-08-24 06:29:42 +00005109 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005110 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005111 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005112
Douglas Gregora16548e2009-08-11 05:31:07 +00005113 if (!getDerived().AlwaysRebuild() &&
5114 LHS.get() == E->getLHS() &&
5115 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005116 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005117
Douglas Gregora16548e2009-08-11 05:31:07 +00005118 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005119 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005120}
5121
Mike Stump11289f42009-09-09 15:08:12 +00005122template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005123ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005124TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005125 CompoundAssignOperator *E) {
5126 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005127}
Mike Stump11289f42009-09-09 15:08:12 +00005128
Douglas Gregora16548e2009-08-11 05:31:07 +00005129template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005130ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005131TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005132 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005133 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005134 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005135
John McCalldadc5752010-08-24 06:29:42 +00005136 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005137 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005138 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005139
John McCalldadc5752010-08-24 06:29:42 +00005140 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005141 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005142 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005143
Douglas Gregora16548e2009-08-11 05:31:07 +00005144 if (!getDerived().AlwaysRebuild() &&
5145 Cond.get() == E->getCond() &&
5146 LHS.get() == E->getLHS() &&
5147 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005148 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005149
John McCallb268a282010-08-23 23:25:46 +00005150 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005151 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005152 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005153 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005154 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005155}
Mike Stump11289f42009-09-09 15:08:12 +00005156
5157template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005158ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005159TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005160 // Implicit casts are eliminated during transformation, since they
5161 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005162 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005163}
Mike Stump11289f42009-09-09 15:08:12 +00005164
Douglas Gregora16548e2009-08-11 05:31:07 +00005165template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005166ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005167TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005168 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5169 if (!Type)
5170 return ExprError();
5171
John McCalldadc5752010-08-24 06:29:42 +00005172 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005173 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005174 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005175 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005176
Douglas Gregora16548e2009-08-11 05:31:07 +00005177 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005178 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005179 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005180 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005181
John McCall97513962010-01-15 18:39:57 +00005182 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005183 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005184 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005185 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005186}
Mike Stump11289f42009-09-09 15:08:12 +00005187
Douglas Gregora16548e2009-08-11 05:31:07 +00005188template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005189ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005190TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005191 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5192 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5193 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005194 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005195
John McCalldadc5752010-08-24 06:29:42 +00005196 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005197 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005198 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005199
Douglas Gregora16548e2009-08-11 05:31:07 +00005200 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005201 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005202 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005203 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005204
John McCall5d7aa7f2010-01-19 22:33:45 +00005205 // Note: the expression type doesn't necessarily match the
5206 // type-as-written, but that's okay, because it should always be
5207 // derivable from the initializer.
5208
John McCalle15bbff2010-01-18 19:35:47 +00005209 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005210 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005211 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005212}
Mike Stump11289f42009-09-09 15:08:12 +00005213
Douglas Gregora16548e2009-08-11 05:31:07 +00005214template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005215ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005216TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005217 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005218 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005219 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005220
Douglas Gregora16548e2009-08-11 05:31:07 +00005221 if (!getDerived().AlwaysRebuild() &&
5222 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00005223 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005224
Douglas Gregora16548e2009-08-11 05:31:07 +00005225 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005226 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005227 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005228 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005229 E->getAccessorLoc(),
5230 E->getAccessor());
5231}
Mike Stump11289f42009-09-09 15:08:12 +00005232
Douglas Gregora16548e2009-08-11 05:31:07 +00005233template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005234ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005235TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005236 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005237
John McCall37ad5512010-08-23 06:44:23 +00005238 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005239 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5240 Inits, &InitChanged))
5241 return ExprError();
5242
Douglas Gregora16548e2009-08-11 05:31:07 +00005243 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005244 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005245
Douglas Gregora16548e2009-08-11 05:31:07 +00005246 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005247 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005248}
Mike Stump11289f42009-09-09 15:08:12 +00005249
Douglas Gregora16548e2009-08-11 05:31:07 +00005250template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005251ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005252TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005253 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005254
Douglas Gregorebe10102009-08-20 07:17:43 +00005255 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005256 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005257 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005258 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005259
Douglas Gregorebe10102009-08-20 07:17:43 +00005260 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005261 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005262 bool ExprChanged = false;
5263 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5264 DEnd = E->designators_end();
5265 D != DEnd; ++D) {
5266 if (D->isFieldDesignator()) {
5267 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5268 D->getDotLoc(),
5269 D->getFieldLoc()));
5270 continue;
5271 }
Mike Stump11289f42009-09-09 15:08:12 +00005272
Douglas Gregora16548e2009-08-11 05:31:07 +00005273 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005274 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005275 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005276 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005277
5278 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005279 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005280
Douglas Gregora16548e2009-08-11 05:31:07 +00005281 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5282 ArrayExprs.push_back(Index.release());
5283 continue;
5284 }
Mike Stump11289f42009-09-09 15:08:12 +00005285
Douglas Gregora16548e2009-08-11 05:31:07 +00005286 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00005287 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00005288 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5289 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005290 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005291
John McCalldadc5752010-08-24 06:29:42 +00005292 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005293 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005294 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005295
5296 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005297 End.get(),
5298 D->getLBracketLoc(),
5299 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005300
Douglas Gregora16548e2009-08-11 05:31:07 +00005301 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5302 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00005303
Douglas Gregora16548e2009-08-11 05:31:07 +00005304 ArrayExprs.push_back(Start.release());
5305 ArrayExprs.push_back(End.release());
5306 }
Mike Stump11289f42009-09-09 15:08:12 +00005307
Douglas Gregora16548e2009-08-11 05:31:07 +00005308 if (!getDerived().AlwaysRebuild() &&
5309 Init.get() == E->getInit() &&
5310 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005311 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005312
Douglas Gregora16548e2009-08-11 05:31:07 +00005313 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5314 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005315 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005316}
Mike Stump11289f42009-09-09 15:08:12 +00005317
Douglas Gregora16548e2009-08-11 05:31:07 +00005318template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005319ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005320TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005321 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00005322 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005323
Douglas Gregor3da3c062009-10-28 00:29:27 +00005324 // FIXME: Will we ever have proper type location here? Will we actually
5325 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00005326 QualType T = getDerived().TransformType(E->getType());
5327 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005328 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005329
Douglas Gregora16548e2009-08-11 05:31:07 +00005330 if (!getDerived().AlwaysRebuild() &&
5331 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005332 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005333
Douglas Gregora16548e2009-08-11 05:31:07 +00005334 return getDerived().RebuildImplicitValueInitExpr(T);
5335}
Mike Stump11289f42009-09-09 15:08:12 +00005336
Douglas Gregora16548e2009-08-11 05:31:07 +00005337template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005338ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005339TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00005340 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5341 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005342 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005343
John McCalldadc5752010-08-24 06:29:42 +00005344 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005345 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005346 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005347
Douglas Gregora16548e2009-08-11 05:31:07 +00005348 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00005349 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005350 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005351 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005352
John McCallb268a282010-08-23 23:25:46 +00005353 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00005354 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005355}
5356
5357template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005358ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005359TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005360 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005361 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005362 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5363 &ArgumentChanged))
5364 return ExprError();
5365
Douglas Gregora16548e2009-08-11 05:31:07 +00005366 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5367 move_arg(Inits),
5368 E->getRParenLoc());
5369}
Mike Stump11289f42009-09-09 15:08:12 +00005370
Douglas Gregora16548e2009-08-11 05:31:07 +00005371/// \brief Transform an address-of-label expression.
5372///
5373/// By default, the transformation of an address-of-label expression always
5374/// rebuilds the expression, so that the label identifier can be resolved to
5375/// the corresponding label statement by semantic analysis.
5376template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005377ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005378TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005379 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
5380 E->getLabel());
5381}
Mike Stump11289f42009-09-09 15:08:12 +00005382
5383template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005384ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005385TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005386 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00005387 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5388 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005389 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005390
Douglas Gregora16548e2009-08-11 05:31:07 +00005391 if (!getDerived().AlwaysRebuild() &&
5392 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00005393 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005394
5395 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005396 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005397 E->getRParenLoc());
5398}
Mike Stump11289f42009-09-09 15:08:12 +00005399
Douglas Gregora16548e2009-08-11 05:31:07 +00005400template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005401ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005402TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005403 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005404 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005405 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005406
John McCalldadc5752010-08-24 06:29:42 +00005407 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005408 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005409 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005410
John McCalldadc5752010-08-24 06:29:42 +00005411 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005412 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005413 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005414
Douglas Gregora16548e2009-08-11 05:31:07 +00005415 if (!getDerived().AlwaysRebuild() &&
5416 Cond.get() == E->getCond() &&
5417 LHS.get() == E->getLHS() &&
5418 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005419 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005420
Douglas Gregora16548e2009-08-11 05:31:07 +00005421 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00005422 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005423 E->getRParenLoc());
5424}
Mike Stump11289f42009-09-09 15:08:12 +00005425
Douglas Gregora16548e2009-08-11 05:31:07 +00005426template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005427ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005428TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005429 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005430}
5431
5432template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005433ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005434TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005435 switch (E->getOperator()) {
5436 case OO_New:
5437 case OO_Delete:
5438 case OO_Array_New:
5439 case OO_Array_Delete:
5440 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00005441 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005442
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005443 case OO_Call: {
5444 // This is a call to an object's operator().
5445 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5446
5447 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00005448 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005449 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005450 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005451
5452 // FIXME: Poor location information
5453 SourceLocation FakeLParenLoc
5454 = SemaRef.PP.getLocForEndOfToken(
5455 static_cast<Expr *>(Object.get())->getLocEnd());
5456
5457 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00005458 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005459 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
5460 Args))
5461 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005462
John McCallb268a282010-08-23 23:25:46 +00005463 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005464 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005465 E->getLocEnd());
5466 }
5467
5468#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5469 case OO_##Name:
5470#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5471#include "clang/Basic/OperatorKinds.def"
5472 case OO_Subscript:
5473 // Handled below.
5474 break;
5475
5476 case OO_Conditional:
5477 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00005478 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005479
5480 case OO_None:
5481 case NUM_OVERLOADED_OPERATORS:
5482 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00005483 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005484 }
5485
John McCalldadc5752010-08-24 06:29:42 +00005486 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005487 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005488 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005489
John McCalldadc5752010-08-24 06:29:42 +00005490 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005491 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005492 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005493
John McCalldadc5752010-08-24 06:29:42 +00005494 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00005495 if (E->getNumArgs() == 2) {
5496 Second = getDerived().TransformExpr(E->getArg(1));
5497 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005498 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005499 }
Mike Stump11289f42009-09-09 15:08:12 +00005500
Douglas Gregora16548e2009-08-11 05:31:07 +00005501 if (!getDerived().AlwaysRebuild() &&
5502 Callee.get() == E->getCallee() &&
5503 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005504 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00005505 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005506
Douglas Gregora16548e2009-08-11 05:31:07 +00005507 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5508 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005509 Callee.get(),
5510 First.get(),
5511 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005512}
Mike Stump11289f42009-09-09 15:08:12 +00005513
Douglas Gregora16548e2009-08-11 05:31:07 +00005514template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005515ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005516TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5517 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005518}
Mike Stump11289f42009-09-09 15:08:12 +00005519
Douglas Gregora16548e2009-08-11 05:31:07 +00005520template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005521ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005522TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005523 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5524 if (!Type)
5525 return ExprError();
5526
John McCalldadc5752010-08-24 06:29:42 +00005527 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005528 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005529 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005530 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005531
Douglas Gregora16548e2009-08-11 05:31:07 +00005532 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005533 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005534 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005535 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005536
Douglas Gregora16548e2009-08-11 05:31:07 +00005537 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005538 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005539 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5540 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5541 SourceLocation FakeRParenLoc
5542 = SemaRef.PP.getLocForEndOfToken(
5543 E->getSubExpr()->getSourceRange().getEnd());
5544 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005545 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005546 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005547 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005548 FakeRAngleLoc,
5549 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005550 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005551 FakeRParenLoc);
5552}
Mike Stump11289f42009-09-09 15:08:12 +00005553
Douglas Gregora16548e2009-08-11 05:31:07 +00005554template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005555ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005556TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5557 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005558}
Mike Stump11289f42009-09-09 15:08:12 +00005559
5560template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005561ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005562TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5563 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005564}
5565
Douglas Gregora16548e2009-08-11 05:31:07 +00005566template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005567ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005568TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005569 CXXReinterpretCastExpr *E) {
5570 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005571}
Mike Stump11289f42009-09-09 15:08:12 +00005572
Douglas Gregora16548e2009-08-11 05:31:07 +00005573template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005574ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005575TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5576 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005577}
Mike Stump11289f42009-09-09 15:08:12 +00005578
Douglas Gregora16548e2009-08-11 05:31:07 +00005579template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005580ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005581TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005582 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005583 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5584 if (!Type)
5585 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005586
John McCalldadc5752010-08-24 06:29:42 +00005587 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005588 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005589 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005590 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005591
Douglas Gregora16548e2009-08-11 05:31:07 +00005592 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005593 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005594 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005595 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005596
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005597 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005598 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005599 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005600 E->getRParenLoc());
5601}
Mike Stump11289f42009-09-09 15:08:12 +00005602
Douglas Gregora16548e2009-08-11 05:31:07 +00005603template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005604ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005605TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005606 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005607 TypeSourceInfo *TInfo
5608 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5609 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005610 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005611
Douglas Gregora16548e2009-08-11 05:31:07 +00005612 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005613 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005614 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005615
Douglas Gregor9da64192010-04-26 22:37:10 +00005616 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5617 E->getLocStart(),
5618 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005619 E->getLocEnd());
5620 }
Mike Stump11289f42009-09-09 15:08:12 +00005621
Douglas Gregora16548e2009-08-11 05:31:07 +00005622 // We don't know whether the expression is potentially evaluated until
5623 // after we perform semantic analysis, so the expression is potentially
5624 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005625 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00005626 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005627
John McCalldadc5752010-08-24 06:29:42 +00005628 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00005629 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005630 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005631
Douglas Gregora16548e2009-08-11 05:31:07 +00005632 if (!getDerived().AlwaysRebuild() &&
5633 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005634 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005635
Douglas Gregor9da64192010-04-26 22:37:10 +00005636 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5637 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005638 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005639 E->getLocEnd());
5640}
5641
5642template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005643ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00005644TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5645 if (E->isTypeOperand()) {
5646 TypeSourceInfo *TInfo
5647 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5648 if (!TInfo)
5649 return ExprError();
5650
5651 if (!getDerived().AlwaysRebuild() &&
5652 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005653 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005654
5655 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5656 E->getLocStart(),
5657 TInfo,
5658 E->getLocEnd());
5659 }
5660
5661 // We don't know whether the expression is potentially evaluated until
5662 // after we perform semantic analysis, so the expression is potentially
5663 // potentially evaluated.
5664 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5665
5666 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5667 if (SubExpr.isInvalid())
5668 return ExprError();
5669
5670 if (!getDerived().AlwaysRebuild() &&
5671 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005672 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005673
5674 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5675 E->getLocStart(),
5676 SubExpr.get(),
5677 E->getLocEnd());
5678}
5679
5680template<typename Derived>
5681ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005682TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005683 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005684}
Mike Stump11289f42009-09-09 15:08:12 +00005685
Douglas Gregora16548e2009-08-11 05:31:07 +00005686template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005687ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005688TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005689 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005690 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005691}
Mike Stump11289f42009-09-09 15:08:12 +00005692
Douglas Gregora16548e2009-08-11 05:31:07 +00005693template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005694ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005695TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005696 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5697 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5698 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00005699
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005700 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005701 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005702
Douglas Gregorb15af892010-01-07 23:12:05 +00005703 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005704}
Mike Stump11289f42009-09-09 15:08:12 +00005705
Douglas Gregora16548e2009-08-11 05:31:07 +00005706template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005707ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005708TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005709 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005710 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005711 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005712
Douglas Gregora16548e2009-08-11 05:31:07 +00005713 if (!getDerived().AlwaysRebuild() &&
5714 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005715 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005716
John McCallb268a282010-08-23 23:25:46 +00005717 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005718}
Mike Stump11289f42009-09-09 15:08:12 +00005719
Douglas Gregora16548e2009-08-11 05:31:07 +00005720template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005721ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005722TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005723 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005724 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5725 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005726 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00005727 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005728
Chandler Carruth794da4c2010-02-08 06:42:49 +00005729 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005730 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00005731 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005732
Douglas Gregor033f6752009-12-23 23:03:06 +00005733 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005734}
Mike Stump11289f42009-09-09 15:08:12 +00005735
Douglas Gregora16548e2009-08-11 05:31:07 +00005736template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005737ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00005738TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5739 CXXScalarValueInitExpr *E) {
5740 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5741 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005742 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00005743
Douglas Gregora16548e2009-08-11 05:31:07 +00005744 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005745 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005746 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005747
Douglas Gregor2b88c112010-09-08 00:15:04 +00005748 return getDerived().RebuildCXXScalarValueInitExpr(T,
5749 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00005750 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005751}
Mike Stump11289f42009-09-09 15:08:12 +00005752
Douglas Gregora16548e2009-08-11 05:31:07 +00005753template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005754ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005755TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005756 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00005757 TypeSourceInfo *AllocTypeInfo
5758 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5759 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005760 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005761
Douglas Gregora16548e2009-08-11 05:31:07 +00005762 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00005763 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00005764 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005765 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005766
Douglas Gregora16548e2009-08-11 05:31:07 +00005767 // Transform the placement arguments (if any).
5768 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005769 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005770 if (getDerived().TransformExprs(E->getPlacementArgs(),
5771 E->getNumPlacementArgs(), true,
5772 PlacementArgs, &ArgumentChanged))
5773 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005774
Douglas Gregorebe10102009-08-20 07:17:43 +00005775 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00005776 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005777 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
5778 ConstructorArgs, &ArgumentChanged))
5779 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005780
Douglas Gregord2d9da02010-02-26 00:38:10 +00005781 // Transform constructor, new operator, and delete operator.
5782 CXXConstructorDecl *Constructor = 0;
5783 if (E->getConstructor()) {
5784 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005785 getDerived().TransformDecl(E->getLocStart(),
5786 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005787 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005788 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005789 }
5790
5791 FunctionDecl *OperatorNew = 0;
5792 if (E->getOperatorNew()) {
5793 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005794 getDerived().TransformDecl(E->getLocStart(),
5795 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005796 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00005797 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005798 }
5799
5800 FunctionDecl *OperatorDelete = 0;
5801 if (E->getOperatorDelete()) {
5802 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005803 getDerived().TransformDecl(E->getLocStart(),
5804 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005805 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005806 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005807 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005808
Douglas Gregora16548e2009-08-11 05:31:07 +00005809 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00005810 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005811 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005812 Constructor == E->getConstructor() &&
5813 OperatorNew == E->getOperatorNew() &&
5814 OperatorDelete == E->getOperatorDelete() &&
5815 !ArgumentChanged) {
5816 // Mark any declarations we need as referenced.
5817 // FIXME: instantiation-specific.
5818 if (Constructor)
5819 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5820 if (OperatorNew)
5821 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5822 if (OperatorDelete)
5823 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00005824 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005825 }
Mike Stump11289f42009-09-09 15:08:12 +00005826
Douglas Gregor0744ef62010-09-07 21:49:58 +00005827 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005828 if (!ArraySize.get()) {
5829 // If no array size was specified, but the new expression was
5830 // instantiated with an array type (e.g., "new T" where T is
5831 // instantiated with "int[4]"), extract the outer bound from the
5832 // array type as our array size. We do this with constant and
5833 // dependently-sized array types.
5834 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5835 if (!ArrayT) {
5836 // Do nothing
5837 } else if (const ConstantArrayType *ConsArrayT
5838 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005839 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00005840 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5841 ConsArrayT->getSize(),
5842 SemaRef.Context.getSizeType(),
5843 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005844 AllocType = ConsArrayT->getElementType();
5845 } else if (const DependentSizedArrayType *DepArrayT
5846 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5847 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00005848 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005849 AllocType = DepArrayT->getElementType();
5850 }
5851 }
5852 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00005853
Douglas Gregora16548e2009-08-11 05:31:07 +00005854 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5855 E->isGlobalNew(),
5856 /*FIXME:*/E->getLocStart(),
5857 move_arg(PlacementArgs),
5858 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00005859 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005860 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00005861 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00005862 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005863 /*FIXME:*/E->getLocStart(),
5864 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005865 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005866}
Mike Stump11289f42009-09-09 15:08:12 +00005867
Douglas Gregora16548e2009-08-11 05:31:07 +00005868template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005869ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005870TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005871 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00005872 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005873 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005874
Douglas Gregord2d9da02010-02-26 00:38:10 +00005875 // Transform the delete operator, if known.
5876 FunctionDecl *OperatorDelete = 0;
5877 if (E->getOperatorDelete()) {
5878 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005879 getDerived().TransformDecl(E->getLocStart(),
5880 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005881 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005882 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005883 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005884
Douglas Gregora16548e2009-08-11 05:31:07 +00005885 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005886 Operand.get() == E->getArgument() &&
5887 OperatorDelete == E->getOperatorDelete()) {
5888 // Mark any declarations we need as referenced.
5889 // FIXME: instantiation-specific.
5890 if (OperatorDelete)
5891 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00005892
5893 if (!E->getArgument()->isTypeDependent()) {
5894 QualType Destroyed = SemaRef.Context.getBaseElementType(
5895 E->getDestroyedType());
5896 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
5897 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
5898 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
5899 SemaRef.LookupDestructor(Record));
5900 }
5901 }
5902
John McCallc3007a22010-10-26 07:05:15 +00005903 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005904 }
Mike Stump11289f42009-09-09 15:08:12 +00005905
Douglas Gregora16548e2009-08-11 05:31:07 +00005906 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5907 E->isGlobalDelete(),
5908 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00005909 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005910}
Mike Stump11289f42009-09-09 15:08:12 +00005911
Douglas Gregora16548e2009-08-11 05:31:07 +00005912template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005913ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005914TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005915 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005916 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00005917 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005918 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005919
John McCallba7bf592010-08-24 05:47:05 +00005920 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00005921 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005922 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005923 E->getOperatorLoc(),
5924 E->isArrow()? tok::arrow : tok::period,
5925 ObjectTypePtr,
5926 MayBePseudoDestructor);
5927 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005928 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005929
John McCallba7bf592010-08-24 05:47:05 +00005930 QualType ObjectType = ObjectTypePtr.get();
John McCall31f82722010-11-12 08:19:04 +00005931 NestedNameSpecifier *Qualifier = E->getQualifier();
5932 if (Qualifier) {
5933 Qualifier
5934 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5935 E->getQualifierRange(),
5936 ObjectType);
5937 if (!Qualifier)
5938 return ExprError();
5939 }
Mike Stump11289f42009-09-09 15:08:12 +00005940
Douglas Gregor678f90d2010-02-25 01:56:36 +00005941 PseudoDestructorTypeStorage Destroyed;
5942 if (E->getDestroyedTypeInfo()) {
5943 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00005944 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
5945 ObjectType, 0, Qualifier);
Douglas Gregor678f90d2010-02-25 01:56:36 +00005946 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005947 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00005948 Destroyed = DestroyedTypeInfo;
5949 } else if (ObjectType->isDependentType()) {
5950 // We aren't likely to be able to resolve the identifier down to a type
5951 // now anyway, so just retain the identifier.
5952 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5953 E->getDestroyedTypeLoc());
5954 } else {
5955 // Look for a destructor known with the given name.
5956 CXXScopeSpec SS;
5957 if (Qualifier) {
5958 SS.setScopeRep(Qualifier);
5959 SS.setRange(E->getQualifierRange());
5960 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005961
John McCallba7bf592010-08-24 05:47:05 +00005962 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005963 *E->getDestroyedTypeIdentifier(),
5964 E->getDestroyedTypeLoc(),
5965 /*Scope=*/0,
5966 SS, ObjectTypePtr,
5967 false);
5968 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005969 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005970
Douglas Gregor678f90d2010-02-25 01:56:36 +00005971 Destroyed
5972 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5973 E->getDestroyedTypeLoc());
5974 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005975
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005976 TypeSourceInfo *ScopeTypeInfo = 0;
5977 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00005978 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005979 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005980 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005981 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005982
John McCallb268a282010-08-23 23:25:46 +00005983 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005984 E->getOperatorLoc(),
5985 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005986 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005987 E->getQualifierRange(),
5988 ScopeTypeInfo,
5989 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005990 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005991 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005992}
Mike Stump11289f42009-09-09 15:08:12 +00005993
Douglas Gregorad8a3362009-09-04 17:36:40 +00005994template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005995ExprResult
John McCalld14a8642009-11-21 08:51:07 +00005996TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005997 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005998 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5999
6000 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6001 Sema::LookupOrdinaryName);
6002
6003 // Transform all the decls.
6004 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6005 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006006 NamedDecl *InstD = static_cast<NamedDecl*>(
6007 getDerived().TransformDecl(Old->getNameLoc(),
6008 *I));
John McCall84d87672009-12-10 09:41:52 +00006009 if (!InstD) {
6010 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6011 // This can happen because of dependent hiding.
6012 if (isa<UsingShadowDecl>(*I))
6013 continue;
6014 else
John McCallfaf5fb42010-08-26 23:41:50 +00006015 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006016 }
John McCalle66edc12009-11-24 19:00:30 +00006017
6018 // Expand using declarations.
6019 if (isa<UsingDecl>(InstD)) {
6020 UsingDecl *UD = cast<UsingDecl>(InstD);
6021 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6022 E = UD->shadow_end(); I != E; ++I)
6023 R.addDecl(*I);
6024 continue;
6025 }
6026
6027 R.addDecl(InstD);
6028 }
6029
6030 // Resolve a kind, but don't do any further analysis. If it's
6031 // ambiguous, the callee needs to deal with it.
6032 R.resolveKind();
6033
6034 // Rebuild the nested-name qualifier, if present.
6035 CXXScopeSpec SS;
6036 NestedNameSpecifier *Qualifier = 0;
6037 if (Old->getQualifier()) {
6038 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006039 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00006040 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006041 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006042
John McCalle66edc12009-11-24 19:00:30 +00006043 SS.setScopeRep(Qualifier);
6044 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006045 }
6046
Douglas Gregor9262f472010-04-27 18:19:34 +00006047 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006048 CXXRecordDecl *NamingClass
6049 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6050 Old->getNameLoc(),
6051 Old->getNamingClass()));
6052 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006053 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006054
Douglas Gregorda7be082010-04-27 16:10:10 +00006055 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006056 }
6057
6058 // If we have no template arguments, it's a normal declaration name.
6059 if (!Old->hasExplicitTemplateArgs())
6060 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6061
6062 // If we have template arguments, rebuild them, then rebuild the
6063 // templateid expression.
6064 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006065 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6066 Old->getNumTemplateArgs(),
6067 TransArgs))
6068 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006069
6070 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6071 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006072}
Mike Stump11289f42009-09-09 15:08:12 +00006073
Douglas Gregora16548e2009-08-11 05:31:07 +00006074template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006075ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006076TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006077 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6078 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006079 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006080
Douglas Gregora16548e2009-08-11 05:31:07 +00006081 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006082 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006083 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006084
Mike Stump11289f42009-09-09 15:08:12 +00006085 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006086 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006087 T,
6088 E->getLocEnd());
6089}
Mike Stump11289f42009-09-09 15:08:12 +00006090
Douglas Gregora16548e2009-08-11 05:31:07 +00006091template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006092ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006093TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6094 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6095 if (!LhsT)
6096 return ExprError();
6097
6098 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6099 if (!RhsT)
6100 return ExprError();
6101
6102 if (!getDerived().AlwaysRebuild() &&
6103 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6104 return SemaRef.Owned(E);
6105
6106 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6107 E->getLocStart(),
6108 LhsT, RhsT,
6109 E->getLocEnd());
6110}
6111
6112template<typename Derived>
6113ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006114TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006115 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006116 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00006117 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006118 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006119 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00006120 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006121
John McCall31f82722010-11-12 08:19:04 +00006122 // TODO: If this is a conversion-function-id, verify that the
6123 // destination type name (if present) resolves the same way after
6124 // instantiation as it did in the local scope.
6125
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006126 DeclarationNameInfo NameInfo
6127 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6128 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006129 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006130
John McCalle66edc12009-11-24 19:00:30 +00006131 if (!E->hasExplicitTemplateArgs()) {
6132 if (!getDerived().AlwaysRebuild() &&
6133 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006134 // Note: it is sufficient to compare the Name component of NameInfo:
6135 // if name has not changed, DNLoc has not changed either.
6136 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006137 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006138
John McCalle66edc12009-11-24 19:00:30 +00006139 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6140 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006141 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006142 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006143 }
John McCall6b51f282009-11-23 01:53:49 +00006144
6145 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006146 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6147 E->getNumTemplateArgs(),
6148 TransArgs))
6149 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006150
John McCalle66edc12009-11-24 19:00:30 +00006151 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6152 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006153 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006154 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006155}
6156
6157template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006158ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006159TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006160 // CXXConstructExprs are always implicit, so when we have a
6161 // 1-argument construction we just transform that argument.
6162 if (E->getNumArgs() == 1 ||
6163 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6164 return getDerived().TransformExpr(E->getArg(0));
6165
Douglas Gregora16548e2009-08-11 05:31:07 +00006166 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6167
6168 QualType T = getDerived().TransformType(E->getType());
6169 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006170 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006171
6172 CXXConstructorDecl *Constructor
6173 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006174 getDerived().TransformDecl(E->getLocStart(),
6175 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006176 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006177 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006178
Douglas Gregora16548e2009-08-11 05:31:07 +00006179 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006180 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006181 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6182 &ArgumentChanged))
6183 return ExprError();
6184
Douglas Gregora16548e2009-08-11 05:31:07 +00006185 if (!getDerived().AlwaysRebuild() &&
6186 T == E->getType() &&
6187 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006188 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006189 // Mark the constructor as referenced.
6190 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006191 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006192 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006193 }
Mike Stump11289f42009-09-09 15:08:12 +00006194
Douglas Gregordb121ba2009-12-14 16:27:04 +00006195 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6196 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006197 move_arg(Args),
6198 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006199 E->getConstructionKind(),
6200 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006201}
Mike Stump11289f42009-09-09 15:08:12 +00006202
Douglas Gregora16548e2009-08-11 05:31:07 +00006203/// \brief Transform a C++ temporary-binding expression.
6204///
Douglas Gregor363b1512009-12-24 18:51:59 +00006205/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6206/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006207template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006208ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006209TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006210 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006211}
Mike Stump11289f42009-09-09 15:08:12 +00006212
John McCall5d413782010-12-06 08:20:24 +00006213/// \brief Transform a C++ expression that contains cleanups that should
6214/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006215///
John McCall5d413782010-12-06 08:20:24 +00006216/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006217/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006218template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006219ExprResult
John McCall5d413782010-12-06 08:20:24 +00006220TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006221 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006222}
Mike Stump11289f42009-09-09 15:08:12 +00006223
Douglas Gregora16548e2009-08-11 05:31:07 +00006224template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006225ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006226TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006227 CXXTemporaryObjectExpr *E) {
6228 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6229 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006230 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006231
Douglas Gregora16548e2009-08-11 05:31:07 +00006232 CXXConstructorDecl *Constructor
6233 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006234 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006235 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006236 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006237 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006238
Douglas Gregora16548e2009-08-11 05:31:07 +00006239 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006240 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006241 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00006242 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6243 &ArgumentChanged))
6244 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006245
Douglas Gregora16548e2009-08-11 05:31:07 +00006246 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006247 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006248 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006249 !ArgumentChanged) {
6250 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006251 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006252 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006253 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006254
6255 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6256 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006257 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006258 E->getLocEnd());
6259}
Mike Stump11289f42009-09-09 15:08:12 +00006260
Douglas Gregora16548e2009-08-11 05:31:07 +00006261template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006262ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006263TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006264 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00006265 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6266 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006267 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006268
Douglas Gregora16548e2009-08-11 05:31:07 +00006269 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006270 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006271 Args.reserve(E->arg_size());
6272 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6273 &ArgumentChanged))
6274 return ExprError();
6275
Douglas Gregora16548e2009-08-11 05:31:07 +00006276 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006277 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006278 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006279 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006280
Douglas Gregora16548e2009-08-11 05:31:07 +00006281 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00006282 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00006283 E->getLParenLoc(),
6284 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006285 E->getRParenLoc());
6286}
Mike Stump11289f42009-09-09 15:08:12 +00006287
Douglas Gregora16548e2009-08-11 05:31:07 +00006288template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006289ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006290TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006291 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006292 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006293 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006294 Expr *OldBase;
6295 QualType BaseType;
6296 QualType ObjectType;
6297 if (!E->isImplicitAccess()) {
6298 OldBase = E->getBase();
6299 Base = getDerived().TransformExpr(OldBase);
6300 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006301 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006302
John McCall2d74de92009-12-01 22:10:20 +00006303 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00006304 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00006305 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006306 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006307 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006308 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00006309 ObjectTy,
6310 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00006311 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006312 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006313
John McCallba7bf592010-08-24 05:47:05 +00006314 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00006315 BaseType = ((Expr*) Base.get())->getType();
6316 } else {
6317 OldBase = 0;
6318 BaseType = getDerived().TransformType(E->getBaseType());
6319 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6320 }
Mike Stump11289f42009-09-09 15:08:12 +00006321
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006322 // Transform the first part of the nested-name-specifier that qualifies
6323 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006324 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006325 = getDerived().TransformFirstQualifierInScope(
6326 E->getFirstQualifierFoundInScope(),
6327 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006328
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006329 NestedNameSpecifier *Qualifier = 0;
6330 if (E->getQualifier()) {
6331 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6332 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00006333 ObjectType,
6334 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006335 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006336 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006337 }
Mike Stump11289f42009-09-09 15:08:12 +00006338
John McCall31f82722010-11-12 08:19:04 +00006339 // TODO: If this is a conversion-function-id, verify that the
6340 // destination type name (if present) resolves the same way after
6341 // instantiation as it did in the local scope.
6342
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006343 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00006344 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006345 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006346 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006347
John McCall2d74de92009-12-01 22:10:20 +00006348 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00006349 // This is a reference to a member without an explicitly-specified
6350 // template argument list. Optimize for this common case.
6351 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00006352 Base.get() == OldBase &&
6353 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006354 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006355 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006356 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00006357 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006358
John McCallb268a282010-08-23 23:25:46 +00006359 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006360 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00006361 E->isArrow(),
6362 E->getOperatorLoc(),
6363 Qualifier,
6364 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00006365 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006366 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006367 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00006368 }
6369
John McCall6b51f282009-11-23 01:53:49 +00006370 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006371 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6372 E->getNumTemplateArgs(),
6373 TransArgs))
6374 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006375
John McCallb268a282010-08-23 23:25:46 +00006376 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006377 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006378 E->isArrow(),
6379 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006380 Qualifier,
6381 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006382 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006383 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006384 &TransArgs);
6385}
6386
6387template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006388ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006389TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00006390 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006391 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006392 QualType BaseType;
6393 if (!Old->isImplicitAccess()) {
6394 Base = getDerived().TransformExpr(Old->getBase());
6395 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006396 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006397 BaseType = ((Expr*) Base.get())->getType();
6398 } else {
6399 BaseType = getDerived().TransformType(Old->getBaseType());
6400 }
John McCall10eae182009-11-30 22:42:35 +00006401
6402 NestedNameSpecifier *Qualifier = 0;
6403 if (Old->getQualifier()) {
6404 Qualifier
6405 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006406 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00006407 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00006408 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006409 }
6410
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006411 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00006412 Sema::LookupOrdinaryName);
6413
6414 // Transform all the decls.
6415 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6416 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006417 NamedDecl *InstD = static_cast<NamedDecl*>(
6418 getDerived().TransformDecl(Old->getMemberLoc(),
6419 *I));
John McCall84d87672009-12-10 09:41:52 +00006420 if (!InstD) {
6421 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6422 // This can happen because of dependent hiding.
6423 if (isa<UsingShadowDecl>(*I))
6424 continue;
6425 else
John McCallfaf5fb42010-08-26 23:41:50 +00006426 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006427 }
John McCall10eae182009-11-30 22:42:35 +00006428
6429 // Expand using declarations.
6430 if (isa<UsingDecl>(InstD)) {
6431 UsingDecl *UD = cast<UsingDecl>(InstD);
6432 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6433 E = UD->shadow_end(); I != E; ++I)
6434 R.addDecl(*I);
6435 continue;
6436 }
6437
6438 R.addDecl(InstD);
6439 }
6440
6441 R.resolveKind();
6442
Douglas Gregor9262f472010-04-27 18:19:34 +00006443 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00006444 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006445 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00006446 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00006447 Old->getMemberLoc(),
6448 Old->getNamingClass()));
6449 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006450 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006451
Douglas Gregorda7be082010-04-27 16:10:10 +00006452 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00006453 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006454
John McCall10eae182009-11-30 22:42:35 +00006455 TemplateArgumentListInfo TransArgs;
6456 if (Old->hasExplicitTemplateArgs()) {
6457 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6458 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006459 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6460 Old->getNumTemplateArgs(),
6461 TransArgs))
6462 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006463 }
John McCall38836f02010-01-15 08:34:02 +00006464
6465 // FIXME: to do this check properly, we will need to preserve the
6466 // first-qualifier-in-scope here, just in case we had a dependent
6467 // base (and therefore couldn't do the check) and a
6468 // nested-name-qualifier (and therefore could do the lookup).
6469 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006470
John McCallb268a282010-08-23 23:25:46 +00006471 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006472 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006473 Old->getOperatorLoc(),
6474 Old->isArrow(),
6475 Qualifier,
6476 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006477 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006478 R,
6479 (Old->hasExplicitTemplateArgs()
6480 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006481}
6482
6483template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006484ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006485TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6486 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6487 if (SubExpr.isInvalid())
6488 return ExprError();
6489
6490 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00006491 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006492
6493 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6494}
6495
6496template<typename Derived>
6497ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006498TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
6499 llvm_unreachable("pack expansion expression in unhandled context");
6500 return ExprError();
6501}
6502
6503template<typename Derived>
6504ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006505TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006506 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006507}
6508
Mike Stump11289f42009-09-09 15:08:12 +00006509template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006510ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006511TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006512 TypeSourceInfo *EncodedTypeInfo
6513 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6514 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006515 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006516
Douglas Gregora16548e2009-08-11 05:31:07 +00006517 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006518 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006519 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006520
6521 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006522 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006523 E->getRParenLoc());
6524}
Mike Stump11289f42009-09-09 15:08:12 +00006525
Douglas Gregora16548e2009-08-11 05:31:07 +00006526template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006527ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006528TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006529 // Transform arguments.
6530 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006531 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006532 Args.reserve(E->getNumArgs());
6533 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
6534 &ArgChanged))
6535 return ExprError();
6536
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006537 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6538 // Class message: transform the receiver type.
6539 TypeSourceInfo *ReceiverTypeInfo
6540 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6541 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006542 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006543
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006544 // If nothing changed, just retain the existing message send.
6545 if (!getDerived().AlwaysRebuild() &&
6546 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006547 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006548
6549 // Build a new class message send.
6550 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6551 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00006552 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006553 E->getMethodDecl(),
6554 E->getLeftLoc(),
6555 move_arg(Args),
6556 E->getRightLoc());
6557 }
6558
6559 // Instance message: transform the receiver
6560 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6561 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00006562 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006563 = getDerived().TransformExpr(E->getInstanceReceiver());
6564 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006565 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006566
6567 // If nothing changed, just retain the existing message send.
6568 if (!getDerived().AlwaysRebuild() &&
6569 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006570 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006571
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006572 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00006573 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006574 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00006575 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006576 E->getMethodDecl(),
6577 E->getLeftLoc(),
6578 move_arg(Args),
6579 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006580}
6581
Mike Stump11289f42009-09-09 15:08:12 +00006582template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006583ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006584TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006585 return SemaRef.Owned(E);
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>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006591 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006592}
6593
Mike Stump11289f42009-09-09 15:08:12 +00006594template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006595ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006596TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006597 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006598 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006599 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006600 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00006601
6602 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006603
Douglas Gregord51d90d2010-04-26 20:11:03 +00006604 // If nothing changed, just retain the existing expression.
6605 if (!getDerived().AlwaysRebuild() &&
6606 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006607 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006608
John McCallb268a282010-08-23 23:25:46 +00006609 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006610 E->getLocation(),
6611 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006612}
6613
Mike Stump11289f42009-09-09 15:08:12 +00006614template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006615ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006616TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00006617 // 'super' and types never change. Property never changes. Just
6618 // retain the existing expression.
6619 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00006620 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006621
Douglas Gregor9faee212010-04-26 20:47:02 +00006622 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006623 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00006624 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006625 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006626
Douglas Gregor9faee212010-04-26 20:47:02 +00006627 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006628
Douglas Gregor9faee212010-04-26 20:47:02 +00006629 // If nothing changed, just retain the existing expression.
6630 if (!getDerived().AlwaysRebuild() &&
6631 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006632 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006633
John McCallb7bd14f2010-12-02 01:19:52 +00006634 if (E->isExplicitProperty())
6635 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6636 E->getExplicitProperty(),
6637 E->getLocation());
6638
6639 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6640 E->getType(),
6641 E->getImplicitPropertyGetter(),
6642 E->getImplicitPropertySetter(),
6643 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006644}
6645
Mike Stump11289f42009-09-09 15:08:12 +00006646template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006647ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006648TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006649 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006650 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006651 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006652 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006653
Douglas Gregord51d90d2010-04-26 20:11:03 +00006654 // If nothing changed, just retain the existing expression.
6655 if (!getDerived().AlwaysRebuild() &&
6656 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006657 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006658
John McCallb268a282010-08-23 23:25:46 +00006659 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006660 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006661}
6662
Mike Stump11289f42009-09-09 15:08:12 +00006663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006664ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006665TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006666 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006667 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006668 SubExprs.reserve(E->getNumSubExprs());
6669 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
6670 SubExprs, &ArgumentChanged))
6671 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006672
Douglas Gregora16548e2009-08-11 05:31:07 +00006673 if (!getDerived().AlwaysRebuild() &&
6674 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006675 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006676
Douglas Gregora16548e2009-08-11 05:31:07 +00006677 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6678 move_arg(SubExprs),
6679 E->getRParenLoc());
6680}
6681
Mike Stump11289f42009-09-09 15:08:12 +00006682template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006683ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006684TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006685 SourceLocation CaretLoc(E->getExprLoc());
6686
6687 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6688 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6689 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6690 llvm::SmallVector<ParmVarDecl*, 4> Params;
6691 llvm::SmallVector<QualType, 4> ParamTypes;
6692
6693 // Parameter substitution.
6694 const BlockDecl *BD = E->getBlockDecl();
6695 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6696 EN = BD->param_end(); P != EN; ++P) {
6697 ParmVarDecl *OldParm = (*P);
6698 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6699 QualType NewType = NewParm->getType();
6700 Params.push_back(NewParm);
6701 ParamTypes.push_back(NewParm->getType());
6702 }
6703
6704 const FunctionType *BExprFunctionType = E->getFunctionType();
6705 QualType BExprResultType = BExprFunctionType->getResultType();
6706 if (!BExprResultType.isNull()) {
6707 if (!BExprResultType->isDependentType())
6708 CurBlock->ReturnType = BExprResultType;
6709 else if (BExprResultType != SemaRef.Context.DependentTy)
6710 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6711 }
6712
6713 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006714 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006715 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006716 return ExprError();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006717 // Set the parameters on the block decl.
6718 if (!Params.empty())
6719 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6720
6721 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6722 CurBlock->ReturnType,
6723 ParamTypes.data(),
6724 ParamTypes.size(),
6725 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006726 0,
6727 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006728
6729 CurBlock->FunctionType = FunctionType;
John McCallb268a282010-08-23 23:25:46 +00006730 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006731}
6732
Mike Stump11289f42009-09-09 15:08:12 +00006733template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006734ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006735TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006736 NestedNameSpecifier *Qualifier = 0;
6737
6738 ValueDecl *ND
6739 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6740 E->getDecl()));
6741 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006742 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006743
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006744 if (!getDerived().AlwaysRebuild() &&
6745 ND == E->getDecl()) {
6746 // Mark it referenced in the new context regardless.
6747 // FIXME: this is a bit instantiation-specific.
6748 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6749
John McCallc3007a22010-10-26 07:05:15 +00006750 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006751 }
6752
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006753 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006754 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006755 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006756}
Mike Stump11289f42009-09-09 15:08:12 +00006757
Douglas Gregora16548e2009-08-11 05:31:07 +00006758//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006759// Type reconstruction
6760//===----------------------------------------------------------------------===//
6761
Mike Stump11289f42009-09-09 15:08:12 +00006762template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006763QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6764 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006765 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006766 getDerived().getBaseEntity());
6767}
6768
Mike Stump11289f42009-09-09 15:08:12 +00006769template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006770QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6771 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006772 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006773 getDerived().getBaseEntity());
6774}
6775
Mike Stump11289f42009-09-09 15:08:12 +00006776template<typename Derived>
6777QualType
John McCall70dd5f62009-10-30 00:06:24 +00006778TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6779 bool WrittenAsLValue,
6780 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006781 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006782 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006783}
6784
6785template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006786QualType
John McCall70dd5f62009-10-30 00:06:24 +00006787TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6788 QualType ClassType,
6789 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006790 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006791 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006792}
6793
6794template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006795QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006796TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6797 ArrayType::ArraySizeModifier SizeMod,
6798 const llvm::APInt *Size,
6799 Expr *SizeExpr,
6800 unsigned IndexTypeQuals,
6801 SourceRange BracketsRange) {
6802 if (SizeExpr || !Size)
6803 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6804 IndexTypeQuals, BracketsRange,
6805 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006806
6807 QualType Types[] = {
6808 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6809 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6810 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006811 };
6812 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6813 QualType SizeType;
6814 for (unsigned I = 0; I != NumTypes; ++I)
6815 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6816 SizeType = Types[I];
6817 break;
6818 }
Mike Stump11289f42009-09-09 15:08:12 +00006819
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006820 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6821 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006822 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006823 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006824 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006825}
Mike Stump11289f42009-09-09 15:08:12 +00006826
Douglas Gregord6ff3322009-08-04 16:50:30 +00006827template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006828QualType
6829TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006830 ArrayType::ArraySizeModifier SizeMod,
6831 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006832 unsigned IndexTypeQuals,
6833 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006834 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006835 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006836}
6837
6838template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006839QualType
Mike Stump11289f42009-09-09 15:08:12 +00006840TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006841 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006842 unsigned IndexTypeQuals,
6843 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006844 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006845 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006846}
Mike Stump11289f42009-09-09 15:08:12 +00006847
Douglas Gregord6ff3322009-08-04 16:50:30 +00006848template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006849QualType
6850TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006851 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006852 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006853 unsigned IndexTypeQuals,
6854 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006855 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006856 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006857 IndexTypeQuals, BracketsRange);
6858}
6859
6860template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006861QualType
6862TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006863 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006864 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006865 unsigned IndexTypeQuals,
6866 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006867 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006868 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006869 IndexTypeQuals, BracketsRange);
6870}
6871
6872template<typename Derived>
6873QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00006874 unsigned NumElements,
6875 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006876 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00006877 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006878}
Mike Stump11289f42009-09-09 15:08:12 +00006879
Douglas Gregord6ff3322009-08-04 16:50:30 +00006880template<typename Derived>
6881QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6882 unsigned NumElements,
6883 SourceLocation AttributeLoc) {
6884 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6885 NumElements, true);
6886 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006887 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6888 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00006889 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006890}
Mike Stump11289f42009-09-09 15:08:12 +00006891
Douglas Gregord6ff3322009-08-04 16:50:30 +00006892template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006893QualType
6894TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00006895 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006896 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00006897 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006898}
Mike Stump11289f42009-09-09 15:08:12 +00006899
Douglas Gregord6ff3322009-08-04 16:50:30 +00006900template<typename Derived>
6901QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006902 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006903 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006904 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00006905 unsigned Quals,
6906 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00006907 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006908 Quals,
6909 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006910 getDerived().getBaseEntity(),
6911 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006912}
Mike Stump11289f42009-09-09 15:08:12 +00006913
Douglas Gregord6ff3322009-08-04 16:50:30 +00006914template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006915QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6916 return SemaRef.Context.getFunctionNoProtoType(T);
6917}
6918
6919template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006920QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6921 assert(D && "no decl found");
6922 if (D->isInvalidDecl()) return QualType();
6923
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006924 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006925 TypeDecl *Ty;
6926 if (isa<UsingDecl>(D)) {
6927 UsingDecl *Using = cast<UsingDecl>(D);
6928 assert(Using->isTypeName() &&
6929 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6930
6931 // A valid resolved using typename decl points to exactly one type decl.
6932 assert(++Using->shadow_begin() == Using->shadow_end());
6933 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006934
John McCallb96ec562009-12-04 22:46:56 +00006935 } else {
6936 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6937 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6938 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6939 }
6940
6941 return SemaRef.Context.getTypeDeclType(Ty);
6942}
6943
6944template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00006945QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
6946 SourceLocation Loc) {
6947 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006948}
6949
6950template<typename Derived>
6951QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6952 return SemaRef.Context.getTypeOfType(Underlying);
6953}
6954
6955template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00006956QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
6957 SourceLocation Loc) {
6958 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006959}
6960
6961template<typename Derived>
6962QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006963 TemplateName Template,
6964 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006965 const TemplateArgumentListInfo &TemplateArgs) {
6966 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006967}
Mike Stump11289f42009-09-09 15:08:12 +00006968
Douglas Gregor1135c352009-08-06 05:28:30 +00006969template<typename Derived>
6970NestedNameSpecifier *
6971TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6972 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006973 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006974 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006975 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006976 CXXScopeSpec SS;
6977 // FIXME: The source location information is all wrong.
6978 SS.setRange(Range);
6979 SS.setScopeRep(Prefix);
6980 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006981 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006982 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006983 ObjectType,
6984 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006985 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006986}
6987
6988template<typename Derived>
6989NestedNameSpecifier *
6990TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6991 SourceRange Range,
6992 NamespaceDecl *NS) {
6993 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6994}
6995
6996template<typename Derived>
6997NestedNameSpecifier *
6998TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6999 SourceRange Range,
7000 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00007001 QualType T) {
7002 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00007003 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00007004 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00007005 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7006 T.getTypePtr());
7007 }
Mike Stump11289f42009-09-09 15:08:12 +00007008
Douglas Gregor1135c352009-08-06 05:28:30 +00007009 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7010 return 0;
7011}
Mike Stump11289f42009-09-09 15:08:12 +00007012
Douglas Gregor71dc5092009-08-06 06:41:21 +00007013template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007014TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007015TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7016 bool TemplateKW,
7017 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00007018 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007019 Template);
7020}
7021
7022template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007023TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007024TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00007025 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00007026 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00007027 QualType ObjectType,
7028 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00007029 CXXScopeSpec SS;
Douglas Gregora5614c52010-09-08 23:56:00 +00007030 SS.setRange(QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00007031 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00007032 UnqualifiedId Name;
7033 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00007034 Sema::TemplateTy Template;
7035 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7036 /*FIXME:*/getDerived().getBaseLocation(),
7037 SS,
7038 Name,
John McCallba7bf592010-08-24 05:47:05 +00007039 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007040 /*EnteringContext=*/false,
7041 Template);
John McCall31f82722010-11-12 08:19:04 +00007042 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007043}
Mike Stump11289f42009-09-09 15:08:12 +00007044
Douglas Gregora16548e2009-08-11 05:31:07 +00007045template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007046TemplateName
7047TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7048 OverloadedOperatorKind Operator,
7049 QualType ObjectType) {
7050 CXXScopeSpec SS;
7051 SS.setRange(SourceRange(getDerived().getBaseLocation()));
7052 SS.setScopeRep(Qualifier);
7053 UnqualifiedId Name;
7054 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7055 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7056 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007057 Sema::TemplateTy Template;
7058 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007059 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007060 SS,
7061 Name,
John McCallba7bf592010-08-24 05:47:05 +00007062 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007063 /*EnteringContext=*/false,
7064 Template);
7065 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007066}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007067
Douglas Gregor71395fa2009-11-04 00:56:37 +00007068template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007069ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007070TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7071 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007072 Expr *OrigCallee,
7073 Expr *First,
7074 Expr *Second) {
7075 Expr *Callee = OrigCallee->IgnoreParenCasts();
7076 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007077
Douglas Gregora16548e2009-08-11 05:31:07 +00007078 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007079 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007080 if (!First->getType()->isOverloadableType() &&
7081 !Second->getType()->isOverloadableType())
7082 return getSema().CreateBuiltinArraySubscriptExpr(First,
7083 Callee->getLocStart(),
7084 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007085 } else if (Op == OO_Arrow) {
7086 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007087 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7088 } else if (Second == 0 || isPostIncDec) {
7089 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007090 // The argument is not of overloadable type, so try to create a
7091 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007092 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007093 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007094
John McCallb268a282010-08-23 23:25:46 +00007095 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007096 }
7097 } else {
John McCallb268a282010-08-23 23:25:46 +00007098 if (!First->getType()->isOverloadableType() &&
7099 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007100 // Neither of the arguments is an overloadable type, so try to
7101 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007102 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007103 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007104 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007105 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007106 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007107
Douglas Gregora16548e2009-08-11 05:31:07 +00007108 return move(Result);
7109 }
7110 }
Mike Stump11289f42009-09-09 15:08:12 +00007111
7112 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007113 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007114 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007115
John McCallb268a282010-08-23 23:25:46 +00007116 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007117 assert(ULE->requiresADL());
7118
7119 // FIXME: Do we have to check
7120 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007121 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007122 } else {
John McCallb268a282010-08-23 23:25:46 +00007123 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007124 }
Mike Stump11289f42009-09-09 15:08:12 +00007125
Douglas Gregora16548e2009-08-11 05:31:07 +00007126 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007127 Expr *Args[2] = { First, Second };
7128 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007129
Douglas Gregora16548e2009-08-11 05:31:07 +00007130 // Create the overloaded operator invocation for unary operators.
7131 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007132 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007133 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007134 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007135 }
Mike Stump11289f42009-09-09 15:08:12 +00007136
Sebastian Redladba46e2009-10-29 20:17:01 +00007137 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007138 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007139 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007140 First,
7141 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007142
Douglas Gregora16548e2009-08-11 05:31:07 +00007143 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007144 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007145 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007146 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7147 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007148 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007149
Mike Stump11289f42009-09-09 15:08:12 +00007150 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007151}
Mike Stump11289f42009-09-09 15:08:12 +00007152
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007153template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007154ExprResult
John McCallb268a282010-08-23 23:25:46 +00007155TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007156 SourceLocation OperatorLoc,
7157 bool isArrow,
7158 NestedNameSpecifier *Qualifier,
7159 SourceRange QualifierRange,
7160 TypeSourceInfo *ScopeType,
7161 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007162 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007163 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007164 CXXScopeSpec SS;
7165 if (Qualifier) {
7166 SS.setRange(QualifierRange);
7167 SS.setScopeRep(Qualifier);
7168 }
7169
John McCallb268a282010-08-23 23:25:46 +00007170 QualType BaseType = Base->getType();
7171 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007172 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007173 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007174 !BaseType->getAs<PointerType>()->getPointeeType()
7175 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007176 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00007177 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007178 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007179 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007180 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007181 /*FIXME?*/true);
7182 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007183
Douglas Gregor678f90d2010-02-25 01:56:36 +00007184 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007185 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7186 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7187 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7188 NameInfo.setNamedTypeInfo(DestroyedType);
7189
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007190 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007191
John McCallb268a282010-08-23 23:25:46 +00007192 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007193 OperatorLoc, isArrow,
7194 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007195 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007196 /*TemplateArgs*/ 0);
7197}
7198
Douglas Gregord6ff3322009-08-04 16:50:30 +00007199} // end namespace clang
7200
7201#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H