blob: 9088ae0fef26b8c6555b18b114b5c3bd6c4cd77e [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()) {
2105 case TemplateArgument::Expression:
Douglas Gregor968f23a2011-01-03 19:31:53 +00002106 // FIXME: We should be able to handle this now!
2107
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002108 case TemplateArgument::Template:
2109 llvm_unreachable("Unsupported pack expansion of expressions/templates");
2110
2111 case TemplateArgument::Null:
2112 case TemplateArgument::Integral:
2113 case TemplateArgument::Declaration:
2114 case TemplateArgument::Pack:
2115 llvm_unreachable("Pack expansion pattern has no parameter packs");
2116
2117 case TemplateArgument::Type:
2118 if (TypeSourceInfo *Expansion
2119 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
2120 EllipsisLoc))
2121 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2122 Expansion);
2123 break;
2124 }
2125
2126 return TemplateArgumentLoc();
2127 }
2128
Douglas Gregor968f23a2011-01-03 19:31:53 +00002129 /// \brief Build a new expression pack expansion.
2130 ///
2131 /// By default, performs semantic analysis to build a new pack expansion
2132 /// for an expression. Subclasses may override this routine to provide
2133 /// different behavior.
2134 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc) {
2135 return getSema().ActOnPackExpansion(Pattern, EllipsisLoc);
2136 }
2137
John McCall31f82722010-11-12 08:19:04 +00002138private:
2139 QualType TransformTypeInObjectScope(QualType T,
2140 QualType ObjectType,
2141 NamedDecl *FirstQualifierInScope,
2142 NestedNameSpecifier *Prefix);
2143
2144 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2145 QualType ObjectType,
2146 NamedDecl *FirstQualifierInScope,
2147 NestedNameSpecifier *Prefix);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002148};
Douglas Gregora16548e2009-08-11 05:31:07 +00002149
Douglas Gregorebe10102009-08-20 07:17:43 +00002150template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002151StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002152 if (!S)
2153 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002154
Douglas Gregorebe10102009-08-20 07:17:43 +00002155 switch (S->getStmtClass()) {
2156 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002157
Douglas Gregorebe10102009-08-20 07:17:43 +00002158 // Transform individual statement nodes
2159#define STMT(Node, Parent) \
2160 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2161#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002162#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002163
Douglas Gregorebe10102009-08-20 07:17:43 +00002164 // Transform expressions by calling TransformExpr.
2165#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002166#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002167#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002168#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002169 {
John McCalldadc5752010-08-24 06:29:42 +00002170 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002171 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002172 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002173
John McCallb268a282010-08-23 23:25:46 +00002174 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002175 }
Mike Stump11289f42009-09-09 15:08:12 +00002176 }
2177
John McCallc3007a22010-10-26 07:05:15 +00002178 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002179}
Mike Stump11289f42009-09-09 15:08:12 +00002180
2181
Douglas Gregore922c772009-08-04 22:27:00 +00002182template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002183ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 if (!E)
2185 return SemaRef.Owned(E);
2186
2187 switch (E->getStmtClass()) {
2188 case Stmt::NoStmtClass: break;
2189#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002190#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002191#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002192 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002193#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002194 }
2195
John McCallc3007a22010-10-26 07:05:15 +00002196 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002197}
2198
2199template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002200bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2201 unsigned NumInputs,
2202 bool IsCall,
2203 llvm::SmallVectorImpl<Expr *> &Outputs,
2204 bool *ArgChanged) {
2205 for (unsigned I = 0; I != NumInputs; ++I) {
2206 // If requested, drop call arguments that need to be dropped.
2207 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2208 if (ArgChanged)
2209 *ArgChanged = true;
2210
2211 break;
2212 }
2213
Douglas Gregor968f23a2011-01-03 19:31:53 +00002214 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2215 Expr *Pattern = Expansion->getPattern();
2216
2217 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2218 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2219 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2220
2221 // Determine whether the set of unexpanded parameter packs can and should
2222 // be expanded.
2223 bool Expand = true;
2224 unsigned NumExpansions = 0;
2225 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2226 Pattern->getSourceRange(),
2227 Unexpanded.data(),
2228 Unexpanded.size(),
2229 Expand, NumExpansions))
2230 return true;
2231
2232 if (!Expand) {
2233 // The transform has determined that we should perform a simple
2234 // transformation on the pack expansion, producing another pack
2235 // expansion.
2236 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2237 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2238 if (OutPattern.isInvalid())
2239 return true;
2240
2241 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
2242 Expansion->getEllipsisLoc());
2243 if (Out.isInvalid())
2244 return true;
2245
2246 if (ArgChanged)
2247 *ArgChanged = true;
2248 Outputs.push_back(Out.get());
2249 continue;
2250 }
2251
2252 // The transform has determined that we should perform an elementwise
2253 // expansion of the pattern. Do so.
2254 for (unsigned I = 0; I != NumExpansions; ++I) {
2255 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2256 ExprResult Out = getDerived().TransformExpr(Pattern);
2257 if (Out.isInvalid())
2258 return true;
2259
2260 if (ArgChanged)
2261 *ArgChanged = true;
2262 Outputs.push_back(Out.get());
2263 }
2264
2265 continue;
2266 }
2267
Douglas Gregora3efea12011-01-03 19:04:46 +00002268 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2269 if (Result.isInvalid())
2270 return true;
2271
2272 if (Result.get() != Inputs[I] && ArgChanged)
2273 *ArgChanged = true;
2274
2275 Outputs.push_back(Result.get());
2276 }
2277
2278 return false;
2279}
2280
2281template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002282NestedNameSpecifier *
2283TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002284 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002285 QualType ObjectType,
2286 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002287 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002288
Douglas Gregorebe10102009-08-20 07:17:43 +00002289 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002290 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002291 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002292 ObjectType,
2293 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002294 if (!Prefix)
2295 return 0;
2296 }
Mike Stump11289f42009-09-09 15:08:12 +00002297
Douglas Gregor1135c352009-08-06 05:28:30 +00002298 switch (NNS->getKind()) {
2299 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002300 if (Prefix) {
2301 // The object type and qualifier-in-scope really apply to the
2302 // leftmost entity.
2303 ObjectType = QualType();
2304 FirstQualifierInScope = 0;
2305 }
2306
Mike Stump11289f42009-09-09 15:08:12 +00002307 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002308 "Identifier nested-name-specifier with no prefix or object type");
2309 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2310 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002311 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002312
2313 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002314 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002315 ObjectType,
2316 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002317
Douglas Gregor1135c352009-08-06 05:28:30 +00002318 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002319 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002320 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002321 getDerived().TransformDecl(Range.getBegin(),
2322 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002323 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002324 Prefix == NNS->getPrefix() &&
2325 NS == NNS->getAsNamespace())
2326 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002327
Douglas Gregor1135c352009-08-06 05:28:30 +00002328 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2329 }
Mike Stump11289f42009-09-09 15:08:12 +00002330
Douglas Gregor1135c352009-08-06 05:28:30 +00002331 case NestedNameSpecifier::Global:
2332 // There is no meaningful transformation that one could perform on the
2333 // global scope.
2334 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002335
Douglas Gregor1135c352009-08-06 05:28:30 +00002336 case NestedNameSpecifier::TypeSpecWithTemplate:
2337 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002338 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002339 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2340 ObjectType,
2341 FirstQualifierInScope,
2342 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002343 if (T.isNull())
2344 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002345
Douglas Gregor1135c352009-08-06 05:28:30 +00002346 if (!getDerived().AlwaysRebuild() &&
2347 Prefix == NNS->getPrefix() &&
2348 T == QualType(NNS->getAsType(), 0))
2349 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002350
2351 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2352 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002353 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002354 }
2355 }
Mike Stump11289f42009-09-09 15:08:12 +00002356
Douglas Gregor1135c352009-08-06 05:28:30 +00002357 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002358 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002359}
2360
2361template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002362DeclarationNameInfo
2363TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002364::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002365 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002366 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002367 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002368
2369 switch (Name.getNameKind()) {
2370 case DeclarationName::Identifier:
2371 case DeclarationName::ObjCZeroArgSelector:
2372 case DeclarationName::ObjCOneArgSelector:
2373 case DeclarationName::ObjCMultiArgSelector:
2374 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002375 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002376 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002377 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002378
Douglas Gregorf816bd72009-09-03 22:13:48 +00002379 case DeclarationName::CXXConstructorName:
2380 case DeclarationName::CXXDestructorName:
2381 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002382 TypeSourceInfo *NewTInfo;
2383 CanQualType NewCanTy;
2384 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002385 NewTInfo = getDerived().TransformType(OldTInfo);
2386 if (!NewTInfo)
2387 return DeclarationNameInfo();
2388 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002389 }
2390 else {
2391 NewTInfo = 0;
2392 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002393 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002394 if (NewT.isNull())
2395 return DeclarationNameInfo();
2396 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2397 }
Mike Stump11289f42009-09-09 15:08:12 +00002398
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002399 DeclarationName NewName
2400 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2401 NewCanTy);
2402 DeclarationNameInfo NewNameInfo(NameInfo);
2403 NewNameInfo.setName(NewName);
2404 NewNameInfo.setNamedTypeInfo(NewTInfo);
2405 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002406 }
Mike Stump11289f42009-09-09 15:08:12 +00002407 }
2408
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002409 assert(0 && "Unknown name kind.");
2410 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002411}
2412
2413template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002414TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002415TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002416 QualType ObjectType,
2417 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002418 SourceLocation Loc = getDerived().getBaseLocation();
2419
Douglas Gregor71dc5092009-08-06 06:41:21 +00002420 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002421 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002422 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002423 /*FIXME*/ SourceRange(Loc),
2424 ObjectType,
2425 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002426 if (!NNS)
2427 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002428
Douglas Gregor71dc5092009-08-06 06:41:21 +00002429 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002430 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002431 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002432 if (!TransTemplate)
2433 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002434
Douglas Gregor71dc5092009-08-06 06:41:21 +00002435 if (!getDerived().AlwaysRebuild() &&
2436 NNS == QTN->getQualifier() &&
2437 TransTemplate == Template)
2438 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002439
Douglas Gregor71dc5092009-08-06 06:41:21 +00002440 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2441 TransTemplate);
2442 }
Mike Stump11289f42009-09-09 15:08:12 +00002443
John McCalle66edc12009-11-24 19:00:30 +00002444 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002445 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002446 }
Mike Stump11289f42009-09-09 15:08:12 +00002447
Douglas Gregor71dc5092009-08-06 06:41:21 +00002448 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002449 NestedNameSpecifier *NNS = DTN->getQualifier();
2450 if (NNS) {
2451 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2452 /*FIXME:*/SourceRange(Loc),
2453 ObjectType,
2454 FirstQualifierInScope);
2455 if (!NNS) return TemplateName();
2456
2457 // These apply to the scope specifier, not the template.
2458 ObjectType = QualType();
2459 FirstQualifierInScope = 0;
2460 }
Mike Stump11289f42009-09-09 15:08:12 +00002461
Douglas Gregor71dc5092009-08-06 06:41:21 +00002462 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002463 NNS == DTN->getQualifier() &&
2464 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002465 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002466
Douglas Gregora5614c52010-09-08 23:56:00 +00002467 if (DTN->isIdentifier()) {
2468 // FIXME: Bad range
2469 SourceRange QualifierRange(getDerived().getBaseLocation());
2470 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2471 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002472 ObjectType,
2473 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002474 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002475
2476 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002477 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002478 }
Mike Stump11289f42009-09-09 15:08:12 +00002479
Douglas Gregor71dc5092009-08-06 06:41:21 +00002480 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002481 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002482 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002483 if (!TransTemplate)
2484 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002485
Douglas Gregor71dc5092009-08-06 06:41:21 +00002486 if (!getDerived().AlwaysRebuild() &&
2487 TransTemplate == Template)
2488 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002489
Douglas Gregor71dc5092009-08-06 06:41:21 +00002490 return TemplateName(TransTemplate);
2491 }
Mike Stump11289f42009-09-09 15:08:12 +00002492
John McCalle66edc12009-11-24 19:00:30 +00002493 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002494 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002495 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002496}
2497
2498template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002499void TreeTransform<Derived>::InventTemplateArgumentLoc(
2500 const TemplateArgument &Arg,
2501 TemplateArgumentLoc &Output) {
2502 SourceLocation Loc = getDerived().getBaseLocation();
2503 switch (Arg.getKind()) {
2504 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002505 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002506 break;
2507
2508 case TemplateArgument::Type:
2509 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002510 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002511
John McCall0ad16662009-10-29 08:12:44 +00002512 break;
2513
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002514 case TemplateArgument::Template:
2515 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2516 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002517
John McCall0ad16662009-10-29 08:12:44 +00002518 case TemplateArgument::Expression:
2519 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2520 break;
2521
2522 case TemplateArgument::Declaration:
2523 case TemplateArgument::Integral:
2524 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002525 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002526 break;
2527 }
2528}
2529
2530template<typename Derived>
2531bool TreeTransform<Derived>::TransformTemplateArgument(
2532 const TemplateArgumentLoc &Input,
2533 TemplateArgumentLoc &Output) {
2534 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002535 switch (Arg.getKind()) {
2536 case TemplateArgument::Null:
2537 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002538 Output = Input;
2539 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002540
Douglas Gregore922c772009-08-04 22:27:00 +00002541 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002542 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002543 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002544 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002545
2546 DI = getDerived().TransformType(DI);
2547 if (!DI) return true;
2548
2549 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2550 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002551 }
Mike Stump11289f42009-09-09 15:08:12 +00002552
Douglas Gregore922c772009-08-04 22:27:00 +00002553 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002554 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002555 DeclarationName Name;
2556 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2557 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002558 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002559 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002560 if (!D) return true;
2561
John McCall0d07eb32009-10-29 18:45:58 +00002562 Expr *SourceExpr = Input.getSourceDeclExpression();
2563 if (SourceExpr) {
2564 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002565 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002566 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002567 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002568 }
2569
2570 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002571 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002572 }
Mike Stump11289f42009-09-09 15:08:12 +00002573
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002574 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002575 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002576 TemplateName Template
2577 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2578 if (Template.isNull())
2579 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002580
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002581 Output = TemplateArgumentLoc(TemplateArgument(Template),
2582 Input.getTemplateQualifierRange(),
2583 Input.getTemplateNameLoc());
2584 return false;
2585 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002586
Douglas Gregore922c772009-08-04 22:27:00 +00002587 case TemplateArgument::Expression: {
2588 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002589 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002590 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002591
John McCall0ad16662009-10-29 08:12:44 +00002592 Expr *InputExpr = Input.getSourceExpression();
2593 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2594
John McCalldadc5752010-08-24 06:29:42 +00002595 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002596 = getDerived().TransformExpr(InputExpr);
2597 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002598 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002599 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002600 }
Mike Stump11289f42009-09-09 15:08:12 +00002601
Douglas Gregore922c772009-08-04 22:27:00 +00002602 case TemplateArgument::Pack: {
2603 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2604 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002605 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002606 AEnd = Arg.pack_end();
2607 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002608
John McCall0ad16662009-10-29 08:12:44 +00002609 // FIXME: preserve source information here when we start
2610 // caring about parameter packs.
2611
John McCall0d07eb32009-10-29 18:45:58 +00002612 TemplateArgumentLoc InputArg;
2613 TemplateArgumentLoc OutputArg;
2614 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2615 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002616 return true;
2617
John McCall0d07eb32009-10-29 18:45:58 +00002618 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002619 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002620
2621 TemplateArgument *TransformedArgsPtr
2622 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2623 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2624 TransformedArgsPtr);
2625 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2626 TransformedArgs.size()),
2627 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002628 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002629 }
2630 }
Mike Stump11289f42009-09-09 15:08:12 +00002631
Douglas Gregore922c772009-08-04 22:27:00 +00002632 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002633 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002634}
2635
Douglas Gregorfe921a72010-12-20 23:36:19 +00002636/// \brief Iterator adaptor that invents template argument location information
2637/// for each of the template arguments in its underlying iterator.
2638template<typename Derived, typename InputIterator>
2639class TemplateArgumentLocInventIterator {
2640 TreeTransform<Derived> &Self;
2641 InputIterator Iter;
2642
2643public:
2644 typedef TemplateArgumentLoc value_type;
2645 typedef TemplateArgumentLoc reference;
2646 typedef typename std::iterator_traits<InputIterator>::difference_type
2647 difference_type;
2648 typedef std::input_iterator_tag iterator_category;
2649
2650 class pointer {
2651 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002652
Douglas Gregorfe921a72010-12-20 23:36:19 +00002653 public:
2654 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2655
2656 const TemplateArgumentLoc *operator->() const { return &Arg; }
2657 };
2658
2659 TemplateArgumentLocInventIterator() { }
2660
2661 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2662 InputIterator Iter)
2663 : Self(Self), Iter(Iter) { }
2664
2665 TemplateArgumentLocInventIterator &operator++() {
2666 ++Iter;
2667 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002668 }
2669
Douglas Gregorfe921a72010-12-20 23:36:19 +00002670 TemplateArgumentLocInventIterator operator++(int) {
2671 TemplateArgumentLocInventIterator Old(*this);
2672 ++(*this);
2673 return Old;
2674 }
2675
2676 reference operator*() const {
2677 TemplateArgumentLoc Result;
2678 Self.InventTemplateArgumentLoc(*Iter, Result);
2679 return Result;
2680 }
2681
2682 pointer operator->() const { return pointer(**this); }
2683
2684 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2685 const TemplateArgumentLocInventIterator &Y) {
2686 return X.Iter == Y.Iter;
2687 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002688
Douglas Gregorfe921a72010-12-20 23:36:19 +00002689 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2690 const TemplateArgumentLocInventIterator &Y) {
2691 return X.Iter != Y.Iter;
2692 }
2693};
2694
Douglas Gregor42cafa82010-12-20 17:42:22 +00002695template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002696template<typename InputIterator>
2697bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2698 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002699 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002700 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002701 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002702 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002703
2704 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2705 // Unpack argument packs, which we translate them into separate
2706 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002707 // FIXME: We could do much better if we could guarantee that the
2708 // TemplateArgumentLocInfo for the pack expansion would be usable for
2709 // all of the template arguments in the argument pack.
2710 typedef TemplateArgumentLocInventIterator<Derived,
2711 TemplateArgument::pack_iterator>
2712 PackLocIterator;
2713 if (TransformTemplateArguments(PackLocIterator(*this,
2714 In.getArgument().pack_begin()),
2715 PackLocIterator(*this,
2716 In.getArgument().pack_end()),
2717 Outputs))
2718 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002719
2720 continue;
2721 }
2722
2723 if (In.getArgument().isPackExpansion()) {
2724 // We have a pack expansion, for which we will be substituting into
2725 // the pattern.
2726 SourceLocation Ellipsis;
2727 TemplateArgumentLoc Pattern
2728 = In.getPackExpansionPattern(Ellipsis, getSema().Context);
2729
2730 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2731 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2732 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2733
2734 // Determine whether the set of unexpanded parameter packs can and should
2735 // be expanded.
2736 bool Expand = true;
2737 unsigned NumExpansions = 0;
2738 if (getDerived().TryExpandParameterPacks(Ellipsis,
2739 Pattern.getSourceRange(),
2740 Unexpanded.data(),
2741 Unexpanded.size(),
2742 Expand, NumExpansions))
2743 return true;
2744
2745 if (!Expand) {
2746 // The transform has determined that we should perform a simple
2747 // transformation on the pack expansion, producing another pack
2748 // expansion.
2749 TemplateArgumentLoc OutPattern;
2750 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2751 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2752 return true;
2753
2754 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis);
2755 if (Out.getArgument().isNull())
2756 return true;
2757
2758 Outputs.addArgument(Out);
2759 continue;
2760 }
2761
2762 // The transform has determined that we should perform an elementwise
2763 // expansion of the pattern. Do so.
2764 for (unsigned I = 0; I != NumExpansions; ++I) {
2765 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2766
2767 if (getDerived().TransformTemplateArgument(Pattern, Out))
2768 return true;
2769
2770 Outputs.addArgument(Out);
2771 }
2772
2773 continue;
2774 }
2775
2776 // The simple case:
2777 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00002778 return true;
2779
2780 Outputs.addArgument(Out);
2781 }
2782
2783 return false;
2784
2785}
2786
Douglas Gregord6ff3322009-08-04 16:50:30 +00002787//===----------------------------------------------------------------------===//
2788// Type transformation
2789//===----------------------------------------------------------------------===//
2790
2791template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002792QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002793 if (getDerived().AlreadyTransformed(T))
2794 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002795
John McCall550e0c22009-10-21 00:40:46 +00002796 // Temporary workaround. All of these transformations should
2797 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002798 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002799 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002800
John McCall31f82722010-11-12 08:19:04 +00002801 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002802
John McCall550e0c22009-10-21 00:40:46 +00002803 if (!NewDI)
2804 return QualType();
2805
2806 return NewDI->getType();
2807}
2808
2809template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002810TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002811 if (getDerived().AlreadyTransformed(DI->getType()))
2812 return DI;
2813
2814 TypeLocBuilder TLB;
2815
2816 TypeLoc TL = DI->getTypeLoc();
2817 TLB.reserve(TL.getFullDataSize());
2818
John McCall31f82722010-11-12 08:19:04 +00002819 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00002820 if (Result.isNull())
2821 return 0;
2822
John McCallbcd03502009-12-07 02:54:59 +00002823 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002824}
2825
2826template<typename Derived>
2827QualType
John McCall31f82722010-11-12 08:19:04 +00002828TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00002829 switch (T.getTypeLocClass()) {
2830#define ABSTRACT_TYPELOC(CLASS, PARENT)
2831#define TYPELOC(CLASS, PARENT) \
2832 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00002833 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00002834#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002835 }
Mike Stump11289f42009-09-09 15:08:12 +00002836
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002837 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002838 return QualType();
2839}
2840
2841/// FIXME: By default, this routine adds type qualifiers only to types
2842/// that can have qualifiers, and silently suppresses those qualifiers
2843/// that are not permitted (e.g., qualifiers on reference or function
2844/// types). This is the right thing for template instantiation, but
2845/// probably not for other clients.
2846template<typename Derived>
2847QualType
2848TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002849 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002850 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002851
John McCall31f82722010-11-12 08:19:04 +00002852 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00002853 if (Result.isNull())
2854 return QualType();
2855
2856 // Silently suppress qualifiers if the result type can't be qualified.
2857 // FIXME: this is the right thing for template instantiation, but
2858 // probably not for other clients.
2859 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002860 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002861
John McCallcb0f89a2010-06-05 06:41:15 +00002862 if (!Quals.empty()) {
2863 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2864 TLB.push<QualifiedTypeLoc>(Result);
2865 // No location information to preserve.
2866 }
John McCall550e0c22009-10-21 00:40:46 +00002867
2868 return Result;
2869}
2870
John McCall31f82722010-11-12 08:19:04 +00002871/// \brief Transforms a type that was written in a scope specifier,
2872/// given an object type, the results of unqualified lookup, and
2873/// an already-instantiated prefix.
2874///
2875/// The object type is provided iff the scope specifier qualifies the
2876/// member of a dependent member-access expression. The prefix is
2877/// provided iff the the scope specifier in which this appears has a
2878/// prefix.
2879///
2880/// This is private to TreeTransform.
2881template<typename Derived>
2882QualType
2883TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
2884 QualType ObjectType,
2885 NamedDecl *UnqualLookup,
2886 NestedNameSpecifier *Prefix) {
2887 if (getDerived().AlreadyTransformed(T))
2888 return T;
2889
2890 TypeSourceInfo *TSI =
2891 SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
2892
2893 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
2894 UnqualLookup, Prefix);
2895 if (!TSI) return QualType();
2896 return TSI->getType();
2897}
2898
2899template<typename Derived>
2900TypeSourceInfo *
2901TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
2902 QualType ObjectType,
2903 NamedDecl *UnqualLookup,
2904 NestedNameSpecifier *Prefix) {
2905 // TODO: in some cases, we might be some verification to do here.
2906 if (ObjectType.isNull())
2907 return getDerived().TransformType(TSI);
2908
2909 QualType T = TSI->getType();
2910 if (getDerived().AlreadyTransformed(T))
2911 return TSI;
2912
2913 TypeLocBuilder TLB;
2914 QualType Result;
2915
2916 if (isa<TemplateSpecializationType>(T)) {
2917 TemplateSpecializationTypeLoc TL
2918 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2919
2920 TemplateName Template =
2921 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
2922 ObjectType, UnqualLookup);
2923 if (Template.isNull()) return 0;
2924
2925 Result = getDerived()
2926 .TransformTemplateSpecializationType(TLB, TL, Template);
2927 } else if (isa<DependentTemplateSpecializationType>(T)) {
2928 DependentTemplateSpecializationTypeLoc TL
2929 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2930
2931 Result = getDerived()
2932 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
2933 } else {
2934 // Nothing special needs to be done for these.
2935 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
2936 }
2937
2938 if (Result.isNull()) return 0;
2939 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
2940}
2941
John McCall550e0c22009-10-21 00:40:46 +00002942template <class TyLoc> static inline
2943QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2944 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2945 NewT.setNameLoc(T.getNameLoc());
2946 return T.getType();
2947}
2948
John McCall550e0c22009-10-21 00:40:46 +00002949template<typename Derived>
2950QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002951 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002952 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2953 NewT.setBuiltinLoc(T.getBuiltinLoc());
2954 if (T.needsExtraLocalData())
2955 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2956 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002957}
Mike Stump11289f42009-09-09 15:08:12 +00002958
Douglas Gregord6ff3322009-08-04 16:50:30 +00002959template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002960QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002961 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00002962 // FIXME: recurse?
2963 return TransformTypeSpecType(TLB, T);
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>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002968 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002969 QualType PointeeType
2970 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002971 if (PointeeType.isNull())
2972 return QualType();
2973
2974 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002975 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002976 // A dependent pointer type 'T *' has is being transformed such
2977 // that an Objective-C class type is being replaced for 'T'. The
2978 // resulting pointer type is an ObjCObjectPointerType, not a
2979 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002980 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002981
John McCall8b07ec22010-05-15 11:32:37 +00002982 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2983 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002984 return Result;
2985 }
John McCall31f82722010-11-12 08:19:04 +00002986
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002987 if (getDerived().AlwaysRebuild() ||
2988 PointeeType != TL.getPointeeLoc().getType()) {
2989 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2990 if (Result.isNull())
2991 return QualType();
2992 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002993
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002994 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2995 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002996 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002997}
Mike Stump11289f42009-09-09 15:08:12 +00002998
2999template<typename Derived>
3000QualType
John McCall550e0c22009-10-21 00:40:46 +00003001TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003002 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003003 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003004 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3005 if (PointeeType.isNull())
3006 return QualType();
3007
3008 QualType Result = TL.getType();
3009 if (getDerived().AlwaysRebuild() ||
3010 PointeeType != TL.getPointeeLoc().getType()) {
3011 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003012 TL.getSigilLoc());
3013 if (Result.isNull())
3014 return QualType();
3015 }
3016
Douglas Gregor049211a2010-04-22 16:50:51 +00003017 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003018 NewT.setSigilLoc(TL.getSigilLoc());
3019 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003020}
3021
John McCall70dd5f62009-10-30 00:06:24 +00003022/// Transforms a reference type. Note that somewhat paradoxically we
3023/// don't care whether the type itself is an l-value type or an r-value
3024/// type; we only care if the type was *written* as an l-value type
3025/// or an r-value type.
3026template<typename Derived>
3027QualType
3028TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003029 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003030 const ReferenceType *T = TL.getTypePtr();
3031
3032 // Note that this works with the pointee-as-written.
3033 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3034 if (PointeeType.isNull())
3035 return QualType();
3036
3037 QualType Result = TL.getType();
3038 if (getDerived().AlwaysRebuild() ||
3039 PointeeType != T->getPointeeTypeAsWritten()) {
3040 Result = getDerived().RebuildReferenceType(PointeeType,
3041 T->isSpelledAsLValue(),
3042 TL.getSigilLoc());
3043 if (Result.isNull())
3044 return QualType();
3045 }
3046
3047 // r-value references can be rebuilt as l-value references.
3048 ReferenceTypeLoc NewTL;
3049 if (isa<LValueReferenceType>(Result))
3050 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3051 else
3052 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3053 NewTL.setSigilLoc(TL.getSigilLoc());
3054
3055 return Result;
3056}
3057
Mike Stump11289f42009-09-09 15:08:12 +00003058template<typename Derived>
3059QualType
John McCall550e0c22009-10-21 00:40:46 +00003060TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003061 LValueReferenceTypeLoc TL) {
3062 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003063}
3064
Mike Stump11289f42009-09-09 15:08:12 +00003065template<typename Derived>
3066QualType
John McCall550e0c22009-10-21 00:40:46 +00003067TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003068 RValueReferenceTypeLoc TL) {
3069 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003070}
Mike Stump11289f42009-09-09 15:08:12 +00003071
Douglas Gregord6ff3322009-08-04 16:50:30 +00003072template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003073QualType
John McCall550e0c22009-10-21 00:40:46 +00003074TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003075 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003076 MemberPointerType *T = TL.getTypePtr();
3077
3078 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003079 if (PointeeType.isNull())
3080 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003081
John McCall550e0c22009-10-21 00:40:46 +00003082 // TODO: preserve source information for this.
3083 QualType ClassType
3084 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003085 if (ClassType.isNull())
3086 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003087
John McCall550e0c22009-10-21 00:40:46 +00003088 QualType Result = TL.getType();
3089 if (getDerived().AlwaysRebuild() ||
3090 PointeeType != T->getPointeeType() ||
3091 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00003092 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3093 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003094 if (Result.isNull())
3095 return QualType();
3096 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003097
John McCall550e0c22009-10-21 00:40:46 +00003098 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3099 NewTL.setSigilLoc(TL.getSigilLoc());
3100
3101 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003102}
3103
Mike Stump11289f42009-09-09 15:08:12 +00003104template<typename Derived>
3105QualType
John McCall550e0c22009-10-21 00:40:46 +00003106TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003107 ConstantArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003108 ConstantArrayType *T = TL.getTypePtr();
3109 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003110 if (ElementType.isNull())
3111 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003112
John McCall550e0c22009-10-21 00:40:46 +00003113 QualType Result = TL.getType();
3114 if (getDerived().AlwaysRebuild() ||
3115 ElementType != T->getElementType()) {
3116 Result = getDerived().RebuildConstantArrayType(ElementType,
3117 T->getSizeModifier(),
3118 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003119 T->getIndexTypeCVRQualifiers(),
3120 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003121 if (Result.isNull())
3122 return QualType();
3123 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003124
John McCall550e0c22009-10-21 00:40:46 +00003125 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3126 NewTL.setLBracketLoc(TL.getLBracketLoc());
3127 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003128
John McCall550e0c22009-10-21 00:40:46 +00003129 Expr *Size = TL.getSizeExpr();
3130 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003131 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003132 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3133 }
3134 NewTL.setSizeExpr(Size);
3135
3136 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003137}
Mike Stump11289f42009-09-09 15:08:12 +00003138
Douglas Gregord6ff3322009-08-04 16:50:30 +00003139template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003140QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003141 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003142 IncompleteArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003143 IncompleteArrayType *T = TL.getTypePtr();
3144 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003145 if (ElementType.isNull())
3146 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003147
John McCall550e0c22009-10-21 00:40:46 +00003148 QualType Result = TL.getType();
3149 if (getDerived().AlwaysRebuild() ||
3150 ElementType != T->getElementType()) {
3151 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003152 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003153 T->getIndexTypeCVRQualifiers(),
3154 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003155 if (Result.isNull())
3156 return QualType();
3157 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003158
John McCall550e0c22009-10-21 00:40:46 +00003159 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3160 NewTL.setLBracketLoc(TL.getLBracketLoc());
3161 NewTL.setRBracketLoc(TL.getRBracketLoc());
3162 NewTL.setSizeExpr(0);
3163
3164 return Result;
3165}
3166
3167template<typename Derived>
3168QualType
3169TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003170 VariableArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003171 VariableArrayType *T = TL.getTypePtr();
3172 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3173 if (ElementType.isNull())
3174 return QualType();
3175
3176 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003177 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003178
John McCalldadc5752010-08-24 06:29:42 +00003179 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003180 = getDerived().TransformExpr(T->getSizeExpr());
3181 if (SizeResult.isInvalid())
3182 return QualType();
3183
John McCallb268a282010-08-23 23:25:46 +00003184 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003185
3186 QualType Result = TL.getType();
3187 if (getDerived().AlwaysRebuild() ||
3188 ElementType != T->getElementType() ||
3189 Size != T->getSizeExpr()) {
3190 Result = getDerived().RebuildVariableArrayType(ElementType,
3191 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003192 Size,
John McCall550e0c22009-10-21 00:40:46 +00003193 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003194 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003195 if (Result.isNull())
3196 return QualType();
3197 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003198
John McCall550e0c22009-10-21 00:40:46 +00003199 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3200 NewTL.setLBracketLoc(TL.getLBracketLoc());
3201 NewTL.setRBracketLoc(TL.getRBracketLoc());
3202 NewTL.setSizeExpr(Size);
3203
3204 return Result;
3205}
3206
3207template<typename Derived>
3208QualType
3209TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003210 DependentSizedArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003211 DependentSizedArrayType *T = TL.getTypePtr();
3212 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3213 if (ElementType.isNull())
3214 return QualType();
3215
3216 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003217 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003218
John McCalldadc5752010-08-24 06:29:42 +00003219 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003220 = getDerived().TransformExpr(T->getSizeExpr());
3221 if (SizeResult.isInvalid())
3222 return QualType();
3223
3224 Expr *Size = static_cast<Expr*>(SizeResult.get());
3225
3226 QualType Result = TL.getType();
3227 if (getDerived().AlwaysRebuild() ||
3228 ElementType != T->getElementType() ||
3229 Size != T->getSizeExpr()) {
3230 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3231 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003232 Size,
John McCall550e0c22009-10-21 00:40:46 +00003233 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003234 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003235 if (Result.isNull())
3236 return QualType();
3237 }
3238 else SizeResult.take();
3239
3240 // We might have any sort of array type now, but fortunately they
3241 // all have the same location layout.
3242 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3243 NewTL.setLBracketLoc(TL.getLBracketLoc());
3244 NewTL.setRBracketLoc(TL.getRBracketLoc());
3245 NewTL.setSizeExpr(Size);
3246
3247 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003248}
Mike Stump11289f42009-09-09 15:08:12 +00003249
3250template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003251QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003252 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003253 DependentSizedExtVectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003254 DependentSizedExtVectorType *T = TL.getTypePtr();
3255
3256 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003257 QualType ElementType = getDerived().TransformType(T->getElementType());
3258 if (ElementType.isNull())
3259 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003260
Douglas Gregore922c772009-08-04 22:27:00 +00003261 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003262 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003263
John McCalldadc5752010-08-24 06:29:42 +00003264 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003265 if (Size.isInvalid())
3266 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003267
John McCall550e0c22009-10-21 00:40:46 +00003268 QualType Result = TL.getType();
3269 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003270 ElementType != T->getElementType() ||
3271 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003272 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003273 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003274 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003275 if (Result.isNull())
3276 return QualType();
3277 }
John McCall550e0c22009-10-21 00:40:46 +00003278
3279 // Result might be dependent or not.
3280 if (isa<DependentSizedExtVectorType>(Result)) {
3281 DependentSizedExtVectorTypeLoc NewTL
3282 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3283 NewTL.setNameLoc(TL.getNameLoc());
3284 } else {
3285 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3286 NewTL.setNameLoc(TL.getNameLoc());
3287 }
3288
3289 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003290}
Mike Stump11289f42009-09-09 15:08:12 +00003291
3292template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003293QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003294 VectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003295 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003296 QualType ElementType = getDerived().TransformType(T->getElementType());
3297 if (ElementType.isNull())
3298 return QualType();
3299
John McCall550e0c22009-10-21 00:40:46 +00003300 QualType Result = TL.getType();
3301 if (getDerived().AlwaysRebuild() ||
3302 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003303 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003304 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003305 if (Result.isNull())
3306 return QualType();
3307 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003308
John McCall550e0c22009-10-21 00:40:46 +00003309 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3310 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003311
John McCall550e0c22009-10-21 00:40:46 +00003312 return Result;
3313}
3314
3315template<typename Derived>
3316QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003317 ExtVectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003318 VectorType *T = TL.getTypePtr();
3319 QualType ElementType = getDerived().TransformType(T->getElementType());
3320 if (ElementType.isNull())
3321 return QualType();
3322
3323 QualType Result = TL.getType();
3324 if (getDerived().AlwaysRebuild() ||
3325 ElementType != T->getElementType()) {
3326 Result = getDerived().RebuildExtVectorType(ElementType,
3327 T->getNumElements(),
3328 /*FIXME*/ SourceLocation());
3329 if (Result.isNull())
3330 return QualType();
3331 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003332
John McCall550e0c22009-10-21 00:40:46 +00003333 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3334 NewTL.setNameLoc(TL.getNameLoc());
3335
3336 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003337}
Mike Stump11289f42009-09-09 15:08:12 +00003338
3339template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003340ParmVarDecl *
3341TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
3342 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
3343 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
3344 if (!NewDI)
3345 return 0;
3346
3347 if (NewDI == OldDI)
3348 return OldParm;
3349 else
3350 return ParmVarDecl::Create(SemaRef.Context,
3351 OldParm->getDeclContext(),
3352 OldParm->getLocation(),
3353 OldParm->getIdentifier(),
3354 NewDI->getType(),
3355 NewDI,
3356 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003357 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003358 /* DefArg */ NULL);
3359}
3360
3361template<typename Derived>
3362bool TreeTransform<Derived>::
3363 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
3364 llvm::SmallVectorImpl<QualType> &PTypes,
3365 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
3366 FunctionProtoType *T = TL.getTypePtr();
3367
3368 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3369 ParmVarDecl *OldParm = TL.getArg(i);
3370
3371 QualType NewType;
3372 ParmVarDecl *NewParm;
3373
3374 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00003375 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
3376 if (!NewParm)
3377 return true;
3378 NewType = NewParm->getType();
3379
3380 // Deal with the possibility that we don't have a parameter
3381 // declaration for this parameter.
3382 } else {
3383 NewParm = 0;
3384
3385 QualType OldType = T->getArgType(i);
3386 NewType = getDerived().TransformType(OldType);
3387 if (NewType.isNull())
3388 return true;
3389 }
3390
3391 PTypes.push_back(NewType);
3392 PVars.push_back(NewParm);
3393 }
3394
3395 return false;
3396}
3397
3398template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003399QualType
John McCall550e0c22009-10-21 00:40:46 +00003400TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003401 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003402 // Transform the parameters and return type.
3403 //
3404 // We instantiate in source order, with the return type first followed by
3405 // the parameters, because users tend to expect this (even if they shouldn't
3406 // rely on it!).
3407 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003408 // When the function has a trailing return type, we instantiate the
3409 // parameters before the return type, since the return type can then refer
3410 // to the parameters themselves (via decltype, sizeof, etc.).
3411 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003412 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003413 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor14cf7522010-04-30 18:55:50 +00003414 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003415
Douglas Gregor7fb25412010-10-01 18:44:50 +00003416 QualType ResultType;
3417
3418 if (TL.getTrailingReturn()) {
3419 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3420 return QualType();
3421
3422 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3423 if (ResultType.isNull())
3424 return QualType();
3425 }
3426 else {
3427 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3428 if (ResultType.isNull())
3429 return QualType();
3430
3431 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3432 return QualType();
3433 }
3434
John McCall550e0c22009-10-21 00:40:46 +00003435 QualType Result = TL.getType();
3436 if (getDerived().AlwaysRebuild() ||
3437 ResultType != T->getResultType() ||
3438 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3439 Result = getDerived().RebuildFunctionProtoType(ResultType,
3440 ParamTypes.data(),
3441 ParamTypes.size(),
3442 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003443 T->getTypeQuals(),
3444 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003445 if (Result.isNull())
3446 return QualType();
3447 }
Mike Stump11289f42009-09-09 15:08:12 +00003448
John McCall550e0c22009-10-21 00:40:46 +00003449 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3450 NewTL.setLParenLoc(TL.getLParenLoc());
3451 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003452 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003453 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3454 NewTL.setArg(i, ParamDecls[i]);
3455
3456 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003457}
Mike Stump11289f42009-09-09 15:08:12 +00003458
Douglas Gregord6ff3322009-08-04 16:50:30 +00003459template<typename Derived>
3460QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003461 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003462 FunctionNoProtoTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003463 FunctionNoProtoType *T = TL.getTypePtr();
3464 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3465 if (ResultType.isNull())
3466 return QualType();
3467
3468 QualType Result = TL.getType();
3469 if (getDerived().AlwaysRebuild() ||
3470 ResultType != T->getResultType())
3471 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3472
3473 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3474 NewTL.setLParenLoc(TL.getLParenLoc());
3475 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003476 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003477
3478 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003479}
Mike Stump11289f42009-09-09 15:08:12 +00003480
John McCallb96ec562009-12-04 22:46:56 +00003481template<typename Derived> QualType
3482TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003483 UnresolvedUsingTypeLoc TL) {
John McCallb96ec562009-12-04 22:46:56 +00003484 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003485 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003486 if (!D)
3487 return QualType();
3488
3489 QualType Result = TL.getType();
3490 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3491 Result = getDerived().RebuildUnresolvedUsingType(D);
3492 if (Result.isNull())
3493 return QualType();
3494 }
3495
3496 // We might get an arbitrary type spec type back. We should at
3497 // least always get a type spec type, though.
3498 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3499 NewTL.setNameLoc(TL.getNameLoc());
3500
3501 return Result;
3502}
3503
Douglas Gregord6ff3322009-08-04 16:50:30 +00003504template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003505QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003506 TypedefTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003507 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003508 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003509 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3510 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003511 if (!Typedef)
3512 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003513
John McCall550e0c22009-10-21 00:40:46 +00003514 QualType Result = TL.getType();
3515 if (getDerived().AlwaysRebuild() ||
3516 Typedef != T->getDecl()) {
3517 Result = getDerived().RebuildTypedefType(Typedef);
3518 if (Result.isNull())
3519 return QualType();
3520 }
Mike Stump11289f42009-09-09 15:08:12 +00003521
John McCall550e0c22009-10-21 00:40:46 +00003522 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3523 NewTL.setNameLoc(TL.getNameLoc());
3524
3525 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003526}
Mike Stump11289f42009-09-09 15:08:12 +00003527
Douglas Gregord6ff3322009-08-04 16:50:30 +00003528template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003529QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003530 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003531 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003532 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003533
John McCalldadc5752010-08-24 06:29:42 +00003534 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003535 if (E.isInvalid())
3536 return QualType();
3537
John McCall550e0c22009-10-21 00:40:46 +00003538 QualType Result = TL.getType();
3539 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003540 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003541 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003542 if (Result.isNull())
3543 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003544 }
John McCall550e0c22009-10-21 00:40:46 +00003545 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003546
John McCall550e0c22009-10-21 00:40:46 +00003547 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003548 NewTL.setTypeofLoc(TL.getTypeofLoc());
3549 NewTL.setLParenLoc(TL.getLParenLoc());
3550 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003551
3552 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003553}
Mike Stump11289f42009-09-09 15:08:12 +00003554
3555template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003556QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003557 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003558 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3559 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3560 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003561 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003562
John McCall550e0c22009-10-21 00:40:46 +00003563 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003564 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3565 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003566 if (Result.isNull())
3567 return QualType();
3568 }
Mike Stump11289f42009-09-09 15:08:12 +00003569
John McCall550e0c22009-10-21 00:40:46 +00003570 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003571 NewTL.setTypeofLoc(TL.getTypeofLoc());
3572 NewTL.setLParenLoc(TL.getLParenLoc());
3573 NewTL.setRParenLoc(TL.getRParenLoc());
3574 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003575
3576 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003577}
Mike Stump11289f42009-09-09 15:08:12 +00003578
3579template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003580QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003581 DecltypeTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003582 DecltypeType *T = TL.getTypePtr();
3583
Douglas Gregore922c772009-08-04 22:27:00 +00003584 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003585 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003586
John McCalldadc5752010-08-24 06:29:42 +00003587 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003588 if (E.isInvalid())
3589 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003590
John McCall550e0c22009-10-21 00:40:46 +00003591 QualType Result = TL.getType();
3592 if (getDerived().AlwaysRebuild() ||
3593 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003594 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003595 if (Result.isNull())
3596 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003597 }
John McCall550e0c22009-10-21 00:40:46 +00003598 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003599
John McCall550e0c22009-10-21 00:40:46 +00003600 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3601 NewTL.setNameLoc(TL.getNameLoc());
3602
3603 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003604}
3605
3606template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003607QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003608 RecordTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003609 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003610 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003611 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3612 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003613 if (!Record)
3614 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003615
John McCall550e0c22009-10-21 00:40:46 +00003616 QualType Result = TL.getType();
3617 if (getDerived().AlwaysRebuild() ||
3618 Record != T->getDecl()) {
3619 Result = getDerived().RebuildRecordType(Record);
3620 if (Result.isNull())
3621 return QualType();
3622 }
Mike Stump11289f42009-09-09 15:08:12 +00003623
John McCall550e0c22009-10-21 00:40:46 +00003624 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3625 NewTL.setNameLoc(TL.getNameLoc());
3626
3627 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003628}
Mike Stump11289f42009-09-09 15:08:12 +00003629
3630template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003631QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003632 EnumTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003633 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003634 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003635 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3636 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003637 if (!Enum)
3638 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003639
John McCall550e0c22009-10-21 00:40:46 +00003640 QualType Result = TL.getType();
3641 if (getDerived().AlwaysRebuild() ||
3642 Enum != T->getDecl()) {
3643 Result = getDerived().RebuildEnumType(Enum);
3644 if (Result.isNull())
3645 return QualType();
3646 }
Mike Stump11289f42009-09-09 15:08:12 +00003647
John McCall550e0c22009-10-21 00:40:46 +00003648 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3649 NewTL.setNameLoc(TL.getNameLoc());
3650
3651 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003652}
John McCallfcc33b02009-09-05 00:15:47 +00003653
John McCalle78aac42010-03-10 03:28:59 +00003654template<typename Derived>
3655QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3656 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003657 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00003658 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3659 TL.getTypePtr()->getDecl());
3660 if (!D) return QualType();
3661
3662 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3663 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3664 return T;
3665}
3666
Mike Stump11289f42009-09-09 15:08:12 +00003667
Douglas Gregord6ff3322009-08-04 16:50:30 +00003668template<typename Derived>
3669QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003670 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003671 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003672 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003673}
3674
Mike Stump11289f42009-09-09 15:08:12 +00003675template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003676QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003677 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003678 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003679 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003680}
3681
3682template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003683QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003684 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003685 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00003686 const TemplateSpecializationType *T = TL.getTypePtr();
3687
Mike Stump11289f42009-09-09 15:08:12 +00003688 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00003689 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003690 if (Template.isNull())
3691 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003692
John McCall31f82722010-11-12 08:19:04 +00003693 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
3694}
3695
Douglas Gregorfe921a72010-12-20 23:36:19 +00003696namespace {
3697 /// \brief Simple iterator that traverses the template arguments in a
3698 /// container that provides a \c getArgLoc() member function.
3699 ///
3700 /// This iterator is intended to be used with the iterator form of
3701 /// \c TreeTransform<Derived>::TransformTemplateArguments().
3702 template<typename ArgLocContainer>
3703 class TemplateArgumentLocContainerIterator {
3704 ArgLocContainer *Container;
3705 unsigned Index;
3706
3707 public:
3708 typedef TemplateArgumentLoc value_type;
3709 typedef TemplateArgumentLoc reference;
3710 typedef int difference_type;
3711 typedef std::input_iterator_tag iterator_category;
3712
3713 class pointer {
3714 TemplateArgumentLoc Arg;
3715
3716 public:
3717 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3718
3719 const TemplateArgumentLoc *operator->() const {
3720 return &Arg;
3721 }
3722 };
3723
3724
3725 TemplateArgumentLocContainerIterator() {}
3726
3727 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
3728 unsigned Index)
3729 : Container(&Container), Index(Index) { }
3730
3731 TemplateArgumentLocContainerIterator &operator++() {
3732 ++Index;
3733 return *this;
3734 }
3735
3736 TemplateArgumentLocContainerIterator operator++(int) {
3737 TemplateArgumentLocContainerIterator Old(*this);
3738 ++(*this);
3739 return Old;
3740 }
3741
3742 TemplateArgumentLoc operator*() const {
3743 return Container->getArgLoc(Index);
3744 }
3745
3746 pointer operator->() const {
3747 return pointer(Container->getArgLoc(Index));
3748 }
3749
3750 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00003751 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003752 return X.Container == Y.Container && X.Index == Y.Index;
3753 }
3754
3755 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00003756 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003757 return !(X == Y);
3758 }
3759 };
3760}
3761
3762
John McCall31f82722010-11-12 08:19:04 +00003763template <typename Derived>
3764QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3765 TypeLocBuilder &TLB,
3766 TemplateSpecializationTypeLoc TL,
3767 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00003768 TemplateArgumentListInfo NewTemplateArgs;
3769 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3770 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00003771 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
3772 ArgIterator;
3773 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
3774 ArgIterator(TL, TL.getNumArgs()),
3775 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003776 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003777
John McCall0ad16662009-10-29 08:12:44 +00003778 // FIXME: maybe don't rebuild if all the template arguments are the same.
3779
3780 QualType Result =
3781 getDerived().RebuildTemplateSpecializationType(Template,
3782 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003783 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003784
3785 if (!Result.isNull()) {
3786 TemplateSpecializationTypeLoc NewTL
3787 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3788 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3789 NewTL.setLAngleLoc(TL.getLAngleLoc());
3790 NewTL.setRAngleLoc(TL.getRAngleLoc());
3791 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3792 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003793 }
Mike Stump11289f42009-09-09 15:08:12 +00003794
John McCall0ad16662009-10-29 08:12:44 +00003795 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003796}
Mike Stump11289f42009-09-09 15:08:12 +00003797
3798template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003799QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003800TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003801 ElaboratedTypeLoc TL) {
Abramo Bagnara6150c882010-05-11 21:36:43 +00003802 ElaboratedType *T = TL.getTypePtr();
3803
3804 NestedNameSpecifier *NNS = 0;
3805 // NOTE: the qualifier in an ElaboratedType is optional.
3806 if (T->getQualifier() != 0) {
3807 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003808 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00003809 if (!NNS)
3810 return QualType();
3811 }
Mike Stump11289f42009-09-09 15:08:12 +00003812
John McCall31f82722010-11-12 08:19:04 +00003813 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3814 if (NamedT.isNull())
3815 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003816
John McCall550e0c22009-10-21 00:40:46 +00003817 QualType Result = TL.getType();
3818 if (getDerived().AlwaysRebuild() ||
3819 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003820 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00003821 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
3822 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003823 if (Result.isNull())
3824 return QualType();
3825 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003826
Abramo Bagnara6150c882010-05-11 21:36:43 +00003827 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003828 NewTL.setKeywordLoc(TL.getKeywordLoc());
3829 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003830
3831 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003832}
Mike Stump11289f42009-09-09 15:08:12 +00003833
3834template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00003835QualType
3836TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
3837 ParenTypeLoc TL) {
3838 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
3839 if (Inner.isNull())
3840 return QualType();
3841
3842 QualType Result = TL.getType();
3843 if (getDerived().AlwaysRebuild() ||
3844 Inner != TL.getInnerLoc().getType()) {
3845 Result = getDerived().RebuildParenType(Inner);
3846 if (Result.isNull())
3847 return QualType();
3848 }
3849
3850 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
3851 NewTL.setLParenLoc(TL.getLParenLoc());
3852 NewTL.setRParenLoc(TL.getRParenLoc());
3853 return Result;
3854}
3855
3856template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003857QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003858 DependentNameTypeLoc TL) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003859 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003860
Douglas Gregord6ff3322009-08-04 16:50:30 +00003861 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003862 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003863 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003864 if (!NNS)
3865 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003866
John McCallc392f372010-06-11 00:33:02 +00003867 QualType Result
3868 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3869 T->getIdentifier(),
3870 TL.getKeywordLoc(),
3871 TL.getQualifierRange(),
3872 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003873 if (Result.isNull())
3874 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003875
Abramo Bagnarad7548482010-05-19 21:37:53 +00003876 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3877 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003878 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3879
Abramo Bagnarad7548482010-05-19 21:37:53 +00003880 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3881 NewTL.setKeywordLoc(TL.getKeywordLoc());
3882 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003883 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003884 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3885 NewTL.setKeywordLoc(TL.getKeywordLoc());
3886 NewTL.setQualifierRange(TL.getQualifierRange());
3887 NewTL.setNameLoc(TL.getNameLoc());
3888 }
John McCall550e0c22009-10-21 00:40:46 +00003889 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003890}
Mike Stump11289f42009-09-09 15:08:12 +00003891
Douglas Gregord6ff3322009-08-04 16:50:30 +00003892template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003893QualType TreeTransform<Derived>::
3894 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003895 DependentTemplateSpecializationTypeLoc TL) {
John McCallc392f372010-06-11 00:33:02 +00003896 DependentTemplateSpecializationType *T = TL.getTypePtr();
3897
3898 NestedNameSpecifier *NNS
3899 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003900 TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003901 if (!NNS)
3902 return QualType();
3903
John McCall31f82722010-11-12 08:19:04 +00003904 return getDerived()
3905 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
3906}
3907
3908template<typename Derived>
3909QualType TreeTransform<Derived>::
3910 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3911 DependentTemplateSpecializationTypeLoc TL,
3912 NestedNameSpecifier *NNS) {
3913 DependentTemplateSpecializationType *T = TL.getTypePtr();
3914
John McCallc392f372010-06-11 00:33:02 +00003915 TemplateArgumentListInfo NewTemplateArgs;
3916 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3917 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00003918
3919 typedef TemplateArgumentLocContainerIterator<
3920 DependentTemplateSpecializationTypeLoc> ArgIterator;
3921 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
3922 ArgIterator(TL, TL.getNumArgs()),
3923 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003924 return QualType();
John McCallc392f372010-06-11 00:33:02 +00003925
Douglas Gregora5614c52010-09-08 23:56:00 +00003926 QualType Result
3927 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
3928 NNS,
3929 TL.getQualifierRange(),
3930 T->getIdentifier(),
3931 TL.getNameLoc(),
3932 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00003933 if (Result.isNull())
3934 return QualType();
3935
3936 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3937 QualType NamedT = ElabT->getNamedType();
3938
3939 // Copy information relevant to the template specialization.
3940 TemplateSpecializationTypeLoc NamedTL
3941 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3942 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3943 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3944 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3945 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3946
3947 // Copy information relevant to the elaborated type.
3948 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3949 NewTL.setKeywordLoc(TL.getKeywordLoc());
3950 NewTL.setQualifierRange(TL.getQualifierRange());
3951 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00003952 TypeLoc NewTL(Result, TL.getOpaqueData());
3953 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00003954 }
3955 return Result;
3956}
3957
3958template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00003959QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
3960 PackExpansionTypeLoc TL) {
3961 // FIXME: Implement!
3962 getSema().Diag(TL.getEllipsisLoc(),
3963 diag::err_pack_expansion_instantiation_unsupported);
3964 return QualType();
3965}
3966
3967template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003968QualType
3969TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003970 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003971 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003972 TLB.pushFullCopy(TL);
3973 return TL.getType();
3974}
3975
3976template<typename Derived>
3977QualType
3978TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003979 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00003980 // ObjCObjectType is never dependent.
3981 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003982 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003983}
Mike Stump11289f42009-09-09 15:08:12 +00003984
3985template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003986QualType
3987TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003988 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003989 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003990 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003991 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003992}
3993
Douglas Gregord6ff3322009-08-04 16:50:30 +00003994//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003995// Statement transformation
3996//===----------------------------------------------------------------------===//
3997template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003998StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003999TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004000 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004001}
4002
4003template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004004StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004005TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4006 return getDerived().TransformCompoundStmt(S, false);
4007}
4008
4009template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004010StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004011TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004012 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004013 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004014 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004015 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004016 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4017 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004018 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004019 if (Result.isInvalid()) {
4020 // Immediately fail if this was a DeclStmt, since it's very
4021 // likely that this will cause problems for future statements.
4022 if (isa<DeclStmt>(*B))
4023 return StmtError();
4024
4025 // Otherwise, just keep processing substatements and fail later.
4026 SubStmtInvalid = true;
4027 continue;
4028 }
Mike Stump11289f42009-09-09 15:08:12 +00004029
Douglas Gregorebe10102009-08-20 07:17:43 +00004030 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4031 Statements.push_back(Result.takeAs<Stmt>());
4032 }
Mike Stump11289f42009-09-09 15:08:12 +00004033
John McCall1ababa62010-08-27 19:56:05 +00004034 if (SubStmtInvalid)
4035 return StmtError();
4036
Douglas Gregorebe10102009-08-20 07:17:43 +00004037 if (!getDerived().AlwaysRebuild() &&
4038 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004039 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004040
4041 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4042 move_arg(Statements),
4043 S->getRBracLoc(),
4044 IsStmtExpr);
4045}
Mike Stump11289f42009-09-09 15:08:12 +00004046
Douglas Gregorebe10102009-08-20 07:17:43 +00004047template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004048StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004049TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004050 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004051 {
4052 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004053 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004054
Eli Friedman06577382009-11-19 03:14:00 +00004055 // Transform the left-hand case value.
4056 LHS = getDerived().TransformExpr(S->getLHS());
4057 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004058 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004059
Eli Friedman06577382009-11-19 03:14:00 +00004060 // Transform the right-hand case value (for the GNU case-range extension).
4061 RHS = getDerived().TransformExpr(S->getRHS());
4062 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004063 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004064 }
Mike Stump11289f42009-09-09 15:08:12 +00004065
Douglas Gregorebe10102009-08-20 07:17:43 +00004066 // Build the case statement.
4067 // Case statements are always rebuilt so that they will attached to their
4068 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004069 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004070 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004071 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004072 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004073 S->getColonLoc());
4074 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004075 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004076
Douglas Gregorebe10102009-08-20 07:17:43 +00004077 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004078 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004079 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004080 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004081
Douglas Gregorebe10102009-08-20 07:17:43 +00004082 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004083 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004084}
4085
4086template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004087StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004088TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004089 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004090 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004091 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004092 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004093
Douglas Gregorebe10102009-08-20 07:17:43 +00004094 // Default statements are always rebuilt
4095 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004096 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004097}
Mike Stump11289f42009-09-09 15:08:12 +00004098
Douglas Gregorebe10102009-08-20 07:17:43 +00004099template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004100StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004101TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004102 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004103 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004104 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004105
Douglas Gregorebe10102009-08-20 07:17:43 +00004106 // FIXME: Pass the real colon location in.
4107 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
4108 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +00004109 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregorebe10102009-08-20 07:17:43 +00004110}
Mike Stump11289f42009-09-09 15:08:12 +00004111
Douglas Gregorebe10102009-08-20 07:17:43 +00004112template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004113StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004114TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004115 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004116 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004117 VarDecl *ConditionVar = 0;
4118 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004119 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004120 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004121 getDerived().TransformDefinition(
4122 S->getConditionVariable()->getLocation(),
4123 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004124 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004125 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004126 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004127 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004128
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004129 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004130 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004131
4132 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004133 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004134 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4135 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004136 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004137 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004138
John McCallb268a282010-08-23 23:25:46 +00004139 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004140 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004141 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004142
John McCallb268a282010-08-23 23:25:46 +00004143 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4144 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004145 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004146
Douglas Gregorebe10102009-08-20 07:17:43 +00004147 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004148 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004149 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004150 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004151
Douglas Gregorebe10102009-08-20 07:17:43 +00004152 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004153 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004154 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004155 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004156
Douglas Gregorebe10102009-08-20 07:17:43 +00004157 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004158 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004159 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004160 Then.get() == S->getThen() &&
4161 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004162 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004163
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004164 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004165 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004166 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004167}
4168
4169template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004170StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004171TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004172 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004173 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004174 VarDecl *ConditionVar = 0;
4175 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004176 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004177 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004178 getDerived().TransformDefinition(
4179 S->getConditionVariable()->getLocation(),
4180 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004181 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004182 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004183 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004184 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004185
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004186 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004187 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004188 }
Mike Stump11289f42009-09-09 15:08:12 +00004189
Douglas Gregorebe10102009-08-20 07:17:43 +00004190 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004191 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004192 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004193 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004194 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004195 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004196
Douglas Gregorebe10102009-08-20 07:17:43 +00004197 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004198 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004199 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004200 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004201
Douglas Gregorebe10102009-08-20 07:17:43 +00004202 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004203 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4204 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004205}
Mike Stump11289f42009-09-09 15:08:12 +00004206
Douglas Gregorebe10102009-08-20 07:17:43 +00004207template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004208StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004209TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004210 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004211 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004212 VarDecl *ConditionVar = 0;
4213 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004214 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004215 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004216 getDerived().TransformDefinition(
4217 S->getConditionVariable()->getLocation(),
4218 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004219 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004220 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004221 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004222 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004223
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004224 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004225 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004226
4227 if (S->getCond()) {
4228 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004229 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4230 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004231 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004232 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004233 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004234 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004235 }
Mike Stump11289f42009-09-09 15:08:12 +00004236
John McCallb268a282010-08-23 23:25:46 +00004237 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4238 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004239 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004240
Douglas Gregorebe10102009-08-20 07:17:43 +00004241 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004242 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004243 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004244 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004245
Douglas Gregorebe10102009-08-20 07:17:43 +00004246 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004247 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004248 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004249 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004250 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004251
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004252 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004253 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004254}
Mike Stump11289f42009-09-09 15:08:12 +00004255
Douglas Gregorebe10102009-08-20 07:17:43 +00004256template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004257StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004258TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004259 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004260 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004261 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004262 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004263
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004264 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004265 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004266 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004267 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004268
Douglas Gregorebe10102009-08-20 07:17:43 +00004269 if (!getDerived().AlwaysRebuild() &&
4270 Cond.get() == S->getCond() &&
4271 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004272 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004273
John McCallb268a282010-08-23 23:25:46 +00004274 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4275 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004276 S->getRParenLoc());
4277}
Mike Stump11289f42009-09-09 15:08:12 +00004278
Douglas Gregorebe10102009-08-20 07:17:43 +00004279template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004280StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004281TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004282 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004283 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004284 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004285 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004286
Douglas Gregorebe10102009-08-20 07:17:43 +00004287 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004288 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004289 VarDecl *ConditionVar = 0;
4290 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004291 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004292 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004293 getDerived().TransformDefinition(
4294 S->getConditionVariable()->getLocation(),
4295 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004296 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004297 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004298 } else {
4299 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004300
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004301 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004302 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004303
4304 if (S->getCond()) {
4305 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004306 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4307 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004308 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004309 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004310
John McCallb268a282010-08-23 23:25:46 +00004311 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004312 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004313 }
Mike Stump11289f42009-09-09 15:08:12 +00004314
John McCallb268a282010-08-23 23:25:46 +00004315 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4316 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004317 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004318
Douglas Gregorebe10102009-08-20 07:17:43 +00004319 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00004320 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00004321 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004322 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004323
John McCallb268a282010-08-23 23:25:46 +00004324 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4325 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004326 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004327
Douglas Gregorebe10102009-08-20 07:17:43 +00004328 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004329 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004330 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004331 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004332
Douglas Gregorebe10102009-08-20 07:17:43 +00004333 if (!getDerived().AlwaysRebuild() &&
4334 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00004335 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004336 Inc.get() == S->getInc() &&
4337 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004338 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004339
Douglas Gregorebe10102009-08-20 07:17:43 +00004340 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004341 Init.get(), FullCond, ConditionVar,
4342 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004343}
4344
4345template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004346StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004347TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004348 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00004349 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004350 S->getLabel());
4351}
4352
4353template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004354StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004355TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004356 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00004357 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004358 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004359
Douglas Gregorebe10102009-08-20 07:17:43 +00004360 if (!getDerived().AlwaysRebuild() &&
4361 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00004362 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004363
4364 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00004365 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004366}
4367
4368template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004369StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004370TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004371 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004372}
Mike Stump11289f42009-09-09 15:08:12 +00004373
Douglas Gregorebe10102009-08-20 07:17:43 +00004374template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004375StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004376TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004377 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004378}
Mike Stump11289f42009-09-09 15:08:12 +00004379
Douglas Gregorebe10102009-08-20 07:17:43 +00004380template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004381StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004382TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004383 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00004384 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004385 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004386
Mike Stump11289f42009-09-09 15:08:12 +00004387 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00004388 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00004389 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004390}
Mike Stump11289f42009-09-09 15:08:12 +00004391
Douglas Gregorebe10102009-08-20 07:17:43 +00004392template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004393StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004394TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004395 bool DeclChanged = false;
4396 llvm::SmallVector<Decl *, 4> Decls;
4397 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4398 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00004399 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4400 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00004401 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00004402 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004403
Douglas Gregorebe10102009-08-20 07:17:43 +00004404 if (Transformed != *D)
4405 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00004406
Douglas Gregorebe10102009-08-20 07:17:43 +00004407 Decls.push_back(Transformed);
4408 }
Mike Stump11289f42009-09-09 15:08:12 +00004409
Douglas Gregorebe10102009-08-20 07:17:43 +00004410 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00004411 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004412
4413 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004414 S->getStartLoc(), S->getEndLoc());
4415}
Mike Stump11289f42009-09-09 15:08:12 +00004416
Douglas Gregorebe10102009-08-20 07:17:43 +00004417template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004418StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004419TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004420 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCallc3007a22010-10-26 07:05:15 +00004421 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004422}
4423
4424template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004425StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004426TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004427
John McCall37ad5512010-08-23 06:44:23 +00004428 ASTOwningVector<Expr*> Constraints(getSema());
4429 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00004430 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00004431
John McCalldadc5752010-08-24 06:29:42 +00004432 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00004433 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004434
4435 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004436
Anders Carlssonaaeef072010-01-24 05:50:09 +00004437 // Go through the outputs.
4438 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004439 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004440
Anders Carlssonaaeef072010-01-24 05:50:09 +00004441 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004442 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004443
Anders Carlssonaaeef072010-01-24 05:50:09 +00004444 // Transform the output expr.
4445 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004446 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004447 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004448 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004449
Anders Carlssonaaeef072010-01-24 05:50:09 +00004450 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004451
John McCallb268a282010-08-23 23:25:46 +00004452 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004453 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004454
Anders Carlssonaaeef072010-01-24 05:50:09 +00004455 // Go through the inputs.
4456 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004457 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004458
Anders Carlssonaaeef072010-01-24 05:50:09 +00004459 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004460 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004461
Anders Carlssonaaeef072010-01-24 05:50:09 +00004462 // Transform the input expr.
4463 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004464 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004465 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004466 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004467
Anders Carlssonaaeef072010-01-24 05:50:09 +00004468 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004469
John McCallb268a282010-08-23 23:25:46 +00004470 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004471 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004472
Anders Carlssonaaeef072010-01-24 05:50:09 +00004473 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00004474 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004475
4476 // Go through the clobbers.
4477 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00004478 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00004479
4480 // No need to transform the asm string literal.
4481 AsmString = SemaRef.Owned(S->getAsmString());
4482
4483 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4484 S->isSimple(),
4485 S->isVolatile(),
4486 S->getNumOutputs(),
4487 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00004488 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004489 move_arg(Constraints),
4490 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00004491 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004492 move_arg(Clobbers),
4493 S->getRParenLoc(),
4494 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00004495}
4496
4497
4498template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004499StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004500TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004501 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00004502 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004503 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004504 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004505
Douglas Gregor96c79492010-04-23 22:50:49 +00004506 // Transform the @catch statements (if present).
4507 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004508 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00004509 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004510 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00004511 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004512 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00004513 if (Catch.get() != S->getCatchStmt(I))
4514 AnyCatchChanged = true;
4515 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004516 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004517
Douglas Gregor306de2f2010-04-22 23:59:56 +00004518 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00004519 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00004520 if (S->getFinallyStmt()) {
4521 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4522 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004523 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00004524 }
4525
4526 // If nothing changed, just retain this statement.
4527 if (!getDerived().AlwaysRebuild() &&
4528 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00004529 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00004530 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00004531 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004532
Douglas Gregor306de2f2010-04-22 23:59:56 +00004533 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00004534 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4535 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004536}
Mike Stump11289f42009-09-09 15:08:12 +00004537
Douglas Gregorebe10102009-08-20 07:17:43 +00004538template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004539StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004540TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004541 // Transform the @catch parameter, if there is one.
4542 VarDecl *Var = 0;
4543 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4544 TypeSourceInfo *TSInfo = 0;
4545 if (FromVar->getTypeSourceInfo()) {
4546 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4547 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004548 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004549 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004550
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004551 QualType T;
4552 if (TSInfo)
4553 T = TSInfo->getType();
4554 else {
4555 T = getDerived().TransformType(FromVar->getType());
4556 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004557 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004558 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004559
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004560 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4561 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00004562 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004563 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004564
John McCalldadc5752010-08-24 06:29:42 +00004565 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004566 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004567 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004568
4569 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004570 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004571 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004572}
Mike Stump11289f42009-09-09 15:08:12 +00004573
Douglas Gregorebe10102009-08-20 07:17:43 +00004574template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004575StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004576TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004577 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004578 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004579 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004580 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004581
Douglas Gregor306de2f2010-04-22 23:59:56 +00004582 // If nothing changed, just retain this statement.
4583 if (!getDerived().AlwaysRebuild() &&
4584 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00004585 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00004586
4587 // Build a new statement.
4588 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004589 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004590}
Mike Stump11289f42009-09-09 15:08:12 +00004591
Douglas Gregorebe10102009-08-20 07:17:43 +00004592template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004593StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004594TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004595 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00004596 if (S->getThrowExpr()) {
4597 Operand = getDerived().TransformExpr(S->getThrowExpr());
4598 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004599 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00004600 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004601
Douglas Gregor2900c162010-04-22 21:44:01 +00004602 if (!getDerived().AlwaysRebuild() &&
4603 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00004604 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004605
John McCallb268a282010-08-23 23:25:46 +00004606 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004607}
Mike Stump11289f42009-09-09 15:08:12 +00004608
Douglas Gregorebe10102009-08-20 07:17:43 +00004609template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004610StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004611TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004612 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004613 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00004614 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00004615 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004616 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004617
Douglas Gregor6148de72010-04-22 22:01:21 +00004618 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004619 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00004620 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004621 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004622
Douglas Gregor6148de72010-04-22 22:01:21 +00004623 // If nothing change, just retain the current statement.
4624 if (!getDerived().AlwaysRebuild() &&
4625 Object.get() == S->getSynchExpr() &&
4626 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00004627 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00004628
4629 // Build a new statement.
4630 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00004631 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004632}
4633
4634template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004635StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004636TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004637 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004638 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00004639 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004640 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004641 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004642
Douglas Gregorf68a5082010-04-22 23:10:45 +00004643 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00004644 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004645 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004646 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004647
Douglas Gregorf68a5082010-04-22 23:10:45 +00004648 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004649 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004650 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004651 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004652
Douglas Gregorf68a5082010-04-22 23:10:45 +00004653 // If nothing changed, just retain this statement.
4654 if (!getDerived().AlwaysRebuild() &&
4655 Element.get() == S->getElement() &&
4656 Collection.get() == S->getCollection() &&
4657 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004658 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004659
Douglas Gregorf68a5082010-04-22 23:10:45 +00004660 // Build a new statement.
4661 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4662 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00004663 Element.get(),
4664 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00004665 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004666 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004667}
4668
4669
4670template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004671StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004672TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4673 // Transform the exception declaration, if any.
4674 VarDecl *Var = 0;
4675 if (S->getExceptionDecl()) {
4676 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004677 TypeSourceInfo *T = getDerived().TransformType(
4678 ExceptionDecl->getTypeSourceInfo());
4679 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00004680 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004681
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004682 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00004683 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004684 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00004685 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00004686 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004687 }
Mike Stump11289f42009-09-09 15:08:12 +00004688
Douglas Gregorebe10102009-08-20 07:17:43 +00004689 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00004690 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004691 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004692 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004693
Douglas Gregorebe10102009-08-20 07:17:43 +00004694 if (!getDerived().AlwaysRebuild() &&
4695 !Var &&
4696 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00004697 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004698
4699 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4700 Var,
John McCallb268a282010-08-23 23:25:46 +00004701 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004702}
Mike Stump11289f42009-09-09 15:08:12 +00004703
Douglas Gregorebe10102009-08-20 07:17:43 +00004704template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004705StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004706TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4707 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00004708 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004709 = getDerived().TransformCompoundStmt(S->getTryBlock());
4710 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004711 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004712
Douglas Gregorebe10102009-08-20 07:17:43 +00004713 // Transform the handlers.
4714 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004715 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00004716 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004717 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004718 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4719 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004720 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004721
Douglas Gregorebe10102009-08-20 07:17:43 +00004722 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4723 Handlers.push_back(Handler.takeAs<Stmt>());
4724 }
Mike Stump11289f42009-09-09 15:08:12 +00004725
Douglas Gregorebe10102009-08-20 07:17:43 +00004726 if (!getDerived().AlwaysRebuild() &&
4727 TryBlock.get() == S->getTryBlock() &&
4728 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00004729 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004730
John McCallb268a282010-08-23 23:25:46 +00004731 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00004732 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004733}
Mike Stump11289f42009-09-09 15:08:12 +00004734
Douglas Gregorebe10102009-08-20 07:17:43 +00004735//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004736// Expression transformation
4737//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004738template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004739ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004740TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00004741 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004742}
Mike Stump11289f42009-09-09 15:08:12 +00004743
4744template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004745ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004746TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004747 NestedNameSpecifier *Qualifier = 0;
4748 if (E->getQualifier()) {
4749 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004750 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004751 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00004752 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004753 }
John McCallce546572009-12-08 09:08:17 +00004754
4755 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004756 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4757 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004758 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00004759 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004760
John McCall815039a2010-08-17 21:27:17 +00004761 DeclarationNameInfo NameInfo = E->getNameInfo();
4762 if (NameInfo.getName()) {
4763 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4764 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00004765 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00004766 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004767
4768 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004769 Qualifier == E->getQualifier() &&
4770 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004771 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00004772 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004773
4774 // Mark it referenced in the new context regardless.
4775 // FIXME: this is a bit instantiation-specific.
4776 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4777
John McCallc3007a22010-10-26 07:05:15 +00004778 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004779 }
John McCallce546572009-12-08 09:08:17 +00004780
4781 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00004782 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004783 TemplateArgs = &TransArgs;
4784 TransArgs.setLAngleLoc(E->getLAngleLoc());
4785 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00004786 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
4787 E->getNumTemplateArgs(),
4788 TransArgs))
4789 return ExprError();
John McCallce546572009-12-08 09:08:17 +00004790 }
4791
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004792 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004793 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004794}
Mike Stump11289f42009-09-09 15:08:12 +00004795
Douglas Gregora16548e2009-08-11 05:31:07 +00004796template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004797ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004798TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004799 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004800}
Mike Stump11289f42009-09-09 15:08:12 +00004801
Douglas Gregora16548e2009-08-11 05:31:07 +00004802template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004803ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004804TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004805 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004806}
Mike Stump11289f42009-09-09 15:08:12 +00004807
Douglas Gregora16548e2009-08-11 05:31:07 +00004808template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004809ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004810TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004811 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004812}
Mike Stump11289f42009-09-09 15:08:12 +00004813
Douglas Gregora16548e2009-08-11 05:31:07 +00004814template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004815ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004816TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004817 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004818}
Mike Stump11289f42009-09-09 15:08:12 +00004819
Douglas Gregora16548e2009-08-11 05:31:07 +00004820template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004821ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004822TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004823 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004824}
4825
4826template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004827ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004828TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004829 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004830 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004831 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004832
Douglas Gregora16548e2009-08-11 05:31:07 +00004833 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004834 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004835
John McCallb268a282010-08-23 23:25:46 +00004836 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004837 E->getRParen());
4838}
4839
Mike Stump11289f42009-09-09 15:08:12 +00004840template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004841ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004842TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004843 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004844 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004845 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004846
Douglas Gregora16548e2009-08-11 05:31:07 +00004847 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004848 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004849
Douglas Gregora16548e2009-08-11 05:31:07 +00004850 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4851 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004852 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004853}
Mike Stump11289f42009-09-09 15:08:12 +00004854
Douglas Gregora16548e2009-08-11 05:31:07 +00004855template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004856ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004857TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4858 // Transform the type.
4859 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4860 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00004861 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004862
Douglas Gregor882211c2010-04-28 22:16:22 +00004863 // Transform all of the components into components similar to what the
4864 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004865 // FIXME: It would be slightly more efficient in the non-dependent case to
4866 // just map FieldDecls, rather than requiring the rebuilder to look for
4867 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004868 // template code that we don't care.
4869 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00004870 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00004871 typedef OffsetOfExpr::OffsetOfNode Node;
4872 llvm::SmallVector<Component, 4> Components;
4873 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4874 const Node &ON = E->getComponent(I);
4875 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004876 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004877 Comp.LocStart = ON.getRange().getBegin();
4878 Comp.LocEnd = ON.getRange().getEnd();
4879 switch (ON.getKind()) {
4880 case Node::Array: {
4881 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00004882 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00004883 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004884 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004885
Douglas Gregor882211c2010-04-28 22:16:22 +00004886 ExprChanged = ExprChanged || Index.get() != FromIndex;
4887 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00004888 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00004889 break;
4890 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004891
Douglas Gregor882211c2010-04-28 22:16:22 +00004892 case Node::Field:
4893 case Node::Identifier:
4894 Comp.isBrackets = false;
4895 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004896 if (!Comp.U.IdentInfo)
4897 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004898
Douglas Gregor882211c2010-04-28 22:16:22 +00004899 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004900
Douglas Gregord1702062010-04-29 00:18:15 +00004901 case Node::Base:
4902 // Will be recomputed during the rebuild.
4903 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004904 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004905
Douglas Gregor882211c2010-04-28 22:16:22 +00004906 Components.push_back(Comp);
4907 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004908
Douglas Gregor882211c2010-04-28 22:16:22 +00004909 // If nothing changed, retain the existing expression.
4910 if (!getDerived().AlwaysRebuild() &&
4911 Type == E->getTypeSourceInfo() &&
4912 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00004913 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004914
Douglas Gregor882211c2010-04-28 22:16:22 +00004915 // Build a new offsetof expression.
4916 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4917 Components.data(), Components.size(),
4918 E->getRParenLoc());
4919}
4920
4921template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004922ExprResult
John McCall8d69a212010-11-15 23:31:06 +00004923TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
4924 assert(getDerived().AlreadyTransformed(E->getType()) &&
4925 "opaque value expression requires transformation");
4926 return SemaRef.Owned(E);
4927}
4928
4929template<typename Derived>
4930ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004931TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004932 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004933 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004934
John McCallbcd03502009-12-07 02:54:59 +00004935 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004936 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004937 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004938
John McCall4c98fd82009-11-04 07:28:41 +00004939 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00004940 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004941
John McCall4c98fd82009-11-04 07:28:41 +00004942 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004943 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004944 E->getSourceRange());
4945 }
Mike Stump11289f42009-09-09 15:08:12 +00004946
John McCalldadc5752010-08-24 06:29:42 +00004947 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00004948 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004949 // C++0x [expr.sizeof]p1:
4950 // The operand is either an expression, which is an unevaluated operand
4951 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00004952 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004953
Douglas Gregora16548e2009-08-11 05:31:07 +00004954 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4955 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004956 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004957
Douglas Gregora16548e2009-08-11 05:31:07 +00004958 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00004959 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004960 }
Mike Stump11289f42009-09-09 15:08:12 +00004961
John McCallb268a282010-08-23 23:25:46 +00004962 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004963 E->isSizeOf(),
4964 E->getSourceRange());
4965}
Mike Stump11289f42009-09-09 15:08:12 +00004966
Douglas Gregora16548e2009-08-11 05:31:07 +00004967template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004968ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004969TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004970 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004971 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004972 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004973
John McCalldadc5752010-08-24 06:29:42 +00004974 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004975 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004976 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004977
4978
Douglas Gregora16548e2009-08-11 05:31:07 +00004979 if (!getDerived().AlwaysRebuild() &&
4980 LHS.get() == E->getLHS() &&
4981 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00004982 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004983
John McCallb268a282010-08-23 23:25:46 +00004984 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004985 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00004986 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004987 E->getRBracketLoc());
4988}
Mike Stump11289f42009-09-09 15:08:12 +00004989
4990template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004991ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004992TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004993 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00004994 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00004995 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004996 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00004997
4998 // Transform arguments.
4999 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005000 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005001 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5002 &ArgChanged))
5003 return ExprError();
5004
Douglas Gregora16548e2009-08-11 05:31:07 +00005005 if (!getDerived().AlwaysRebuild() &&
5006 Callee.get() == E->getCallee() &&
5007 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005008 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005009
Douglas Gregora16548e2009-08-11 05:31:07 +00005010 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005011 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005012 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005013 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005014 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005015 E->getRParenLoc());
5016}
Mike Stump11289f42009-09-09 15:08:12 +00005017
5018template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005019ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005020TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005021 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005022 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005023 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005024
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005025 NestedNameSpecifier *Qualifier = 0;
5026 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00005027 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005028 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005029 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00005030 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00005031 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005032 }
Mike Stump11289f42009-09-09 15:08:12 +00005033
Eli Friedman2cfcef62009-12-04 06:40:45 +00005034 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005035 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5036 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005037 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005038 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005039
John McCall16df1e52010-03-30 21:47:33 +00005040 NamedDecl *FoundDecl = E->getFoundDecl();
5041 if (FoundDecl == E->getMemberDecl()) {
5042 FoundDecl = Member;
5043 } else {
5044 FoundDecl = cast_or_null<NamedDecl>(
5045 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5046 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005047 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005048 }
5049
Douglas Gregora16548e2009-08-11 05:31:07 +00005050 if (!getDerived().AlwaysRebuild() &&
5051 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005052 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005053 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005054 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005055 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005056
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005057 // Mark it referenced in the new context regardless.
5058 // FIXME: this is a bit instantiation-specific.
5059 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005060 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005061 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005062
John McCall6b51f282009-11-23 01:53:49 +00005063 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005064 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005065 TransArgs.setLAngleLoc(E->getLAngleLoc());
5066 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005067 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5068 E->getNumTemplateArgs(),
5069 TransArgs))
5070 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005071 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005072
Douglas Gregora16548e2009-08-11 05:31:07 +00005073 // FIXME: Bogus source location for the operator
5074 SourceLocation FakeOperatorLoc
5075 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5076
John McCall38836f02010-01-15 08:34:02 +00005077 // FIXME: to do this check properly, we will need to preserve the
5078 // first-qualifier-in-scope here, just in case we had a dependent
5079 // base (and therefore couldn't do the check) and a
5080 // nested-name-qualifier (and therefore could do the lookup).
5081 NamedDecl *FirstQualifierInScope = 0;
5082
John McCallb268a282010-08-23 23:25:46 +00005083 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005084 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005085 Qualifier,
5086 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005087 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005088 Member,
John McCall16df1e52010-03-30 21:47:33 +00005089 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005090 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005091 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005092 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005093}
Mike Stump11289f42009-09-09 15:08:12 +00005094
Douglas Gregora16548e2009-08-11 05:31:07 +00005095template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005096ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005097TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005098 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005099 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005100 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005101
John McCalldadc5752010-08-24 06:29:42 +00005102 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005103 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005104 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005105
Douglas Gregora16548e2009-08-11 05:31:07 +00005106 if (!getDerived().AlwaysRebuild() &&
5107 LHS.get() == E->getLHS() &&
5108 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005109 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005110
Douglas Gregora16548e2009-08-11 05:31:07 +00005111 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005112 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005113}
5114
Mike Stump11289f42009-09-09 15:08:12 +00005115template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005116ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005117TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005118 CompoundAssignOperator *E) {
5119 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005120}
Mike Stump11289f42009-09-09 15:08:12 +00005121
Douglas Gregora16548e2009-08-11 05:31:07 +00005122template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005123ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005124TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005125 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005126 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005127 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005128
John McCalldadc5752010-08-24 06:29:42 +00005129 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005130 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005131 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005132
John McCalldadc5752010-08-24 06:29:42 +00005133 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005134 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005135 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005136
Douglas Gregora16548e2009-08-11 05:31:07 +00005137 if (!getDerived().AlwaysRebuild() &&
5138 Cond.get() == E->getCond() &&
5139 LHS.get() == E->getLHS() &&
5140 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005141 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005142
John McCallb268a282010-08-23 23:25:46 +00005143 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005144 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005145 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005146 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005147 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005148}
Mike Stump11289f42009-09-09 15:08:12 +00005149
5150template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005151ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005152TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005153 // Implicit casts are eliminated during transformation, since they
5154 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005155 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005156}
Mike Stump11289f42009-09-09 15:08:12 +00005157
Douglas Gregora16548e2009-08-11 05:31:07 +00005158template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005159ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005160TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005161 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5162 if (!Type)
5163 return ExprError();
5164
John McCalldadc5752010-08-24 06:29:42 +00005165 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005166 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005167 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005168 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005169
Douglas Gregora16548e2009-08-11 05:31:07 +00005170 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005171 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005172 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005173 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005174
John McCall97513962010-01-15 18:39:57 +00005175 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005176 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005177 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005178 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005179}
Mike Stump11289f42009-09-09 15:08:12 +00005180
Douglas Gregora16548e2009-08-11 05:31:07 +00005181template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005182ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005183TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005184 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5185 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5186 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005187 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005188
John McCalldadc5752010-08-24 06:29:42 +00005189 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005190 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005191 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005192
Douglas Gregora16548e2009-08-11 05:31:07 +00005193 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005194 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005195 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005196 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005197
John McCall5d7aa7f2010-01-19 22:33:45 +00005198 // Note: the expression type doesn't necessarily match the
5199 // type-as-written, but that's okay, because it should always be
5200 // derivable from the initializer.
5201
John McCalle15bbff2010-01-18 19:35:47 +00005202 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005203 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005204 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005205}
Mike Stump11289f42009-09-09 15:08:12 +00005206
Douglas Gregora16548e2009-08-11 05:31:07 +00005207template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005208ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005209TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005210 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005211 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005212 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005213
Douglas Gregora16548e2009-08-11 05:31:07 +00005214 if (!getDerived().AlwaysRebuild() &&
5215 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00005216 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005217
Douglas Gregora16548e2009-08-11 05:31:07 +00005218 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005219 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005220 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005221 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005222 E->getAccessorLoc(),
5223 E->getAccessor());
5224}
Mike Stump11289f42009-09-09 15:08:12 +00005225
Douglas Gregora16548e2009-08-11 05:31:07 +00005226template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005227ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005228TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005229 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005230
John McCall37ad5512010-08-23 06:44:23 +00005231 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005232 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5233 Inits, &InitChanged))
5234 return ExprError();
5235
Douglas Gregora16548e2009-08-11 05:31:07 +00005236 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005237 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005238
Douglas Gregora16548e2009-08-11 05:31:07 +00005239 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005240 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005241}
Mike Stump11289f42009-09-09 15:08:12 +00005242
Douglas Gregora16548e2009-08-11 05:31:07 +00005243template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005244ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005245TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005246 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005247
Douglas Gregorebe10102009-08-20 07:17:43 +00005248 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005249 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005250 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005251 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005252
Douglas Gregorebe10102009-08-20 07:17:43 +00005253 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005254 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005255 bool ExprChanged = false;
5256 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5257 DEnd = E->designators_end();
5258 D != DEnd; ++D) {
5259 if (D->isFieldDesignator()) {
5260 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5261 D->getDotLoc(),
5262 D->getFieldLoc()));
5263 continue;
5264 }
Mike Stump11289f42009-09-09 15:08:12 +00005265
Douglas Gregora16548e2009-08-11 05:31:07 +00005266 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005267 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005268 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005269 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005270
5271 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005272 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005273
Douglas Gregora16548e2009-08-11 05:31:07 +00005274 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5275 ArrayExprs.push_back(Index.release());
5276 continue;
5277 }
Mike Stump11289f42009-09-09 15:08:12 +00005278
Douglas Gregora16548e2009-08-11 05:31:07 +00005279 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00005280 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00005281 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5282 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005283 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005284
John McCalldadc5752010-08-24 06:29:42 +00005285 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005286 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005287 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005288
5289 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005290 End.get(),
5291 D->getLBracketLoc(),
5292 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005293
Douglas Gregora16548e2009-08-11 05:31:07 +00005294 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5295 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00005296
Douglas Gregora16548e2009-08-11 05:31:07 +00005297 ArrayExprs.push_back(Start.release());
5298 ArrayExprs.push_back(End.release());
5299 }
Mike Stump11289f42009-09-09 15:08:12 +00005300
Douglas Gregora16548e2009-08-11 05:31:07 +00005301 if (!getDerived().AlwaysRebuild() &&
5302 Init.get() == E->getInit() &&
5303 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005304 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005305
Douglas Gregora16548e2009-08-11 05:31:07 +00005306 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5307 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005308 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005309}
Mike Stump11289f42009-09-09 15:08:12 +00005310
Douglas Gregora16548e2009-08-11 05:31:07 +00005311template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005312ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005313TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005314 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00005315 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005316
Douglas Gregor3da3c062009-10-28 00:29:27 +00005317 // FIXME: Will we ever have proper type location here? Will we actually
5318 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00005319 QualType T = getDerived().TransformType(E->getType());
5320 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005321 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005322
Douglas Gregora16548e2009-08-11 05:31:07 +00005323 if (!getDerived().AlwaysRebuild() &&
5324 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005325 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005326
Douglas Gregora16548e2009-08-11 05:31:07 +00005327 return getDerived().RebuildImplicitValueInitExpr(T);
5328}
Mike Stump11289f42009-09-09 15:08:12 +00005329
Douglas Gregora16548e2009-08-11 05:31:07 +00005330template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005331ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005332TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00005333 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5334 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005335 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005336
John McCalldadc5752010-08-24 06:29:42 +00005337 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005338 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005339 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005340
Douglas Gregora16548e2009-08-11 05:31:07 +00005341 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00005342 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005343 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005344 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005345
John McCallb268a282010-08-23 23:25:46 +00005346 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00005347 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005348}
5349
5350template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005351ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005352TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005353 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005354 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005355 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5356 &ArgumentChanged))
5357 return ExprError();
5358
Douglas Gregora16548e2009-08-11 05:31:07 +00005359 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5360 move_arg(Inits),
5361 E->getRParenLoc());
5362}
Mike Stump11289f42009-09-09 15:08:12 +00005363
Douglas Gregora16548e2009-08-11 05:31:07 +00005364/// \brief Transform an address-of-label expression.
5365///
5366/// By default, the transformation of an address-of-label expression always
5367/// rebuilds the expression, so that the label identifier can be resolved to
5368/// the corresponding label statement by semantic analysis.
5369template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005370ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005371TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005372 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
5373 E->getLabel());
5374}
Mike Stump11289f42009-09-09 15:08:12 +00005375
5376template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005377ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005378TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005379 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00005380 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5381 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005382 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005383
Douglas Gregora16548e2009-08-11 05:31:07 +00005384 if (!getDerived().AlwaysRebuild() &&
5385 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00005386 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005387
5388 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005389 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005390 E->getRParenLoc());
5391}
Mike Stump11289f42009-09-09 15:08:12 +00005392
Douglas Gregora16548e2009-08-11 05:31:07 +00005393template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005394ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005395TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005396 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005397 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005398 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005399
John McCalldadc5752010-08-24 06:29:42 +00005400 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005401 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005402 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005403
John McCalldadc5752010-08-24 06:29:42 +00005404 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005405 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005406 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005407
Douglas Gregora16548e2009-08-11 05:31:07 +00005408 if (!getDerived().AlwaysRebuild() &&
5409 Cond.get() == E->getCond() &&
5410 LHS.get() == E->getLHS() &&
5411 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005412 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005413
Douglas Gregora16548e2009-08-11 05:31:07 +00005414 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00005415 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005416 E->getRParenLoc());
5417}
Mike Stump11289f42009-09-09 15:08:12 +00005418
Douglas Gregora16548e2009-08-11 05:31:07 +00005419template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005420ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005421TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005422 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005423}
5424
5425template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005426ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005427TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005428 switch (E->getOperator()) {
5429 case OO_New:
5430 case OO_Delete:
5431 case OO_Array_New:
5432 case OO_Array_Delete:
5433 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00005434 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005435
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005436 case OO_Call: {
5437 // This is a call to an object's operator().
5438 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5439
5440 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00005441 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005442 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005443 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005444
5445 // FIXME: Poor location information
5446 SourceLocation FakeLParenLoc
5447 = SemaRef.PP.getLocForEndOfToken(
5448 static_cast<Expr *>(Object.get())->getLocEnd());
5449
5450 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00005451 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005452 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
5453 Args))
5454 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005455
John McCallb268a282010-08-23 23:25:46 +00005456 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005457 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005458 E->getLocEnd());
5459 }
5460
5461#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5462 case OO_##Name:
5463#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5464#include "clang/Basic/OperatorKinds.def"
5465 case OO_Subscript:
5466 // Handled below.
5467 break;
5468
5469 case OO_Conditional:
5470 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00005471 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005472
5473 case OO_None:
5474 case NUM_OVERLOADED_OPERATORS:
5475 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00005476 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005477 }
5478
John McCalldadc5752010-08-24 06:29:42 +00005479 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005480 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005481 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005482
John McCalldadc5752010-08-24 06:29:42 +00005483 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005484 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005485 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005486
John McCalldadc5752010-08-24 06:29:42 +00005487 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00005488 if (E->getNumArgs() == 2) {
5489 Second = getDerived().TransformExpr(E->getArg(1));
5490 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005491 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005492 }
Mike Stump11289f42009-09-09 15:08:12 +00005493
Douglas Gregora16548e2009-08-11 05:31:07 +00005494 if (!getDerived().AlwaysRebuild() &&
5495 Callee.get() == E->getCallee() &&
5496 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005497 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00005498 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005499
Douglas Gregora16548e2009-08-11 05:31:07 +00005500 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5501 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005502 Callee.get(),
5503 First.get(),
5504 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005505}
Mike Stump11289f42009-09-09 15:08:12 +00005506
Douglas Gregora16548e2009-08-11 05:31:07 +00005507template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005508ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005509TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5510 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005511}
Mike Stump11289f42009-09-09 15:08:12 +00005512
Douglas Gregora16548e2009-08-11 05:31:07 +00005513template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005514ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005515TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005516 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5517 if (!Type)
5518 return ExprError();
5519
John McCalldadc5752010-08-24 06:29:42 +00005520 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005521 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005522 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005523 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005524
Douglas Gregora16548e2009-08-11 05:31:07 +00005525 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005526 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005527 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005528 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005529
Douglas Gregora16548e2009-08-11 05:31:07 +00005530 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005531 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005532 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5533 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5534 SourceLocation FakeRParenLoc
5535 = SemaRef.PP.getLocForEndOfToken(
5536 E->getSubExpr()->getSourceRange().getEnd());
5537 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005538 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005539 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005540 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005541 FakeRAngleLoc,
5542 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005543 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005544 FakeRParenLoc);
5545}
Mike Stump11289f42009-09-09 15:08:12 +00005546
Douglas Gregora16548e2009-08-11 05:31:07 +00005547template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005548ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005549TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5550 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005551}
Mike Stump11289f42009-09-09 15:08:12 +00005552
5553template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005554ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005555TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5556 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005557}
5558
Douglas Gregora16548e2009-08-11 05:31:07 +00005559template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005560ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005561TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005562 CXXReinterpretCastExpr *E) {
5563 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005564}
Mike Stump11289f42009-09-09 15:08:12 +00005565
Douglas Gregora16548e2009-08-11 05:31:07 +00005566template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005567ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005568TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5569 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005570}
Mike Stump11289f42009-09-09 15:08:12 +00005571
Douglas Gregora16548e2009-08-11 05:31:07 +00005572template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005573ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005574TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005575 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005576 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5577 if (!Type)
5578 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005579
John McCalldadc5752010-08-24 06:29:42 +00005580 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005581 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005582 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005583 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005584
Douglas Gregora16548e2009-08-11 05:31:07 +00005585 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005586 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005587 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005588 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005589
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005590 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005591 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005592 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005593 E->getRParenLoc());
5594}
Mike Stump11289f42009-09-09 15:08:12 +00005595
Douglas Gregora16548e2009-08-11 05:31:07 +00005596template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005597ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005598TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005599 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005600 TypeSourceInfo *TInfo
5601 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5602 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005603 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005604
Douglas Gregora16548e2009-08-11 05:31:07 +00005605 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005606 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005607 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005608
Douglas Gregor9da64192010-04-26 22:37:10 +00005609 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5610 E->getLocStart(),
5611 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005612 E->getLocEnd());
5613 }
Mike Stump11289f42009-09-09 15:08:12 +00005614
Douglas Gregora16548e2009-08-11 05:31:07 +00005615 // We don't know whether the expression is potentially evaluated until
5616 // after we perform semantic analysis, so the expression is potentially
5617 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005618 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00005619 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005620
John McCalldadc5752010-08-24 06:29:42 +00005621 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00005622 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005623 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005624
Douglas Gregora16548e2009-08-11 05:31:07 +00005625 if (!getDerived().AlwaysRebuild() &&
5626 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005627 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005628
Douglas Gregor9da64192010-04-26 22:37:10 +00005629 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5630 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005631 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005632 E->getLocEnd());
5633}
5634
5635template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005636ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00005637TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5638 if (E->isTypeOperand()) {
5639 TypeSourceInfo *TInfo
5640 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5641 if (!TInfo)
5642 return ExprError();
5643
5644 if (!getDerived().AlwaysRebuild() &&
5645 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005646 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005647
5648 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5649 E->getLocStart(),
5650 TInfo,
5651 E->getLocEnd());
5652 }
5653
5654 // We don't know whether the expression is potentially evaluated until
5655 // after we perform semantic analysis, so the expression is potentially
5656 // potentially evaluated.
5657 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5658
5659 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5660 if (SubExpr.isInvalid())
5661 return ExprError();
5662
5663 if (!getDerived().AlwaysRebuild() &&
5664 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005665 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005666
5667 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5668 E->getLocStart(),
5669 SubExpr.get(),
5670 E->getLocEnd());
5671}
5672
5673template<typename Derived>
5674ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005675TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005676 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005677}
Mike Stump11289f42009-09-09 15:08:12 +00005678
Douglas Gregora16548e2009-08-11 05:31:07 +00005679template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005680ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005681TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005682 CXXNullPtrLiteralExpr *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
John McCall47f29ea2009-12-08 09:21:05 +00005688TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005689 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5690 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5691 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00005692
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005693 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005694 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005695
Douglas Gregorb15af892010-01-07 23:12:05 +00005696 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005697}
Mike Stump11289f42009-09-09 15:08:12 +00005698
Douglas Gregora16548e2009-08-11 05:31:07 +00005699template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005700ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005701TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005702 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005703 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005704 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005705
Douglas Gregora16548e2009-08-11 05:31:07 +00005706 if (!getDerived().AlwaysRebuild() &&
5707 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005708 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005709
John McCallb268a282010-08-23 23:25:46 +00005710 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005711}
Mike Stump11289f42009-09-09 15:08:12 +00005712
Douglas Gregora16548e2009-08-11 05:31:07 +00005713template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005714ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005715TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005716 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005717 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5718 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005719 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00005720 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005721
Chandler Carruth794da4c2010-02-08 06:42:49 +00005722 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005723 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00005724 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005725
Douglas Gregor033f6752009-12-23 23:03:06 +00005726 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005727}
Mike Stump11289f42009-09-09 15:08:12 +00005728
Douglas Gregora16548e2009-08-11 05:31:07 +00005729template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005730ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00005731TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5732 CXXScalarValueInitExpr *E) {
5733 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5734 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005735 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00005736
Douglas Gregora16548e2009-08-11 05:31:07 +00005737 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005738 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005739 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005740
Douglas Gregor2b88c112010-09-08 00:15:04 +00005741 return getDerived().RebuildCXXScalarValueInitExpr(T,
5742 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00005743 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005744}
Mike Stump11289f42009-09-09 15:08:12 +00005745
Douglas Gregora16548e2009-08-11 05:31:07 +00005746template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005747ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005748TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005749 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00005750 TypeSourceInfo *AllocTypeInfo
5751 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5752 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005753 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005754
Douglas Gregora16548e2009-08-11 05:31:07 +00005755 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00005756 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00005757 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005758 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005759
Douglas Gregora16548e2009-08-11 05:31:07 +00005760 // Transform the placement arguments (if any).
5761 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005762 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005763 if (getDerived().TransformExprs(E->getPlacementArgs(),
5764 E->getNumPlacementArgs(), true,
5765 PlacementArgs, &ArgumentChanged))
5766 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005767
Douglas Gregorebe10102009-08-20 07:17:43 +00005768 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00005769 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005770 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
5771 ConstructorArgs, &ArgumentChanged))
5772 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005773
Douglas Gregord2d9da02010-02-26 00:38:10 +00005774 // Transform constructor, new operator, and delete operator.
5775 CXXConstructorDecl *Constructor = 0;
5776 if (E->getConstructor()) {
5777 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005778 getDerived().TransformDecl(E->getLocStart(),
5779 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005780 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005781 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005782 }
5783
5784 FunctionDecl *OperatorNew = 0;
5785 if (E->getOperatorNew()) {
5786 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005787 getDerived().TransformDecl(E->getLocStart(),
5788 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005789 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00005790 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005791 }
5792
5793 FunctionDecl *OperatorDelete = 0;
5794 if (E->getOperatorDelete()) {
5795 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005796 getDerived().TransformDecl(E->getLocStart(),
5797 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005798 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005799 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005800 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005801
Douglas Gregora16548e2009-08-11 05:31:07 +00005802 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00005803 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005804 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005805 Constructor == E->getConstructor() &&
5806 OperatorNew == E->getOperatorNew() &&
5807 OperatorDelete == E->getOperatorDelete() &&
5808 !ArgumentChanged) {
5809 // Mark any declarations we need as referenced.
5810 // FIXME: instantiation-specific.
5811 if (Constructor)
5812 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5813 if (OperatorNew)
5814 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5815 if (OperatorDelete)
5816 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00005817 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005818 }
Mike Stump11289f42009-09-09 15:08:12 +00005819
Douglas Gregor0744ef62010-09-07 21:49:58 +00005820 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005821 if (!ArraySize.get()) {
5822 // If no array size was specified, but the new expression was
5823 // instantiated with an array type (e.g., "new T" where T is
5824 // instantiated with "int[4]"), extract the outer bound from the
5825 // array type as our array size. We do this with constant and
5826 // dependently-sized array types.
5827 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5828 if (!ArrayT) {
5829 // Do nothing
5830 } else if (const ConstantArrayType *ConsArrayT
5831 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005832 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00005833 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5834 ConsArrayT->getSize(),
5835 SemaRef.Context.getSizeType(),
5836 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005837 AllocType = ConsArrayT->getElementType();
5838 } else if (const DependentSizedArrayType *DepArrayT
5839 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5840 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00005841 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005842 AllocType = DepArrayT->getElementType();
5843 }
5844 }
5845 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00005846
Douglas Gregora16548e2009-08-11 05:31:07 +00005847 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5848 E->isGlobalNew(),
5849 /*FIXME:*/E->getLocStart(),
5850 move_arg(PlacementArgs),
5851 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00005852 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005853 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00005854 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00005855 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005856 /*FIXME:*/E->getLocStart(),
5857 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005858 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005859}
Mike Stump11289f42009-09-09 15:08:12 +00005860
Douglas Gregora16548e2009-08-11 05:31:07 +00005861template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005862ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005863TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005864 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00005865 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005866 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005867
Douglas Gregord2d9da02010-02-26 00:38:10 +00005868 // Transform the delete operator, if known.
5869 FunctionDecl *OperatorDelete = 0;
5870 if (E->getOperatorDelete()) {
5871 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005872 getDerived().TransformDecl(E->getLocStart(),
5873 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005874 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005875 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005876 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005877
Douglas Gregora16548e2009-08-11 05:31:07 +00005878 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005879 Operand.get() == E->getArgument() &&
5880 OperatorDelete == E->getOperatorDelete()) {
5881 // Mark any declarations we need as referenced.
5882 // FIXME: instantiation-specific.
5883 if (OperatorDelete)
5884 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00005885
5886 if (!E->getArgument()->isTypeDependent()) {
5887 QualType Destroyed = SemaRef.Context.getBaseElementType(
5888 E->getDestroyedType());
5889 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
5890 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
5891 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
5892 SemaRef.LookupDestructor(Record));
5893 }
5894 }
5895
John McCallc3007a22010-10-26 07:05:15 +00005896 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005897 }
Mike Stump11289f42009-09-09 15:08:12 +00005898
Douglas Gregora16548e2009-08-11 05:31:07 +00005899 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5900 E->isGlobalDelete(),
5901 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00005902 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005903}
Mike Stump11289f42009-09-09 15:08:12 +00005904
Douglas Gregora16548e2009-08-11 05:31:07 +00005905template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005906ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005907TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005908 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005909 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00005910 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005911 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005912
John McCallba7bf592010-08-24 05:47:05 +00005913 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00005914 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005915 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005916 E->getOperatorLoc(),
5917 E->isArrow()? tok::arrow : tok::period,
5918 ObjectTypePtr,
5919 MayBePseudoDestructor);
5920 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005921 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005922
John McCallba7bf592010-08-24 05:47:05 +00005923 QualType ObjectType = ObjectTypePtr.get();
John McCall31f82722010-11-12 08:19:04 +00005924 NestedNameSpecifier *Qualifier = E->getQualifier();
5925 if (Qualifier) {
5926 Qualifier
5927 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5928 E->getQualifierRange(),
5929 ObjectType);
5930 if (!Qualifier)
5931 return ExprError();
5932 }
Mike Stump11289f42009-09-09 15:08:12 +00005933
Douglas Gregor678f90d2010-02-25 01:56:36 +00005934 PseudoDestructorTypeStorage Destroyed;
5935 if (E->getDestroyedTypeInfo()) {
5936 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00005937 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
5938 ObjectType, 0, Qualifier);
Douglas Gregor678f90d2010-02-25 01:56:36 +00005939 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005940 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00005941 Destroyed = DestroyedTypeInfo;
5942 } else if (ObjectType->isDependentType()) {
5943 // We aren't likely to be able to resolve the identifier down to a type
5944 // now anyway, so just retain the identifier.
5945 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5946 E->getDestroyedTypeLoc());
5947 } else {
5948 // Look for a destructor known with the given name.
5949 CXXScopeSpec SS;
5950 if (Qualifier) {
5951 SS.setScopeRep(Qualifier);
5952 SS.setRange(E->getQualifierRange());
5953 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005954
John McCallba7bf592010-08-24 05:47:05 +00005955 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005956 *E->getDestroyedTypeIdentifier(),
5957 E->getDestroyedTypeLoc(),
5958 /*Scope=*/0,
5959 SS, ObjectTypePtr,
5960 false);
5961 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005962 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005963
Douglas Gregor678f90d2010-02-25 01:56:36 +00005964 Destroyed
5965 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5966 E->getDestroyedTypeLoc());
5967 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005968
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005969 TypeSourceInfo *ScopeTypeInfo = 0;
5970 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00005971 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005972 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005973 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00005974 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005975
John McCallb268a282010-08-23 23:25:46 +00005976 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005977 E->getOperatorLoc(),
5978 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005979 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005980 E->getQualifierRange(),
5981 ScopeTypeInfo,
5982 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005983 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005984 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005985}
Mike Stump11289f42009-09-09 15:08:12 +00005986
Douglas Gregorad8a3362009-09-04 17:36:40 +00005987template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005988ExprResult
John McCalld14a8642009-11-21 08:51:07 +00005989TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005990 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005991 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5992
5993 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5994 Sema::LookupOrdinaryName);
5995
5996 // Transform all the decls.
5997 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5998 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005999 NamedDecl *InstD = static_cast<NamedDecl*>(
6000 getDerived().TransformDecl(Old->getNameLoc(),
6001 *I));
John McCall84d87672009-12-10 09:41:52 +00006002 if (!InstD) {
6003 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6004 // This can happen because of dependent hiding.
6005 if (isa<UsingShadowDecl>(*I))
6006 continue;
6007 else
John McCallfaf5fb42010-08-26 23:41:50 +00006008 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006009 }
John McCalle66edc12009-11-24 19:00:30 +00006010
6011 // Expand using declarations.
6012 if (isa<UsingDecl>(InstD)) {
6013 UsingDecl *UD = cast<UsingDecl>(InstD);
6014 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6015 E = UD->shadow_end(); I != E; ++I)
6016 R.addDecl(*I);
6017 continue;
6018 }
6019
6020 R.addDecl(InstD);
6021 }
6022
6023 // Resolve a kind, but don't do any further analysis. If it's
6024 // ambiguous, the callee needs to deal with it.
6025 R.resolveKind();
6026
6027 // Rebuild the nested-name qualifier, if present.
6028 CXXScopeSpec SS;
6029 NestedNameSpecifier *Qualifier = 0;
6030 if (Old->getQualifier()) {
6031 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006032 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00006033 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006034 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006035
John McCalle66edc12009-11-24 19:00:30 +00006036 SS.setScopeRep(Qualifier);
6037 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006038 }
6039
Douglas Gregor9262f472010-04-27 18:19:34 +00006040 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006041 CXXRecordDecl *NamingClass
6042 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6043 Old->getNameLoc(),
6044 Old->getNamingClass()));
6045 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006046 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006047
Douglas Gregorda7be082010-04-27 16:10:10 +00006048 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006049 }
6050
6051 // If we have no template arguments, it's a normal declaration name.
6052 if (!Old->hasExplicitTemplateArgs())
6053 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6054
6055 // If we have template arguments, rebuild them, then rebuild the
6056 // templateid expression.
6057 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006058 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6059 Old->getNumTemplateArgs(),
6060 TransArgs))
6061 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006062
6063 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6064 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006065}
Mike Stump11289f42009-09-09 15:08:12 +00006066
Douglas Gregora16548e2009-08-11 05:31:07 +00006067template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006068ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006069TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006070 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6071 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006072 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006073
Douglas Gregora16548e2009-08-11 05:31:07 +00006074 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006075 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006076 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006077
Mike Stump11289f42009-09-09 15:08:12 +00006078 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006079 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006080 T,
6081 E->getLocEnd());
6082}
Mike Stump11289f42009-09-09 15:08:12 +00006083
Douglas Gregora16548e2009-08-11 05:31:07 +00006084template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006085ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006086TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6087 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6088 if (!LhsT)
6089 return ExprError();
6090
6091 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6092 if (!RhsT)
6093 return ExprError();
6094
6095 if (!getDerived().AlwaysRebuild() &&
6096 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6097 return SemaRef.Owned(E);
6098
6099 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6100 E->getLocStart(),
6101 LhsT, RhsT,
6102 E->getLocEnd());
6103}
6104
6105template<typename Derived>
6106ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006107TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006108 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006109 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00006110 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006111 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006112 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00006113 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006114
John McCall31f82722010-11-12 08:19:04 +00006115 // TODO: If this is a conversion-function-id, verify that the
6116 // destination type name (if present) resolves the same way after
6117 // instantiation as it did in the local scope.
6118
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006119 DeclarationNameInfo NameInfo
6120 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6121 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006122 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006123
John McCalle66edc12009-11-24 19:00:30 +00006124 if (!E->hasExplicitTemplateArgs()) {
6125 if (!getDerived().AlwaysRebuild() &&
6126 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006127 // Note: it is sufficient to compare the Name component of NameInfo:
6128 // if name has not changed, DNLoc has not changed either.
6129 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006130 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006131
John McCalle66edc12009-11-24 19:00:30 +00006132 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6133 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006134 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006135 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006136 }
John McCall6b51f282009-11-23 01:53:49 +00006137
6138 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006139 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6140 E->getNumTemplateArgs(),
6141 TransArgs))
6142 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006143
John McCalle66edc12009-11-24 19:00:30 +00006144 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6145 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006146 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006147 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006148}
6149
6150template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006151ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006152TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006153 // CXXConstructExprs are always implicit, so when we have a
6154 // 1-argument construction we just transform that argument.
6155 if (E->getNumArgs() == 1 ||
6156 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6157 return getDerived().TransformExpr(E->getArg(0));
6158
Douglas Gregora16548e2009-08-11 05:31:07 +00006159 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6160
6161 QualType T = getDerived().TransformType(E->getType());
6162 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006163 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006164
6165 CXXConstructorDecl *Constructor
6166 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006167 getDerived().TransformDecl(E->getLocStart(),
6168 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006169 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006170 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006171
Douglas Gregora16548e2009-08-11 05:31:07 +00006172 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006173 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006174 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6175 &ArgumentChanged))
6176 return ExprError();
6177
Douglas Gregora16548e2009-08-11 05:31:07 +00006178 if (!getDerived().AlwaysRebuild() &&
6179 T == E->getType() &&
6180 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006181 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006182 // Mark the constructor as referenced.
6183 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006184 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006185 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006186 }
Mike Stump11289f42009-09-09 15:08:12 +00006187
Douglas Gregordb121ba2009-12-14 16:27:04 +00006188 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6189 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006190 move_arg(Args),
6191 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006192 E->getConstructionKind(),
6193 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006194}
Mike Stump11289f42009-09-09 15:08:12 +00006195
Douglas Gregora16548e2009-08-11 05:31:07 +00006196/// \brief Transform a C++ temporary-binding expression.
6197///
Douglas Gregor363b1512009-12-24 18:51:59 +00006198/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6199/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006200template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006201ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006202TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006203 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006204}
Mike Stump11289f42009-09-09 15:08:12 +00006205
John McCall5d413782010-12-06 08:20:24 +00006206/// \brief Transform a C++ expression that contains cleanups that should
6207/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006208///
John McCall5d413782010-12-06 08:20:24 +00006209/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006210/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006211template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006212ExprResult
John McCall5d413782010-12-06 08:20:24 +00006213TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006214 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006215}
Mike Stump11289f42009-09-09 15:08:12 +00006216
Douglas Gregora16548e2009-08-11 05:31:07 +00006217template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006218ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006219TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006220 CXXTemporaryObjectExpr *E) {
6221 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6222 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006223 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006224
Douglas Gregora16548e2009-08-11 05:31:07 +00006225 CXXConstructorDecl *Constructor
6226 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006227 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006228 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006229 if (!Constructor)
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 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006233 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006234 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00006235 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6236 &ArgumentChanged))
6237 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006238
Douglas Gregora16548e2009-08-11 05:31:07 +00006239 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006240 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006241 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006242 !ArgumentChanged) {
6243 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006244 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006245 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006246 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006247
6248 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6249 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006250 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006251 E->getLocEnd());
6252}
Mike Stump11289f42009-09-09 15:08:12 +00006253
Douglas Gregora16548e2009-08-11 05:31:07 +00006254template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006255ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006256TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006257 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00006258 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6259 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006260 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006261
Douglas Gregora16548e2009-08-11 05:31:07 +00006262 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006263 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006264 Args.reserve(E->arg_size());
6265 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6266 &ArgumentChanged))
6267 return ExprError();
6268
Douglas Gregora16548e2009-08-11 05:31:07 +00006269 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006270 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006271 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006272 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006273
Douglas Gregora16548e2009-08-11 05:31:07 +00006274 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00006275 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00006276 E->getLParenLoc(),
6277 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006278 E->getRParenLoc());
6279}
Mike Stump11289f42009-09-09 15:08:12 +00006280
Douglas Gregora16548e2009-08-11 05:31:07 +00006281template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006282ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006283TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006284 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006285 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006286 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006287 Expr *OldBase;
6288 QualType BaseType;
6289 QualType ObjectType;
6290 if (!E->isImplicitAccess()) {
6291 OldBase = E->getBase();
6292 Base = getDerived().TransformExpr(OldBase);
6293 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006294 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006295
John McCall2d74de92009-12-01 22:10:20 +00006296 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00006297 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00006298 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006299 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006300 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006301 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00006302 ObjectTy,
6303 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00006304 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006305 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006306
John McCallba7bf592010-08-24 05:47:05 +00006307 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00006308 BaseType = ((Expr*) Base.get())->getType();
6309 } else {
6310 OldBase = 0;
6311 BaseType = getDerived().TransformType(E->getBaseType());
6312 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6313 }
Mike Stump11289f42009-09-09 15:08:12 +00006314
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006315 // Transform the first part of the nested-name-specifier that qualifies
6316 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006317 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006318 = getDerived().TransformFirstQualifierInScope(
6319 E->getFirstQualifierFoundInScope(),
6320 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006321
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006322 NestedNameSpecifier *Qualifier = 0;
6323 if (E->getQualifier()) {
6324 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6325 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00006326 ObjectType,
6327 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006328 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006329 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006330 }
Mike Stump11289f42009-09-09 15:08:12 +00006331
John McCall31f82722010-11-12 08:19:04 +00006332 // TODO: If this is a conversion-function-id, verify that the
6333 // destination type name (if present) resolves the same way after
6334 // instantiation as it did in the local scope.
6335
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006336 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00006337 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006338 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006339 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006340
John McCall2d74de92009-12-01 22:10:20 +00006341 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00006342 // This is a reference to a member without an explicitly-specified
6343 // template argument list. Optimize for this common case.
6344 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00006345 Base.get() == OldBase &&
6346 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006347 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006348 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006349 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00006350 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006351
John McCallb268a282010-08-23 23:25:46 +00006352 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006353 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00006354 E->isArrow(),
6355 E->getOperatorLoc(),
6356 Qualifier,
6357 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00006358 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006359 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006360 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00006361 }
6362
John McCall6b51f282009-11-23 01:53:49 +00006363 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006364 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6365 E->getNumTemplateArgs(),
6366 TransArgs))
6367 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006368
John McCallb268a282010-08-23 23:25:46 +00006369 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006370 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006371 E->isArrow(),
6372 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006373 Qualifier,
6374 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006375 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006376 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006377 &TransArgs);
6378}
6379
6380template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006381ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006382TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00006383 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006384 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006385 QualType BaseType;
6386 if (!Old->isImplicitAccess()) {
6387 Base = getDerived().TransformExpr(Old->getBase());
6388 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006389 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006390 BaseType = ((Expr*) Base.get())->getType();
6391 } else {
6392 BaseType = getDerived().TransformType(Old->getBaseType());
6393 }
John McCall10eae182009-11-30 22:42:35 +00006394
6395 NestedNameSpecifier *Qualifier = 0;
6396 if (Old->getQualifier()) {
6397 Qualifier
6398 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006399 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00006400 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00006401 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006402 }
6403
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006404 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00006405 Sema::LookupOrdinaryName);
6406
6407 // Transform all the decls.
6408 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6409 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006410 NamedDecl *InstD = static_cast<NamedDecl*>(
6411 getDerived().TransformDecl(Old->getMemberLoc(),
6412 *I));
John McCall84d87672009-12-10 09:41:52 +00006413 if (!InstD) {
6414 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6415 // This can happen because of dependent hiding.
6416 if (isa<UsingShadowDecl>(*I))
6417 continue;
6418 else
John McCallfaf5fb42010-08-26 23:41:50 +00006419 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006420 }
John McCall10eae182009-11-30 22:42:35 +00006421
6422 // Expand using declarations.
6423 if (isa<UsingDecl>(InstD)) {
6424 UsingDecl *UD = cast<UsingDecl>(InstD);
6425 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6426 E = UD->shadow_end(); I != E; ++I)
6427 R.addDecl(*I);
6428 continue;
6429 }
6430
6431 R.addDecl(InstD);
6432 }
6433
6434 R.resolveKind();
6435
Douglas Gregor9262f472010-04-27 18:19:34 +00006436 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00006437 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006438 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00006439 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00006440 Old->getMemberLoc(),
6441 Old->getNamingClass()));
6442 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006443 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006444
Douglas Gregorda7be082010-04-27 16:10:10 +00006445 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00006446 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006447
John McCall10eae182009-11-30 22:42:35 +00006448 TemplateArgumentListInfo TransArgs;
6449 if (Old->hasExplicitTemplateArgs()) {
6450 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6451 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006452 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6453 Old->getNumTemplateArgs(),
6454 TransArgs))
6455 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006456 }
John McCall38836f02010-01-15 08:34:02 +00006457
6458 // FIXME: to do this check properly, we will need to preserve the
6459 // first-qualifier-in-scope here, just in case we had a dependent
6460 // base (and therefore couldn't do the check) and a
6461 // nested-name-qualifier (and therefore could do the lookup).
6462 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006463
John McCallb268a282010-08-23 23:25:46 +00006464 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006465 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006466 Old->getOperatorLoc(),
6467 Old->isArrow(),
6468 Qualifier,
6469 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006470 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006471 R,
6472 (Old->hasExplicitTemplateArgs()
6473 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006474}
6475
6476template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006477ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006478TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6479 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6480 if (SubExpr.isInvalid())
6481 return ExprError();
6482
6483 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00006484 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006485
6486 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6487}
6488
6489template<typename Derived>
6490ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006491TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
6492 llvm_unreachable("pack expansion expression in unhandled context");
6493 return ExprError();
6494}
6495
6496template<typename Derived>
6497ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006498TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006499 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006500}
6501
Mike Stump11289f42009-09-09 15:08:12 +00006502template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006503ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006504TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006505 TypeSourceInfo *EncodedTypeInfo
6506 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6507 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006508 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006509
Douglas Gregora16548e2009-08-11 05:31:07 +00006510 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006511 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006512 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006513
6514 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006515 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006516 E->getRParenLoc());
6517}
Mike Stump11289f42009-09-09 15:08:12 +00006518
Douglas Gregora16548e2009-08-11 05:31:07 +00006519template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006520ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006521TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006522 // Transform arguments.
6523 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006524 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006525 Args.reserve(E->getNumArgs());
6526 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
6527 &ArgChanged))
6528 return ExprError();
6529
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006530 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6531 // Class message: transform the receiver type.
6532 TypeSourceInfo *ReceiverTypeInfo
6533 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6534 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006535 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006536
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006537 // If nothing changed, just retain the existing message send.
6538 if (!getDerived().AlwaysRebuild() &&
6539 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006540 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006541
6542 // Build a new class message send.
6543 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6544 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00006545 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006546 E->getMethodDecl(),
6547 E->getLeftLoc(),
6548 move_arg(Args),
6549 E->getRightLoc());
6550 }
6551
6552 // Instance message: transform the receiver
6553 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6554 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00006555 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006556 = getDerived().TransformExpr(E->getInstanceReceiver());
6557 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006558 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006559
6560 // If nothing changed, just retain the existing message send.
6561 if (!getDerived().AlwaysRebuild() &&
6562 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006563 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006564
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006565 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00006566 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006567 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00006568 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006569 E->getMethodDecl(),
6570 E->getLeftLoc(),
6571 move_arg(Args),
6572 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006573}
6574
Mike Stump11289f42009-09-09 15:08:12 +00006575template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006576ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006577TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006578 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006579}
6580
Mike Stump11289f42009-09-09 15:08:12 +00006581template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006582ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006583TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006584 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006585}
6586
Mike Stump11289f42009-09-09 15:08:12 +00006587template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006588ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006589TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006590 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006591 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006592 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006593 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00006594
6595 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006596
Douglas Gregord51d90d2010-04-26 20:11:03 +00006597 // If nothing changed, just retain the existing expression.
6598 if (!getDerived().AlwaysRebuild() &&
6599 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006600 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006601
John McCallb268a282010-08-23 23:25:46 +00006602 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006603 E->getLocation(),
6604 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006605}
6606
Mike Stump11289f42009-09-09 15:08:12 +00006607template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006608ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006609TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00006610 // 'super' and types never change. Property never changes. Just
6611 // retain the existing expression.
6612 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00006613 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006614
Douglas Gregor9faee212010-04-26 20:47:02 +00006615 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006616 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00006617 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006618 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006619
Douglas Gregor9faee212010-04-26 20:47:02 +00006620 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006621
Douglas Gregor9faee212010-04-26 20:47:02 +00006622 // If nothing changed, just retain the existing expression.
6623 if (!getDerived().AlwaysRebuild() &&
6624 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006625 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006626
John McCallb7bd14f2010-12-02 01:19:52 +00006627 if (E->isExplicitProperty())
6628 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6629 E->getExplicitProperty(),
6630 E->getLocation());
6631
6632 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6633 E->getType(),
6634 E->getImplicitPropertyGetter(),
6635 E->getImplicitPropertySetter(),
6636 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006637}
6638
Mike Stump11289f42009-09-09 15:08:12 +00006639template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006640ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006641TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006642 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006643 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006644 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006645 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006646
Douglas Gregord51d90d2010-04-26 20:11:03 +00006647 // If nothing changed, just retain the existing expression.
6648 if (!getDerived().AlwaysRebuild() &&
6649 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006650 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006651
John McCallb268a282010-08-23 23:25:46 +00006652 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006653 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006654}
6655
Mike Stump11289f42009-09-09 15:08:12 +00006656template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006657ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006658TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006659 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006660 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006661 SubExprs.reserve(E->getNumSubExprs());
6662 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
6663 SubExprs, &ArgumentChanged))
6664 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006665
Douglas Gregora16548e2009-08-11 05:31:07 +00006666 if (!getDerived().AlwaysRebuild() &&
6667 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006668 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006669
Douglas Gregora16548e2009-08-11 05:31:07 +00006670 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6671 move_arg(SubExprs),
6672 E->getRParenLoc());
6673}
6674
Mike Stump11289f42009-09-09 15:08:12 +00006675template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006676ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006677TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006678 SourceLocation CaretLoc(E->getExprLoc());
6679
6680 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6681 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6682 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6683 llvm::SmallVector<ParmVarDecl*, 4> Params;
6684 llvm::SmallVector<QualType, 4> ParamTypes;
6685
6686 // Parameter substitution.
6687 const BlockDecl *BD = E->getBlockDecl();
6688 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6689 EN = BD->param_end(); P != EN; ++P) {
6690 ParmVarDecl *OldParm = (*P);
6691 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6692 QualType NewType = NewParm->getType();
6693 Params.push_back(NewParm);
6694 ParamTypes.push_back(NewParm->getType());
6695 }
6696
6697 const FunctionType *BExprFunctionType = E->getFunctionType();
6698 QualType BExprResultType = BExprFunctionType->getResultType();
6699 if (!BExprResultType.isNull()) {
6700 if (!BExprResultType->isDependentType())
6701 CurBlock->ReturnType = BExprResultType;
6702 else if (BExprResultType != SemaRef.Context.DependentTy)
6703 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6704 }
6705
6706 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006707 StmtResult Body = getDerived().TransformStmt(E->getBody());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006708 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006709 return ExprError();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006710 // Set the parameters on the block decl.
6711 if (!Params.empty())
6712 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6713
6714 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6715 CurBlock->ReturnType,
6716 ParamTypes.data(),
6717 ParamTypes.size(),
6718 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006719 0,
6720 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006721
6722 CurBlock->FunctionType = FunctionType;
John McCallb268a282010-08-23 23:25:46 +00006723 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006724}
6725
Mike Stump11289f42009-09-09 15:08:12 +00006726template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006727ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006728TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006729 NestedNameSpecifier *Qualifier = 0;
6730
6731 ValueDecl *ND
6732 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6733 E->getDecl()));
6734 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006735 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006736
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006737 if (!getDerived().AlwaysRebuild() &&
6738 ND == E->getDecl()) {
6739 // Mark it referenced in the new context regardless.
6740 // FIXME: this is a bit instantiation-specific.
6741 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6742
John McCallc3007a22010-10-26 07:05:15 +00006743 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006744 }
6745
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006746 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006747 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006748 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006749}
Mike Stump11289f42009-09-09 15:08:12 +00006750
Douglas Gregora16548e2009-08-11 05:31:07 +00006751//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006752// Type reconstruction
6753//===----------------------------------------------------------------------===//
6754
Mike Stump11289f42009-09-09 15:08:12 +00006755template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006756QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6757 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006758 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006759 getDerived().getBaseEntity());
6760}
6761
Mike Stump11289f42009-09-09 15:08:12 +00006762template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006763QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6764 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006765 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006766 getDerived().getBaseEntity());
6767}
6768
Mike Stump11289f42009-09-09 15:08:12 +00006769template<typename Derived>
6770QualType
John McCall70dd5f62009-10-30 00:06:24 +00006771TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6772 bool WrittenAsLValue,
6773 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006774 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006775 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006776}
6777
6778template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006779QualType
John McCall70dd5f62009-10-30 00:06:24 +00006780TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6781 QualType ClassType,
6782 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006783 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006784 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006785}
6786
6787template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006788QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006789TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6790 ArrayType::ArraySizeModifier SizeMod,
6791 const llvm::APInt *Size,
6792 Expr *SizeExpr,
6793 unsigned IndexTypeQuals,
6794 SourceRange BracketsRange) {
6795 if (SizeExpr || !Size)
6796 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6797 IndexTypeQuals, BracketsRange,
6798 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006799
6800 QualType Types[] = {
6801 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6802 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6803 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006804 };
6805 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6806 QualType SizeType;
6807 for (unsigned I = 0; I != NumTypes; ++I)
6808 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6809 SizeType = Types[I];
6810 break;
6811 }
Mike Stump11289f42009-09-09 15:08:12 +00006812
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006813 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6814 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006815 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006816 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006817 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006818}
Mike Stump11289f42009-09-09 15:08:12 +00006819
Douglas Gregord6ff3322009-08-04 16:50:30 +00006820template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006821QualType
6822TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006823 ArrayType::ArraySizeModifier SizeMod,
6824 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006825 unsigned IndexTypeQuals,
6826 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006827 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006828 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006829}
6830
6831template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006832QualType
Mike Stump11289f42009-09-09 15:08:12 +00006833TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006834 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006835 unsigned IndexTypeQuals,
6836 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006837 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006838 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006839}
Mike Stump11289f42009-09-09 15:08:12 +00006840
Douglas Gregord6ff3322009-08-04 16:50:30 +00006841template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006842QualType
6843TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006844 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006845 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006846 unsigned IndexTypeQuals,
6847 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006848 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006849 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006850 IndexTypeQuals, BracketsRange);
6851}
6852
6853template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006854QualType
6855TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006856 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006857 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006858 unsigned IndexTypeQuals,
6859 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006860 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006861 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006862 IndexTypeQuals, BracketsRange);
6863}
6864
6865template<typename Derived>
6866QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00006867 unsigned NumElements,
6868 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006869 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00006870 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006871}
Mike Stump11289f42009-09-09 15:08:12 +00006872
Douglas Gregord6ff3322009-08-04 16:50:30 +00006873template<typename Derived>
6874QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6875 unsigned NumElements,
6876 SourceLocation AttributeLoc) {
6877 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6878 NumElements, true);
6879 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006880 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6881 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00006882 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006883}
Mike Stump11289f42009-09-09 15:08:12 +00006884
Douglas Gregord6ff3322009-08-04 16:50:30 +00006885template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006886QualType
6887TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00006888 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006889 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00006890 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006891}
Mike Stump11289f42009-09-09 15:08:12 +00006892
Douglas Gregord6ff3322009-08-04 16:50:30 +00006893template<typename Derived>
6894QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006895 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006896 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006897 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00006898 unsigned Quals,
6899 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00006900 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006901 Quals,
6902 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006903 getDerived().getBaseEntity(),
6904 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006905}
Mike Stump11289f42009-09-09 15:08:12 +00006906
Douglas Gregord6ff3322009-08-04 16:50:30 +00006907template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006908QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6909 return SemaRef.Context.getFunctionNoProtoType(T);
6910}
6911
6912template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006913QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6914 assert(D && "no decl found");
6915 if (D->isInvalidDecl()) return QualType();
6916
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006917 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006918 TypeDecl *Ty;
6919 if (isa<UsingDecl>(D)) {
6920 UsingDecl *Using = cast<UsingDecl>(D);
6921 assert(Using->isTypeName() &&
6922 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6923
6924 // A valid resolved using typename decl points to exactly one type decl.
6925 assert(++Using->shadow_begin() == Using->shadow_end());
6926 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006927
John McCallb96ec562009-12-04 22:46:56 +00006928 } else {
6929 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6930 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6931 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6932 }
6933
6934 return SemaRef.Context.getTypeDeclType(Ty);
6935}
6936
6937template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00006938QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
6939 SourceLocation Loc) {
6940 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006941}
6942
6943template<typename Derived>
6944QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6945 return SemaRef.Context.getTypeOfType(Underlying);
6946}
6947
6948template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00006949QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
6950 SourceLocation Loc) {
6951 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006952}
6953
6954template<typename Derived>
6955QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006956 TemplateName Template,
6957 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006958 const TemplateArgumentListInfo &TemplateArgs) {
6959 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006960}
Mike Stump11289f42009-09-09 15:08:12 +00006961
Douglas Gregor1135c352009-08-06 05:28:30 +00006962template<typename Derived>
6963NestedNameSpecifier *
6964TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6965 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006966 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006967 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006968 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006969 CXXScopeSpec SS;
6970 // FIXME: The source location information is all wrong.
6971 SS.setRange(Range);
6972 SS.setScopeRep(Prefix);
6973 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006974 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006975 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006976 ObjectType,
6977 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006978 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006979}
6980
6981template<typename Derived>
6982NestedNameSpecifier *
6983TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6984 SourceRange Range,
6985 NamespaceDecl *NS) {
6986 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6987}
6988
6989template<typename Derived>
6990NestedNameSpecifier *
6991TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6992 SourceRange Range,
6993 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006994 QualType T) {
6995 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006996 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006997 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006998 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6999 T.getTypePtr());
7000 }
Mike Stump11289f42009-09-09 15:08:12 +00007001
Douglas Gregor1135c352009-08-06 05:28:30 +00007002 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7003 return 0;
7004}
Mike Stump11289f42009-09-09 15:08:12 +00007005
Douglas Gregor71dc5092009-08-06 06:41:21 +00007006template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007007TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007008TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7009 bool TemplateKW,
7010 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00007011 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007012 Template);
7013}
7014
7015template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007016TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007017TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00007018 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00007019 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00007020 QualType ObjectType,
7021 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00007022 CXXScopeSpec SS;
Douglas Gregora5614c52010-09-08 23:56:00 +00007023 SS.setRange(QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00007024 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00007025 UnqualifiedId Name;
7026 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00007027 Sema::TemplateTy Template;
7028 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7029 /*FIXME:*/getDerived().getBaseLocation(),
7030 SS,
7031 Name,
John McCallba7bf592010-08-24 05:47:05 +00007032 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007033 /*EnteringContext=*/false,
7034 Template);
John McCall31f82722010-11-12 08:19:04 +00007035 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007036}
Mike Stump11289f42009-09-09 15:08:12 +00007037
Douglas Gregora16548e2009-08-11 05:31:07 +00007038template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007039TemplateName
7040TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7041 OverloadedOperatorKind Operator,
7042 QualType ObjectType) {
7043 CXXScopeSpec SS;
7044 SS.setRange(SourceRange(getDerived().getBaseLocation()));
7045 SS.setScopeRep(Qualifier);
7046 UnqualifiedId Name;
7047 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7048 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7049 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007050 Sema::TemplateTy Template;
7051 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007052 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007053 SS,
7054 Name,
John McCallba7bf592010-08-24 05:47:05 +00007055 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007056 /*EnteringContext=*/false,
7057 Template);
7058 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007059}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007060
Douglas Gregor71395fa2009-11-04 00:56:37 +00007061template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007062ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007063TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7064 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007065 Expr *OrigCallee,
7066 Expr *First,
7067 Expr *Second) {
7068 Expr *Callee = OrigCallee->IgnoreParenCasts();
7069 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007070
Douglas Gregora16548e2009-08-11 05:31:07 +00007071 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007072 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007073 if (!First->getType()->isOverloadableType() &&
7074 !Second->getType()->isOverloadableType())
7075 return getSema().CreateBuiltinArraySubscriptExpr(First,
7076 Callee->getLocStart(),
7077 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007078 } else if (Op == OO_Arrow) {
7079 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007080 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7081 } else if (Second == 0 || isPostIncDec) {
7082 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007083 // The argument is not of overloadable type, so try to create a
7084 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007085 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007086 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007087
John McCallb268a282010-08-23 23:25:46 +00007088 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007089 }
7090 } else {
John McCallb268a282010-08-23 23:25:46 +00007091 if (!First->getType()->isOverloadableType() &&
7092 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007093 // Neither of the arguments is an overloadable type, so try to
7094 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007095 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007096 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007097 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007098 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007099 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007100
Douglas Gregora16548e2009-08-11 05:31:07 +00007101 return move(Result);
7102 }
7103 }
Mike Stump11289f42009-09-09 15:08:12 +00007104
7105 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007106 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007107 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007108
John McCallb268a282010-08-23 23:25:46 +00007109 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007110 assert(ULE->requiresADL());
7111
7112 // FIXME: Do we have to check
7113 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007114 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007115 } else {
John McCallb268a282010-08-23 23:25:46 +00007116 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007117 }
Mike Stump11289f42009-09-09 15:08:12 +00007118
Douglas Gregora16548e2009-08-11 05:31:07 +00007119 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007120 Expr *Args[2] = { First, Second };
7121 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007122
Douglas Gregora16548e2009-08-11 05:31:07 +00007123 // Create the overloaded operator invocation for unary operators.
7124 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007125 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007126 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007127 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007128 }
Mike Stump11289f42009-09-09 15:08:12 +00007129
Sebastian Redladba46e2009-10-29 20:17:01 +00007130 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007131 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007132 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007133 First,
7134 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007135
Douglas Gregora16548e2009-08-11 05:31:07 +00007136 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007137 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007138 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007139 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7140 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007141 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007142
Mike Stump11289f42009-09-09 15:08:12 +00007143 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007144}
Mike Stump11289f42009-09-09 15:08:12 +00007145
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007146template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007147ExprResult
John McCallb268a282010-08-23 23:25:46 +00007148TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007149 SourceLocation OperatorLoc,
7150 bool isArrow,
7151 NestedNameSpecifier *Qualifier,
7152 SourceRange QualifierRange,
7153 TypeSourceInfo *ScopeType,
7154 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007155 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007156 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007157 CXXScopeSpec SS;
7158 if (Qualifier) {
7159 SS.setRange(QualifierRange);
7160 SS.setScopeRep(Qualifier);
7161 }
7162
John McCallb268a282010-08-23 23:25:46 +00007163 QualType BaseType = Base->getType();
7164 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007165 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007166 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007167 !BaseType->getAs<PointerType>()->getPointeeType()
7168 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007169 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00007170 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007171 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007172 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007173 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007174 /*FIXME?*/true);
7175 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007176
Douglas Gregor678f90d2010-02-25 01:56:36 +00007177 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007178 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7179 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7180 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7181 NameInfo.setNamedTypeInfo(DestroyedType);
7182
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007183 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007184
John McCallb268a282010-08-23 23:25:46 +00007185 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007186 OperatorLoc, isArrow,
7187 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007188 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007189 /*TemplateArgs*/ 0);
7190}
7191
Douglas Gregord6ff3322009-08-04 16:50:30 +00007192} // end namespace clang
7193
7194#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H